summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Oberbrunner <garyo@oberbrunner.com>2014-03-01 18:05:19 -0500
committerGary Oberbrunner <garyo@oberbrunner.com>2014-03-01 18:05:19 -0500
commiteee9fcf49fac8b8bd3bf21f7d787261be80069e9 (patch)
treee6ac75005b7db1b3f477b3db362fc964e3b429c1
parent5ad8964393d4a0eecec0c4b21f9c8799de6c9f4b (diff)
parent8a78b9b09c4baea24078589a887d78c7db751249 (diff)
downloadscons-eee9fcf49fac8b8bd3bf21f7d787261be80069e9.tar.gz
Merged in techtonik/scons (pull request #108), update copyrights to 2014
-rw-r--r--src/CHANGES.txt2
-rw-r--r--src/engine/SCons/Node/FS.py12
-rw-r--r--src/engine/SCons/Node/__init__.py11
-rw-r--r--src/engine/SCons/Script/SConsOptions.py67
-rw-r--r--test/AddOption/longopts.py60
-rw-r--r--test/Depends/spurious-rebuilds.py72
6 files changed, 218 insertions, 6 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 978c82c8..39c8d32a 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -49,6 +49,8 @@ RELEASE 2.3.1.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE
- Added release_target_info() to File nodes, which helps to
reduce memory consumption in clean builds and update runs
of large projects.
+ - Fixed the handling of long options in the command-line
+ parsing (#2929).
From Gary Oberbrunner:
- Test harness: fail_test() can now print a message to help debugging.
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index aaa5b473..219718cc 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -2779,7 +2779,7 @@ class File(Base):
if not hasattr(self.attributes, 'keep_targetinfo'):
# Cache some required values, before releasing
# stuff like env, executor and builder...
- self.changed()
+ self.changed(allowcache=True)
self.get_contents_sig()
self.get_build_env()
# Now purge unneeded stuff to free memory...
@@ -3023,7 +3023,8 @@ class File(Base):
SCons.Node.Node.built(self)
- if not hasattr(self.attributes, 'keep_targetinfo'):
+ if (not SCons.Node.interactive and
+ not hasattr(self.attributes, 'keep_targetinfo')):
# Ensure that the build infos get computed and cached...
self.store_info()
# ... then release some more variables.
@@ -3034,7 +3035,7 @@ class File(Base):
self.scanner_paths = None
- def changed(self, node=None):
+ def changed(self, node=None, allowcache=False):
"""
Returns if the node is up-to-date with respect to the BuildInfo
stored last time it was built.
@@ -3042,6 +3043,8 @@ class File(Base):
For File nodes this is basically a wrapper around Node.changed(),
but we allow the return value to get cached after the reference
to the Executor got released in release_target_info().
+
+ @see: Node.changed()
"""
if node is None:
try:
@@ -3050,7 +3053,8 @@ class File(Base):
pass
has_changed = SCons.Node.Node.changed(self, node)
- self._memo['changed'] = has_changed
+ if allowcache:
+ self._memo['changed'] = has_changed
return has_changed
def changed_content(self, target, prev_ni):
diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py
index d6dbf2e6..1f629712 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -1049,7 +1049,7 @@ class Node(object):
def Decider(self, function):
SCons.Util.AddMethod(self, function, 'changed_since_last_build')
- def changed(self, node=None):
+ def changed(self, node=None, allowcache=False):
"""
Returns if the node is up-to-date with respect to the BuildInfo
stored last time it was built. The default behavior is to compare
@@ -1062,6 +1062,15 @@ class Node(object):
any difference, but we now rely on checking every dependency
to make sure that any necessary Node information (for example,
the content signature of an #included .h file) is updated.
+
+ The allowcache option was added for supporting the early
+ release of the executor/builder structures, right after
+ a File target was built. When set to true, the return
+ value of this changed method gets cached for File nodes.
+ Like this, the executor isn't needed any longer for subsequent
+ calls to changed().
+
+ @see: FS.File.changed(), FS.File.release_target_info()
"""
t = 0
if t: Trace('changed(%s [%s], %s)' % (self, classname(self), node))
diff --git a/src/engine/SCons/Script/SConsOptions.py b/src/engine/SCons/Script/SConsOptions.py
index 62033ba1..d7262a9d 100644
--- a/src/engine/SCons/Script/SConsOptions.py
+++ b/src/engine/SCons/Script/SConsOptions.py
@@ -337,6 +337,71 @@ class SConsOptionParser(optparse.OptionParser):
option.process(opt, value, values, self)
+ def reparse_local_options(self):
+ """
+ Re-parse the leftover command-line options stored
+ in self.largs, so that any value overridden on the
+ command line is immediately available if the user turns
+ around and does a GetOption() right away.
+
+ We mimic the processing of the single args
+ in the original OptionParser._process_args(), but here we
+ allow exact matches for long-opts only (no partial
+ argument names!).
+
+ Else, this would lead to problems in add_local_option()
+ below. When called from there, we try to reparse the
+ command-line arguments that
+ 1. haven't been processed so far (self.largs), but
+ 2. are possibly not added to the list of options yet.
+
+ So, when we only have a value for "--myargument" yet,
+ a command-line argument of "--myarg=test" would set it.
+ Responsible for this behaviour is the method
+ _match_long_opt(), which allows for partial matches of
+ the option name, as long as the common prefix appears to
+ be unique.
+ This would lead to further confusion, because we might want
+ to add another option "--myarg" later on (see issue #2929).
+
+ """
+ rargs = []
+ largs_restore = []
+ # Loop over all remaining arguments
+ skip = False
+ for l in self.largs:
+ if skip:
+ # Accept all remaining arguments as they are
+ largs_restore.append(l)
+ else:
+ if len(l) > 2 and l[0:2] == "--":
+ # Check long option
+ lopt = (l,)
+ if "=" in l:
+ # Split into option and value
+ lopt = l.split("=", 1)
+
+ if lopt[0] in self._long_opt:
+ # Argument is already known
+ rargs.append('='.join(lopt))
+ else:
+ # Not known yet, so reject for now
+ largs_restore.append('='.join(lopt))
+ else:
+ if l == "--" or l == "-":
+ # Stop normal processing and don't
+ # process the rest of the command-line opts
+ largs_restore.append(l)
+ skip = True
+ else:
+ rargs.append(l)
+
+ # Parse the filtered list
+ self.parse_args(rargs, self.values)
+ # Restore the list of remaining arguments for the
+ # next call of AddOption/add_local_option...
+ self.largs = self.largs + largs_restore
+
def add_local_option(self, *args, **kw):
"""
Adds a local option to the parser.
@@ -364,7 +429,7 @@ class SConsOptionParser(optparse.OptionParser):
# available if the user turns around and does a GetOption()
# right away.
setattr(self.values.__defaults__, result.dest, result.default)
- self.parse_args(self.largs, self.values)
+ self.reparse_local_options()
return result
diff --git a/test/AddOption/longopts.py b/test/AddOption/longopts.py
new file mode 100644
index 00000000..47ae4f17
--- /dev/null
+++ b/test/AddOption/longopts.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verifies that the default name matching of optparse for long options
+gets properly suppressed. We don't allow for partial matching
+of argument names, because it would lead to trouble in the test
+case below...
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """\
+AddOption('--myargument', dest='myargument', type='string', default='gully')
+AddOption('--myarg', dest='myarg', type='string', default='balla')
+print("myargument: " + str(GetOption('myargument')))
+print("myarg: " + str(GetOption('myarg')))
+""")
+
+test.run('-Q -q .',
+ stdout="myargument: gully\nmyarg: balla\n")
+
+test.run('-Q -q . --myargument=helloworld',
+ stdout="myargument: helloworld\nmyarg: balla\n")
+
+test.run('-Q -q . --myarg=helloworld',
+ stdout="myargument: gully\nmyarg: helloworld\n")
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/Depends/spurious-rebuilds.py b/test/Depends/spurious-rebuilds.py
new file mode 100644
index 00000000..6afc829d
--- /dev/null
+++ b/test/Depends/spurious-rebuilds.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+After adding some code for reducing the overall memory consumption in
+revision b4bc497, a number of spurious rebuilds was observed by different
+people. The problem was, that the value of the Node.changed() method got cached
+too early for File nodes.
+
+This test verifies that the changed() function works properly, especially
+in connection with auto-generated sources, combined with an explicit Depends().
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """\
+# This tests the too-many-rebuilds problem with SCons 2.3.1 (test)
+# Run like this: scons all-defuns.obj
+
+# Test setup (only runs once)
+import os.path
+if not os.path.exists('mkl'):
+ os.mkdir('mkl')
+if not os.path.exists('test.c'):
+ open('test.c', 'w').write('int i;')
+
+env=Environment()
+env.SharedObject('all-defuns.obj', 'all-defuns.c')
+results = env.Command('all-defuns.c', 'test.c', Copy('$TARGET', '$SOURCE'))
+env.Depends(results, '#mkl')
+""")
+
+test.run(arguments = 'all-defuns.obj')
+
+test.must_exist('all-defuns.c')
+test.must_exist('test.c')
+test.must_exist('all-defuns.obj')
+
+test.up_to_date(arguments = 'all-defuns.obj')
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: