From: stevenknight Date: Tue, 16 Sep 2003 06:39:36 +0000 (+0000) Subject: Fix dependency scans of generated files. (John Johnson) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=38e842500bed62374ed255f2478daff43fce0e95;p=scons.git Fix dependency scans of generated files. (John Johnson) git-svn-id: http://scons.tigris.org/svn/scons/trunk@797 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 72491cb6..a2f94c15 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -30,6 +30,11 @@ RELEASE X.XX - XXX can be used to avoid cluttering each directory with an individual .sconsign file. + From John Johnson: + + - Fix (re-)scanning of dependencies in generated or installed + header files. + From Steven Knight: - The -Q option suppressed too many messages; fix it so that it only diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index fe017aeb..08c35c8c 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -207,13 +207,13 @@ def _init_nodes(builder, env, overrides, tlist, slist): t.set_executor(executor) if builder.scanner: t.target_scanner = builder.scanner + if not hasattr(t, 'source_scanner'): + t.source_scanner = env.get_scanner(t.scanner_key()) # Last, add scanners from the Environment to the source Nodes. for s in slist: - src_key = s.scanner_key() # the file suffix - scanner = env.get_scanner(src_key) - if scanner: - s.source_scanner = scanner + if not hasattr(s, 'source_scanner'): + s.source_scanner = env.get_scanner(s.scanner_key()) class EmitterProxy: """This is a callable class that can act as a diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index b51eb9fa..23f18c43 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -752,10 +752,10 @@ class BuilderTestCase(unittest.TestCase): env_scanner = TestScanner() env = Environment() builder = SCons.Builder.Builder(action='action') - tgt = builder(env, target='foo.x', source='bar') + tgt = builder(env, target='foo.x', source='bar.y') src = tgt.sources[0] assert tgt.target_scanner != env_scanner, tgt.target_scanner - assert src.source_scanner == env_scanner + assert src.source_scanner == env_scanner, src.source_scanner def test_Builder_Args(self): """Testing passing extra args to a builder.""" diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index a78a2c90..0abc21b4 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -924,6 +924,7 @@ class Dir(Base): self.abspath_ = self.abspath + os.sep self.repositories = [] self.srcdir = None + self.source_scanner = None self.entries = {} self.entries['.'] = self diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 3802aad4..4dd0bd9e 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -111,9 +111,13 @@ class Node: self.implicit = None # implicit (scanned) dependencies (None means not scanned yet) self.parents = {} self.wkids = None # Kids yet to walk, when it's an array - self.source_scanner = None # implicit scanner from scanner map self.target_scanner = None # explicit scanner from this node's Builder + # If/when this attribute exists, it's an implicit scanner from + # the scanner map for an environment. The attribute is created + # when we select the scanner, a value of None means there is none. + #self.source_scanner = None + self.env = None self.state = None self.precious = None @@ -197,16 +201,21 @@ class Node: # Clear out the implicit dependency caches: # XXX this really should somehow be made more general and put # under the control of the scanners. - if self.source_scanner: - self.found_includes = {} - self.includes = None + try: + scanner = self.source_scanner + except AttributeError: + pass + else: + if scanner: + self.found_includes = {} + self.includes = None - def get_parents(node, parent): return node.get_parents() - def clear_cache(node, parent): - node.implicit = None - node.del_bsig() - w = Walker(self, get_parents, ignore_cycle, clear_cache) - while w.next(): pass + def get_parents(node, parent): return node.get_parents() + def clear_cache(node, parent): + node.implicit = None + node.del_bsig() + w = Walker(self, get_parents, ignore_cycle, clear_cache) + while w.next(): pass # clear out the content signature, since the contents of this # node were presumably just changed: @@ -384,11 +393,17 @@ class Node: build_env = self.get_build_env() for child in self.children(scan=0): - self._add_child(self.implicit, - self.implicit_dict, - child.get_implicit_deps(build_env, - child.source_scanner, - self)) + try: + scanner = child.source_scanner + except AttributeError: + pass + else: + if scanner: + self._add_child(self.implicit, + self.implicit_dict, + child.get_implicit_deps(build_env, + scanner, + self)) # scan this node itself for implicit dependencies self._add_child(self.implicit, diff --git a/test/HeaderGen.py b/test/HeaderGen.py new file mode 100644 index 00000000..9a3a6ab0 --- /dev/null +++ b/test/HeaderGen.py @@ -0,0 +1,57 @@ +#!/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__" + +""" +Test that dependencies in generated header files get re-scanned correctly. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """\ +def writeFile(target, contents): + file = open(str(target[0]), 'wb') + file.write(contents) + file.close() + return 0 + +env = Environment() +libgen = env.StaticLibrary('gen', 'gen.cpp') +Default(libgen) +env.Command('gen2.h', [], + lambda env,target,source: writeFile(target, 'int foo = 3;\\n')) +env.Command('gen.h', [], + lambda env,target,source: writeFile(target, '#include "gen2.h"\\n')) +env.Command('gen.cpp', [], + lambda env,target,source: writeFile(target, '#include "gen.h"\\n')) +""") + +test.run() + +test.up_to_date(arguments = '.') + +test.pass_test() diff --git a/test/HeaderInstall.py b/test/HeaderInstall.py new file mode 100644 index 00000000..523044cf --- /dev/null +++ b/test/HeaderInstall.py @@ -0,0 +1,69 @@ +#!/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__" + +""" +Test that dependencies in installed header files get re-scanned correctly. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +env = Environment(CPPPATH=['#include']) +Export('env') +SConscript('dist/SConscript') +libfoo = env.StaticLibrary('foo', ['foo.c']) +Default(libfoo) +""") + +test.write('foo.c', """ +#include +""") + +test.subdir('dist') + +test.write(['dist', 'SConscript'], """\ +Import('env') +env.Install('#include', ['h1.h', 'h2.h', 'h3.h']) +""") + +test.write(['dist', 'h1.h'], """\ +#include "h2.h" +""") + +test.write(['dist', 'h2.h'], """\ +#include "h3.h" +""") + +test.write(['dist', 'h3.h'], """\ +int foo = 3; +""") + +test.run(arguments = ".") + +test.up_to_date(arguments = ".") + +test.pass_test()