From a2a45672f2fcba37980f6616a19ee7143b4b7f12 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sun, 18 May 2008 05:12:35 +0000 Subject: [PATCH] Merged revisions 2928-2932,2934-2946 via svnmerge from http://scons.tigris.org/svn/scons/branches/core ........ r2932 | garyo | 2008-04-30 09:14:38 -0700 (Wed, 30 Apr 2008) | 1 line Add doc for site_scons dir and related options. Closes issue #1996. ........ r2934 | stevenknight | 2008-04-30 22:05:38 -0700 (Wed, 30 Apr 2008) | 3 lines Issue 2039: Fix a syntax error in Intel C compiler support on Windows. (Jonas Olsson) ........ r2935 | belley | 2008-05-01 06:59:21 -0700 (Thu, 01 May 2008) | 10 lines test/KeyboardInterrupt.py no longer hangs under Cygwin. There seems to be a bug on Cygwin where the compiler process hangs after sending the SIGINT signal to the process group. It is probably a bug in cygwin1.dll, or maybe in the Python 'C' code or the Python subprocess module. We therefore do not use 'killpg' on Cygwin. Benoit ........ r2936 | belley | 2008-05-01 07:10:23 -0700 (Thu, 01 May 2008) | 12 lines cell_contents not defined in python < 2.5. [Issue 2035] Some versions of Python supports lexical scoping of local variables (aka closures) but not the cell_contents attribute that would allow the FunctionAction signature that take the content of these closure cells into account. The access to the cell_contents attribute is now protected with a try/except AttributeError so that at least the other parts of the function signature are properly computed. Benoit ........ r2937 | stevenknight | 2008-05-01 12:08:25 -0700 (Thu, 01 May 2008) | 3 lines When running tests, allow the user to set the $SCONSIGN variable to pick a specific sconsign script to execute. ........ r2938 | stevenknight | 2008-05-02 19:13:14 -0700 (Fri, 02 May 2008) | 2 lines Set svn:ignore to '*.py[co]'. ........ r2939 | stevenknight | 2008-05-08 21:07:18 -0700 (Thu, 08 May 2008) | 4 lines Issue 2033: Fix excessive memory use when a Python Value node's representation is stored in a .sconsign file and then re-stored after being interpreted with escaped backslashes and quotes. ........ r2940 | cournape | 2008-05-16 03:56:49 -0700 (Fri, 16 May 2008) | 1 line Fix issue 2054. ........ r2941 | stevenknight | 2008-05-16 12:02:45 -0700 (Fri, 16 May 2008) | 8 lines Issue 2045: After a Node has failed its build and we're propagating the failure to other Nodes on the candidate list, don't marke candidate Nodes as FAILED if they've already been visited and been determined to be up-to-date. This avoids problems with Configure tests not running because failure of an earlier Configure tests caused (e.g.) /usr/bin/g++ to get marked as FAILED, making SCons think it doesn't need to bother trying to rebuild anything that will use it... ........ r2942 | stevenknight | 2008-05-16 12:10:14 -0700 (Fri, 16 May 2008) | 8 lines Improve the regular expressions used by the test infrastructure to examine SCons output to decide if a list of targets are considered up-to-date or not. The new code uses the re.escape() function instead of hand-escaping '.' and '\n'. This required a little restructuring in the not_up_to_date() method to escape the characters within the arguments themselves, but not the surrounding characters we use to construct the regex that makes sure those strings *don't* exist in the output. ........ r2943 | stevenknight | 2008-05-16 14:04:23 -0700 (Fri, 16 May 2008) | 3 lines Issue 2049: Handle multiple pipe-separated values in Visual Studio for INCLUDE, LIB and PATH. Still only uses Win32, not any other values. ........ r2944 | stevenknight | 2008-05-16 18:36:27 -0700 (Fri, 16 May 2008) | 2 lines Record changes by David Cournapeau and Benoit Belley. ........ r2945 | stevenknight | 2008-05-17 07:13:46 -0700 (Sat, 17 May 2008) | 3 lines Pass in dc as a keyword argument to _smartLink for older Python versions without nested scopes. ........ r2946 | stevenknight | 2008-05-17 07:14:01 -0700 (Sat, 17 May 2008) | 3 lines Expect a warning about shadowing global variables on Python 2.1. (This code can go away after we release 1.0.) ........ git-svn-id: http://scons.tigris.org/svn/scons/trunk@2948 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- QMTest/TestSCons.py | 17 ++-- QMTest/TestSConsign.py | 24 ++++-- doc/user/add-method.in | 8 +- doc/user/add-method.xml | 6 ++ doc/user/builders-writing.in | 138 +++++++++++++++++++++++++++++++ doc/user/builders-writing.xml | 123 +++++++++++++++++++++++++++ doc/user/main.in | 6 -- doc/user/main.xml | 6 -- src/CHANGES.txt | 30 +++++++ src/engine/SCons/Action.py | 13 ++- src/engine/SCons/ActionTests.py | 30 +++---- src/engine/SCons/Node/Alias.py | 3 + src/engine/SCons/Node/FS.py | 3 + src/engine/SCons/Node/Python.py | 5 +- src/engine/SCons/Taskmaster.py | 15 ++-- src/engine/SCons/Tool/dmd.py | 2 +- src/engine/SCons/Tool/g77.py | 4 +- src/engine/SCons/Tool/intelc.py | 2 +- src/engine/SCons/Tool/msvc.py | 35 ++++---- src/script/sconsign.py | 4 + test/Actions/function.py | 56 +++++++++++-- test/Configure/build-fail.py | 90 ++++++++++++++++++++ test/Configure/implicit-cache.py | 103 +++++++++++++++++++++++ test/KeyboardInterrupt.py | 46 ++++++++--- test/Value.py | 18 ++-- test/explain/basic.py | 10 ++- 26 files changed, 697 insertions(+), 100 deletions(-) create mode 100644 test/Configure/build-fail.py create mode 100644 test/Configure/implicit-cache.py diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py index 1277af57..cfcbfb14 100644 --- a/QMTest/TestSCons.py +++ b/QMTest/TestSCons.py @@ -338,9 +338,8 @@ class TestSCons(TestCommon): if options: arguments = options + " " + arguments kw['arguments'] = arguments - kw['stdout'] = self.wrap_stdout(read_str = read_str, build_str = s) - kw['stdout'] = string.replace(kw['stdout'],'\n','\\n') - kw['stdout'] = string.replace(kw['stdout'],'.','\\.') + stdout = self.wrap_stdout(read_str = read_str, build_str = s) + kw['stdout'] = re.escape(stdout) kw['match'] = self.match_re_dotall apply(self.run, [], kw) @@ -350,14 +349,14 @@ class TestSCons(TestCommon): This function is most useful in conjunction with the -n option. """ s = "" - for arg in string.split(arguments): - s = s + "(?!scons: `%s' is up to date.)" % arg + for arg in string.split(arguments): + s = s + "(?!scons: `%s' is up to date.)" % re.escape(arg) if options: arguments = options + " " + arguments + s = '('+s+'[^\n]*\n)*' kw['arguments'] = arguments - kw['stdout'] = self.wrap_stdout(build_str="("+s+"[^\n]*\n)*") - kw['stdout'] = string.replace(kw['stdout'],'\n','\\n') - kw['stdout'] = string.replace(kw['stdout'],'.','\\.') + stdout = re.escape(self.wrap_stdout(build_str='ARGUMENTSGOHERE')) + kw['stdout'] = string.replace(stdout, 'ARGUMENTSGOHERE', s) kw['match'] = self.match_re_dotall apply(self.run, [], kw) @@ -833,7 +832,7 @@ print "self._msvs_versions =", str(env['MSVS']['VERSIONS']) def __init__(self, p): self.pos = p - def matchPart(log, logfile, lastEnd): + def matchPart(log, logfile, lastEnd, NoMatch=NoMatch): m = re.match(log, logfile[lastEnd:]) if not m: raise NoMatch, lastEnd diff --git a/QMTest/TestSConsign.py b/QMTest/TestSConsign.py index d1440400..fd8ef306 100644 --- a/QMTest/TestSConsign.py +++ b/QMTest/TestSConsign.py @@ -54,13 +54,23 @@ class TestSConsign(TestSCons): 'interpreter' : python, # imported from TestSCons } - if os.path.exists(self.script_path('sconsign.py')): - sconsign = 'sconsign.py' - elif os.path.exists(self.script_path('sconsign')): - sconsign = 'sconsign' - else: - print "Can find neither 'sconsign.py' nor 'sconsign' scripts." - self.no_result() + if not kw.has_key('program'): + kw['program'] = os.environ.get('SCONS') + if not kw['program']: + if os.path.exists('scons'): + kw['program'] = 'scons' + else: + kw['program'] = 'scons.py' + + sconsign = os.environ.get('SCONSIGN') + if not sconsign: + if os.path.exists(self.script_path('sconsign.py')): + sconsign = 'sconsign.py' + elif os.path.exists(self.script_path('sconsign')): + sconsign = 'sconsign' + else: + print "Can find neither 'sconsign.py' nor 'sconsign' scripts." + self.no_result() self.set_sconsign(sconsign) def script_path(self, script): diff --git a/doc/user/add-method.in b/doc/user/add-method.in index 853b9a86..a0a60391 100644 --- a/doc/user/add-method.in +++ b/doc/user/add-method.in @@ -72,7 +72,7 @@ - import sys; + import sys def BuildTestProg(env, testfile, resourcefile, testdir="tests"): """Build the test program; prepends "test_" to src and target, and puts target into testdir.""" @@ -103,3 +103,9 @@ scons -Q + + Using AddMethod is better than just adding an instance method to an + Environment because it gets called as a proper method, and AddMethod + provides for copying the method to any copies of the Environment + instance. + diff --git a/doc/user/add-method.xml b/doc/user/add-method.xml index 22f5f1a5..7e84b808 100644 --- a/doc/user/add-method.xml +++ b/doc/user/add-method.xml @@ -98,3 +98,9 @@ cc -o tests/test_stuff test_stuff.o + + Using AddMethod is better than just adding an instance method to an + Environment because it gets called as a proper method, and AddMethod + provides for copying the method to any copies of the Environment + instance. + diff --git a/doc/user/builders-writing.in b/doc/user/builders-writing.in index 2285ac88..67a95f92 100644 --- a/doc/user/builders-writing.in +++ b/doc/user/builders-writing.in @@ -761,6 +761,144 @@ This functionality could be invoked as in the following example: +
+ Where To Put Your Custom Builders and Tools + + + + The site_scons directory gives you a place to + put Python modules you can import into your SConscripts + (site_scons), add-on tools that can integrate into &SCons; + (site_scons/site_tools), and a site_scons/site_init.py file that + gets read before any &SConstruct; or &SConscript;, allowing you to + change &SCons;'s default behavior. + + + + + + If you get a tool from somewhere (the &SCons; wiki or a third party, + for instance) and you'd like to use it in your project, the + site_scons dir is the simplest place to put it. + Tools come in two flavors; either a Python function that operates on + an &Environment; or a Python file containing two functions, exists() + and generate(). + + + + + + A single-function Tool can just be included in your + site_scons/site_init.py file where it will be + parsed and made available for use. For instance, you could have a + site_scons/site_init.py file like this: + + + + + + def TOOL_ADD_HEADER(env): + """A Tool to add a header from $HEADER to the source file""" + add_header = Builder(action=['echo "$HEADER" > $TARGET', + 'cat $SOURCE >> $TARGET']) + env.Append(BUILDERS = {'AddHeader' : add_header}) + env['HEADER'] = '' # set default value + + + env=Environment(tools=['default', TOOL_ADD_HEADER], HEADER="=====") + env.AddHeader('tgt', 'src') + + + hi there + + + + + + and a &SConstruct; like this: + + + + + # Use TOOL_ADD_HEADER from site_scons/site_init.py + env=Environment(tools=['default', TOOL_ADD_HEADER], HEADER="=====") + env.AddHeader('tgt', 'src') + + + + + The TOOL_ADD_HEADER tool method will be + called to add the AddHeader tool to the + environment. + + + + + + + Similarly, a more full-fledged tool with + exists() and generate() + methods can be installed in + site_scons/site_tools/toolname.py. Since + site_scons/site_tools is automatically added + to the head of the tool search path, any tool found there will be + available to all environments. Furthermore, a tool found there + will override a built-in tool of the same name, so if you need to + change the behavior of a built-in tool, site_scons gives you the + hook you need. + + + + Many people have a library of utility Python functions they'd like + to include in &SConscript;s; just put that module in + site_scons/my_utils.py or any valid Python module name of your + choice. For instance you can do something like this in + site_scons/my_utils.py to add a build_id method: + + + + + def build_id(): + """Return a build ID (stub version)""" + return "100" + + + import my_utils + print "build_id=" + my_utils.build_id() + + + + + + And then in your &SConscript; or any sub-&SConscript; anywhere in + your build, you can import my_utils and use it: + + + + + import my_utils + print "build_id=" + my_utils.build_id() + + + + + If you have a machine-wide site dir you'd like to use instead of + ./site_scons, use the + --site-dir option to point to your dir. + site_init.py and + site_tools will be located under that dir. + To avoid using a site_scons dir at all, even + if it exists, use the --no-site-dir option. + + + +
+ + + + + Similarly, a more full-fledged tool with + exists() and generate() + methods can be installed in + site_scons/site_tools/toolname.py. Since + site_scons/site_tools is automatically added + to the head of the tool search path, any tool found there will be + available to all environments. Furthermore, a tool found there + will override a built-in tool of the same name, so if you need to + change the behavior of a built-in tool, site_scons gives you the + hook you need. + + + + Many people have a library of utility Python functions they'd like + to include in &SConscript;s; just put that module in + site_scons/my_utils.py or any valid Python module name of your + choice. For instance you can do something like this in + site_scons/my_utils.py to add a build_id method: + + + + def build_id(): + """Return a build ID (stub version)""" + return "100" + + + + + And then in your &SConscript; or any sub-&SConscript; anywhere in + your build, you can import my_utils and use it: + + + + + import my_utils + print "build_id=" + my_utils.build_id() + + + + + If you have a machine-wide site dir you'd like to use instead of + ./site_scons, use the + --site-dir option to point to your dir. + site_init.py and + site_tools will be located under that dir. + To avoid using a site_scons dir at all, even + if it exists, use the --no-site-dir option. + + + + + +