summaryrefslogtreecommitdiffstats
path: root/test/Scanner
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2006-11-02 16:21:36 (GMT)
committerSteven Knight <knight@baldmt.com>2006-11-02 16:21:36 (GMT)
commit6fcc7d78858a5ca068e3deea183d35295b7dd88e (patch)
treeea835f8b96e6c67766b4c0e6437f363d76164d39 /test/Scanner
parent66edd5ceedb4e6b83e6b4d03e244af74fe720041 (diff)
downloadSCons-6fcc7d78858a5ca068e3deea183d35295b7dd88e.zip
SCons-6fcc7d78858a5ca068e3deea183d35295b7dd88e.tar.gz
SCons-6fcc7d78858a5ca068e3deea183d35295b7dd88e.tar.bz2
Merged revisions 1582-1665 via svnmerge from
http://scons.tigris.org/svn/scons/branches/core ........ r1585 | stevenknight | 2006-08-06 21:21:12 -0500 (Sun, 06 Aug 2006) | 1 line 0.96.D430 - Fix bug with finding Fortran modules in build directories. (Nicolas Vigier) ........ r1586 | stevenknight | 2006-08-06 22:54:39 -0500 (Sun, 06 Aug 2006) | 1 line 0.96.D431 - Fix use of BuildDir when the source file is a relative-path symlink. (Nicola Vi ........ r1587 | timot | 2006-08-10 14:45:00 -0500 (Thu, 10 Aug 2006) | 1 line fix Platform SDK init ........ r1589 | stevenknight | 2006-08-12 13:28:51 -0500 (Sat, 12 Aug 2006) | 1 line 0.96.D432 - Change the default mingw linker from g++ to gcc. (Mariusz Olko) ........ r1590 | stevenknight | 2006-08-13 11:16:32 -0500 (Sun, 13 Aug 2006) | 1 line 0.96.D433 - More runtest.py enhancements. ........ r1594 | stevenknight | 2006-08-15 04:47:46 -0500 (Tue, 15 Aug 2006) | 1 line 0.96.D434 - Print the full path of SConscript files in stack traces. (Dobes Vandermeer) ........ r1600 | timot | 2006-08-16 11:34:44 -0500 (Wed, 16 Aug 2006) | 1 line add M4 to mingw tools ........ r1611 | stevenknight | 2006-08-19 16:25:24 -0500 (Sat, 19 Aug 2006) | 1 line 0.96.D435 - Add an SCons XMLResultStream to capture test results for mailing in. Get Aegis ........ r1617 | timot | 2006-08-21 16:19:03 -0500 (Mon, 21 Aug 2006) | 1 line handling of spawnve returning an error code that is not in exitvalmap ........ r1619 | stevenknight | 2006-09-01 19:07:47 -0500 (Fri, 01 Sep 2006) | 1 line 0.96.D436 - Win32 test portability and other test fixes. ........ r1620 | stevenknight | 2006-09-02 20:21:51 -0500 (Sat, 02 Sep 2006) | 2 lines Bring msvc.py in sync with Aegis repository. ........ r1621 | stevenknight | 2006-09-02 20:23:48 -0500 (Sat, 02 Sep 2006) | 2 lines Move to keep symlink tests together. ........ r1622 | garyo | 2006-09-06 11:51:42 -0500 (Wed, 06 Sep 2006) | 1 line Fix for Issue #1370; allow exit values not in exitvalmap. Added some tests for this kind of thing. Also improved win32 err msg if command exits with nonzero to show actual cmd, not just "cmd.exe". Note this fix improves posix and win32 behavior. ........ r1623 | stevenknight | 2006-09-07 06:35:16 -0500 (Thu, 07 Sep 2006) | 1 line 0.96.D440 - Fix runtest.py with QMTest on Windows. ........ r1625 | stevenknight | 2006-09-09 09:22:15 -0500 (Sat, 09 Sep 2006) | 3 lines Comment out a long-command test which fails on older Pythons (1.5.2) on Fedora Core 3. We can restore it in the future. ........ r1626 | stevenknight | 2006-09-09 16:17:44 -0500 (Sat, 09 Sep 2006) | 1 line 0.96.D441 - Allow Python Values to be the targets of Builders. (Anonymous) ........ r1627 | stevenknight | 2006-09-09 20:25:53 -0500 (Sat, 09 Sep 2006) | 1 line 0.96.D442 - Support src_dir on SConscript() calls. (Dobes Vandermeer) ........ r1628 | stevenknight | 2006-09-10 07:28:54 -0500 (Sun, 10 Sep 2006) | 1 line 0.96.D443 - Add miscellaneous utility scripts and config changes. ........ r1629 | stevenknight | 2006-09-11 04:45:01 -0500 (Mon, 11 Sep 2006) | 1 line 0.96.D444 - Add a test case for BuildDir handling of nested SConscript files. (Adam Simpkin ........ r1630 | stevenknight | 2006-09-11 11:34:07 -0500 (Mon, 11 Sep 2006) | 1 line 0.96.D445 - Workaround bug in early versions of thePython 2.4 profiler. ........ r1631 | stevenknight | 2006-09-19 19:12:51 -0500 (Tue, 19 Sep 2006) | 1 line 0.96.D446 - Fix Visual Studio common prefix handling to only treat common prefixes on comple ........ r1632 | stevenknight | 2006-09-25 07:11:44 -0500 (Mon, 25 Sep 2006) | 1 line 0.96.D447 - Fix tests that fail due to warnings from (some versions?) of gcc. (Sohail Soman ........ r1633 | stevenknight | 2006-09-25 07:57:48 -0500 (Mon, 25 Sep 2006) | 1 line 0.96.D448 - Handle python paths with quotes in tests. ........ r1634 | stevenknight | 2006-09-25 14:38:07 -0500 (Mon, 25 Sep 2006) | 1 line 0.96.D449 - Fix SCons build when python is not in the path (e.g. on Windows). (Chad Austin) ........ r1635 | stevenknight | 2006-09-26 11:28:23 -0500 (Tue, 26 Sep 2006) | 1 line 0.96.D450 - Handle warnings from Python 2.1; make sure we still test on Python 1.5. ........ r1636 | stevenknight | 2006-09-27 05:34:23 -0500 (Wed, 27 Sep 2006) | 1 line 0.96.D451 - Avoid calling Options validators and converters twice. ........ r1637 | stevenknight | 2006-09-28 08:12:38 -0500 (Thu, 28 Sep 2006) | 1 line 0.96.D452 - Allow setting MSVS_VERSION after initialization to select the Visual Studio vers ........ r1638 | stevenknight | 2006-09-30 08:38:15 -0500 (Sat, 30 Sep 2006) | 1 line 0.96.D453 - Give the MSVC resource builder a src_builder list and .rc src_suffix. (Leanid N ........ r1639 | stevenknight | 2006-10-12 08:50:58 -0500 (Thu, 12 Oct 2006) | 1 line 0.96.D454 - Test handling of env.Append() and env.Prepend(), making sure it works on later P ........ r1640 | stevenknight | 2006-10-15 20:42:09 -0500 (Sun, 15 Oct 2006) | 1 line 0.96.D455 - Support the runtest.py -f option when using QMTest. ........ r1641 | stevenknight | 2006-10-15 21:20:02 -0500 (Sun, 15 Oct 2006) | 1 line 0.96.D456 - Fix an error in ListOption handling caused by making new copies of Options objec ........ r1642 | stevenknight | 2006-10-16 05:53:14 -0500 (Mon, 16 Oct 2006) | 1 line 0.96.D457 - Fix new Append()/Prepend() handling of dictionaries in later Python versions (2. ........ r1643 | stevenknight | 2006-10-16 07:13:16 -0500 (Mon, 16 Oct 2006) | 1 line 0.96.D458 - Allow Install() to handle directories as sources. (Matthew A. Nicholson) ........ r1644 | stevenknight | 2006-10-17 09:17:58 -0500 (Tue, 17 Oct 2006) | 1 line 0.96.D459 - Add a test to make sure SideEffect() doesn't interfere with CacheDir(). Refacto ........ r1645 | stevenknight | 2006-10-17 10:20:22 -0500 (Tue, 17 Oct 2006) | 1 line 0.96.D460 - Do not use -fPIC when using gcc on win32 (MinGW). (Jan Nijtmans) ........ r1646 | stevenknight | 2006-10-17 17:21:58 -0500 (Tue, 17 Oct 2006) | 6 lines Move all the scons.org stuff from the scons source tree itself to a directory next to the trunk, and delete the copies from the branches. There's a lot of stuff there (what with all of the documentation of the different versions) and it's ridiculous to make everyone sync it just to work on the code. ........ r1647 | stevenknight | 2006-10-17 23:18:29 -0500 (Tue, 17 Oct 2006) | 1 line 0.96.D461 - Fix the tests of runtest.py so they skip appropriately if qmtest.py isn't instal ........ r1648 | stevenknight | 2006-10-18 08:48:47 -0500 (Wed, 18 Oct 2006) | 1 line 0.96.D462 - When using --implicit-cache, do not re-scan files if the scanner returned no imp ........ r1649 | stevenknight | 2006-10-18 19:42:13 -0500 (Wed, 18 Oct 2006) | 1 line 0.96.D463 - More test portability fixes. ........ r1650 | stevenknight | 2006-10-19 00:30:23 -0500 (Thu, 19 Oct 2006) | 1 line 0.96.D464 - Add a cpp.py module that knows how to find dependencies from #include lines like ........ r1651 | stevenknight | 2006-10-20 06:49:51 -0500 (Fri, 20 Oct 2006) | 1 line 0.96.D465 - Fix unresolved variable name in win32 portion of test. ........ r1652 | stevenknight | 2006-10-23 00:20:38 -0500 (Mon, 23 Oct 2006) | 1 line 0.96.D466 - Add an option for tracing files to and from the CacheDir. ........ r1653 | stevenknight | 2006-10-23 00:29:32 -0500 (Mon, 23 Oct 2006) | 1 line 0.96.D467 - Make {Append,Prepend}Unique() handle adding elements to empty lists like {Append ........ r1654 | stevenknight | 2006-10-23 02:38:06 -0500 (Mon, 23 Oct 2006) | 1 line 0.96.D468 - Allow Debug.caller() to take multiple arguments; add a debug utility to post-pro ........ r1655 | stevenknight | 2006-10-23 03:16:42 -0500 (Mon, 23 Oct 2006) | 1 line 0.96.D469 - Reduce unnecessary calls to Node.FS.disambiguate(), undoing (?) a performance hi ........ r1656 | stevenknight | 2006-10-25 00:06:27 -0500 (Wed, 25 Oct 2006) | 1 line 0.96.D470 - More test portability fixes. ........ r1657 | stevenknight | 2006-10-25 00:16:22 -0500 (Wed, 25 Oct 2006) | 1 line 0.96.D471 - Have runtest.py fall back to the --noqmtest option (with a warning) if qmtest.py ........ r1658 | stevenknight | 2006-10-25 12:12:02 -0500 (Wed, 25 Oct 2006) | 1 line 0.96.D472 - Document the default use of the /Z7 flag for Visual Studio and ways to use /Zi. ........ r1659 | stevenknight | 2006-10-26 23:53:51 -0500 (Thu, 26 Oct 2006) | 1 line 0.96.D473 - Have runtest.py -d accomodate different Python library locations. ........ r1660 | stevenknight | 2006-10-27 00:03:59 -0500 (Fri, 27 Oct 2006) | 1 line 0.96.D474 - Patch to support running SCons under WingIDE. (Allen Bierbaum) ........ r1661 | stevenknight | 2006-10-27 12:17:27 -0500 (Fri, 27 Oct 2006) | 1 line 0.96.D475 - Restore execution of all Environment unit tests. ........ r1662 | stevenknight | 2006-10-31 23:22:58 -0600 (Tue, 31 Oct 2006) | 1 line 0.96.D476 - Eliminate unnecessary print from a test, left over from debugging. ........ r1663 | stevenknight | 2006-10-31 23:32:00 -0600 (Tue, 31 Oct 2006) | 1 line 0.96.D477 - Support creating shared object files from assembly language. (James Y. Knight) ........ r1664 | stevenknight | 2006-10-31 23:44:08 -0600 (Tue, 31 Oct 2006) | 1 line 0.96.D478 - Fix the Memoizer to deal with a compiled .pyo or .pyc file that's in a different ........ r1665 | stevenknight | 2006-11-01 21:59:18 -0600 (Wed, 01 Nov 2006) | 1 line 0.96.D479 - Put back the scons-{LICENSE,README} files in the scons-loacal package; add tests ........
Diffstat (limited to 'test/Scanner')
-rw-r--r--test/Scanner/Scanner.py240
-rw-r--r--test/Scanner/empty-implicit.py81
-rw-r--r--test/Scanner/exception.py115
-rw-r--r--test/Scanner/generated.py427
-rw-r--r--test/Scanner/multi-env.py116
-rw-r--r--test/Scanner/parallel-rescan.py72
-rw-r--r--test/Scanner/scan-once.py94
7 files changed, 1145 insertions, 0 deletions
diff --git a/test/Scanner/Scanner.py b/test/Scanner/Scanner.py
new file mode 100644
index 0000000..09c5680
--- /dev/null
+++ b/test/Scanner/Scanner.py
@@ -0,0 +1,240 @@
+#!/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__"
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons()
+
+test.write('build.py', r"""
+import sys
+input = open(sys.argv[1], 'rb')
+output = open(sys.argv[2], 'wb')
+
+def process(infp, outfp):
+ for line in infp.readlines():
+ if line[:8] == 'include ':
+ file = line[8:-1]
+ process(open(file, 'rb'), outfp)
+ elif line[:8] == 'getfile ':
+ outfp.write('include ')
+ outfp.write(line[8:])
+ # note: converted, but not acted upon
+ else:
+ outfp.write(line)
+
+process(input, output)
+
+sys.exit(0)
+""")
+
+# Execute a subsidiary SConscript just to make sure we can
+# get at the Scanner keyword from there.
+
+test.write('SConstruct', """
+SConscript('SConscript')
+""")
+
+test.write('SConscript', """
+import re
+
+include_re = re.compile(r'^include\s+(\S+)$', re.M)
+
+def kfile_scan(node, env, scanpaths, arg):
+ contents = node.get_contents()
+ includes = include_re.findall(contents)
+ return includes
+
+kscan = Scanner(name = 'kfile',
+ function = kfile_scan,
+ argument = None,
+ skeys = ['.k'])
+
+env = Environment(K2SCAN=kfile_scan)
+
+k2scan = env.Scanner(name = 'k2',
+ # We'd like to do the following, but it will take
+ # some major surgery to subst() and subst_list(),
+ # so comment it out for now.
+ # function = '$K2SCAN',
+ function = kfile_scan,
+ argument = None,
+ skeys = ['.k2'])
+
+##########################################################
+# Test scanner as found automatically from the environment
+# (backup_source_scanner)
+
+env = Environment()
+env.Append(SCANNERS = kscan)
+
+env.Command('foo', 'foo.k', r'%(_python_)s build.py $SOURCES $TARGET')
+
+##########################################################
+# Test resetting the environment scanners (and specifying as a list).
+
+env2 = env.Copy()
+env2.Append(SCANNERS = [k2scan])
+env2.Command('junk', 'junk.k2', r'%(_python_)s build.py $SOURCES $TARGET')
+
+##########################################################
+# Test specifying a specific source scanner for a target Node
+
+barbld = Builder(action=r'%(_python_)s build.py $SOURCES $TARGET',
+ source_scanner=kscan)
+env.Append(BUILDERS={'BarBld':barbld})
+bar = env.BarBld(target='bar', source='bar.in')
+
+##########################################################
+# Test specifying a source scanner for a Builder that gets
+# automatically applied to targets generated from that Builder
+
+import string
+
+def blork(env, target, source):
+ open(str(target[0]), 'wb').write(
+ string.replace(source[0].get_contents(), 'getfile', 'MISSEDME'))
+
+kbld = Builder(action=r'%(_python_)s build.py $SOURCES $TARGET',
+ src_suffix='.lork',
+ suffix='.blork',
+ source_scanner=kscan)
+blorkbld = Builder(action=blork,
+ src_suffix='.blork',
+ suffix='.ork')
+
+env.Append(BUILDERS={'BLORK':blorkbld, 'KB':kbld})
+
+blork = env.KB('moo.lork')
+ork = env.BLORK(blork)
+Alias('make_ork', ork)
+
+""" % locals())
+
+test.write('foo.k',
+"""foo.k 1 line 1
+include xxx
+include yyy
+foo.k 1 line 4
+""")
+
+test.write('bar.in',
+"""include yyy
+bar.in 1 line 2
+bar.in 1 line 3
+include zzz
+""")
+
+test.write('junk.k2',
+"""include yyy
+junk.k2 1 line 2
+junk.k2 1 line 3
+include zzz
+""")
+
+test.write('moo.lork',
+"""include xxx
+moo.lork 1 line 2
+include yyy
+moo.lork 1 line 4
+include moo.inc
+""")
+
+test.write('moo.inc',
+"""getfile zzz
+""")
+
+test.write('xxx', "xxx 1\n")
+test.write('yyy', "yyy 1\n")
+test.write('zzz', "zzz 1\n")
+
+expect = test.wrap_stdout("""\
+%(_python_)s build.py bar.in bar
+%(_python_)s build.py foo.k foo
+%(_python_)s build.py junk.k2 junk
+%(_python_)s build.py moo.lork moo.blork
+blork(["moo.ork"], ["moo.blork"])
+""" % locals())
+
+test.run(arguments = '.', stdout=expect)
+
+test.must_match('foo', "foo.k 1 line 1\nxxx 1\nyyy 1\nfoo.k 1 line 4\n")
+test.must_match('bar', "yyy 1\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
+test.must_match('junk', "yyy 1\njunk.k2 1 line 2\njunk.k2 1 line 3\nzzz 1\n")
+test.must_match('moo.ork', "xxx 1\nmoo.lork 1 line 2\nyyy 1\nmoo.lork 1 line 4\ninclude zzz\n")
+
+test.up_to_date(arguments = '.')
+
+test.write('xxx', "xxx 2\n")
+
+expect = test.wrap_stdout("""\
+%(_python_)s build.py foo.k foo
+%(_python_)s build.py moo.lork moo.blork
+blork(["moo.ork"], ["moo.blork"])
+""" % locals())
+
+test.run(arguments = '.', stdout=expect)
+
+test.must_match('foo', "foo.k 1 line 1\nxxx 2\nyyy 1\nfoo.k 1 line 4\n")
+test.must_match('bar', "yyy 1\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
+test.must_match('junk', "yyy 1\njunk.k2 1 line 2\njunk.k2 1 line 3\nzzz 1\n")
+test.must_match('moo.ork', "xxx 2\nmoo.lork 1 line 2\nyyy 1\nmoo.lork 1 line 4\ninclude zzz\n")
+
+test.write('yyy', "yyy 2\n")
+
+expect = test.wrap_stdout("""\
+%(_python_)s build.py bar.in bar
+%(_python_)s build.py foo.k foo
+%(_python_)s build.py junk.k2 junk
+%(_python_)s build.py moo.lork moo.blork
+blork(["moo.ork"], ["moo.blork"])
+""" % locals())
+
+test.run(arguments = '.', stdout=expect)
+
+test.must_match('foo', "foo.k 1 line 1\nxxx 2\nyyy 2\nfoo.k 1 line 4\n")
+test.must_match('bar', "yyy 2\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
+test.must_match('junk', "yyy 2\njunk.k2 1 line 2\njunk.k2 1 line 3\nzzz 1\n")
+test.must_match('moo.ork', "xxx 2\nmoo.lork 1 line 2\nyyy 2\nmoo.lork 1 line 4\ninclude zzz\n")
+
+test.write('zzz', "zzz 2\n")
+
+expect = test.wrap_stdout("""\
+%(_python_)s build.py bar.in bar
+%(_python_)s build.py junk.k2 junk
+""" % locals())
+
+test.run(arguments = '.', stdout=expect)
+
+test.must_match('foo', "foo.k 1 line 1\nxxx 2\nyyy 2\nfoo.k 1 line 4\n")
+test.must_match('bar', "yyy 2\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 2\n")
+test.must_match('junk', "yyy 2\njunk.k2 1 line 2\njunk.k2 1 line 3\nzzz 2\n")
+test.must_match('moo.ork', "xxx 2\nmoo.lork 1 line 2\nyyy 2\nmoo.lork 1 line 4\ninclude zzz\n")
+
+test.up_to_date(arguments = 'foo')
+
+test.pass_test()
diff --git a/test/Scanner/empty-implicit.py b/test/Scanner/empty-implicit.py
new file mode 100644
index 0000000..2112fd8
--- /dev/null
+++ b/test/Scanner/empty-implicit.py
@@ -0,0 +1,81 @@
+#!/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__"
+
+"""
+Verify that Scanners are not called if a previous --implicit-cache
+run stored an empty list of implicit dependencies.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', r"""
+import os.path
+
+def scan(node, env, envkey, arg):
+ print 'XScanner: node =', os.path.split(str(node))[1]
+ return []
+
+def exists_check(node, env):
+ return os.path.exists(str(node))
+
+XScanner = Scanner(name = 'XScanner',
+ function = scan,
+ argument = None,
+ scan_check = exists_check,
+ skeys = ['.x'])
+
+def echo(env, target, source):
+ t = os.path.split(str(target[0]))[1]
+ s = os.path.split(str(source[0]))[1]
+ print 'create %s from %s' % (t, s)
+ open(t, 'wb').write(open(s, 'rb').read())
+
+Echo = Builder(action = Action(echo, None),
+ src_suffix = '.x',
+ suffix = '.x')
+
+env = Environment(BUILDERS = {'Echo':Echo}, SCANNERS = [XScanner])
+
+f1 = env.Echo(source=['f1_in'], target=['f1_out'])
+""")
+
+test.write('f1_in.x', 'f1_in.x\n')
+
+expect = test.wrap_stdout("""\
+XScanner: node = f1_in.x
+create f1_out.x from f1_in.x
+""")
+
+test.run(arguments = '--implicit-cache .', stdout = expect)
+
+# Run it again, and the output must contain only the "up to date" message,
+# *not* the line printed by the XScanner function.
+
+test.up_to_date(options = '--implicit-cache', arguments = '.')
+
+test.pass_test()
diff --git a/test/Scanner/exception.py b/test/Scanner/exception.py
new file mode 100644
index 0000000..7615888
--- /dev/null
+++ b/test/Scanner/exception.py
@@ -0,0 +1,115 @@
+#!/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__"
+
+import string
+import sys
+import TestSCons
+
+python = TestSCons.python
+
+test = TestSCons.TestSCons()
+
+# Execute a subsidiary SConscript just to make sure we can
+# get at the SCanners keyword from there.
+
+test.write('SConstruct', """
+SConscript('SConscript')
+""")
+
+test.write('SConscript', """
+import re
+
+include_re = re.compile(r'^include\s+(\S+)$', re.M)
+exception_re = re.compile(r'^exception\s+(.+)$', re.M)
+
+def kfile_scan(node, env, target, arg):
+ contents = node.get_contents()
+ exceptions = exception_re.findall(contents)
+ if exceptions:
+ raise "kfile_scan error: %s" % exceptions[0]
+ includes = include_re.findall(contents)
+ return includes
+
+kscan = Scanner(name = 'kfile',
+ function = kfile_scan,
+ argument = None,
+ recursive = 1,
+ skeys = ['.k'])
+
+def process(outf, inf):
+ for line in inf.readlines():
+ if line[:8] == 'include ':
+ file = line[8:-1]
+ process(outf, open(file, 'rb'))
+ else:
+ outf.write(line)
+
+def cat(env, source, target):
+ target = str(target[0])
+ source = map(str, source)
+
+ outf = open(target, 'wb')
+ for src in source:
+ process(outf, open(src, 'rb'))
+ outf.close()
+
+env = Environment(BUILDERS={'Cat':Builder(action=cat)})
+env.Append(SCANNERS = [kscan])
+
+env.Cat('foo', 'foo.k')
+
+bar_in = File('bar.in')
+env.Cat('bar', bar_in)
+bar_in.source_scanner = kscan
+""")
+
+test.write('foo.k',
+"""foo.k 1 line 1
+include xxx
+include yyy
+foo.k 1 line 4
+""")
+
+test.write('bar.in',
+"""include yyy
+bar.in 1 line 2
+bar.in 1 line 3
+include zzz
+""")
+
+test.write('xxx', "xxx 1\n")
+
+test.write('yyy', "exception yyy 1\n")
+
+test.write('zzz', "zzz 1\n")
+
+test.run(arguments = '.',
+ status = 2,
+ stderr = """\
+scons: *** kfile_scan error: yyy 1
+""")
+
+test.pass_test()
diff --git a/test/Scanner/generated.py b/test/Scanner/generated.py
new file mode 100644
index 0000000..36f35f6
--- /dev/null
+++ b/test/Scanner/generated.py
@@ -0,0 +1,427 @@
+#!/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__"
+
+"""
+Verify that we only scan generated .h files once.
+
+This originated as a real-life bug report submitted by Scott Lystig
+Fritchie. It's been left as-is, rather than stripped down to bear
+minimum, partly because it wasn't completely clear what combination of
+factors triggered the bug Scott saw, and partly because the real-world
+complexity is valuable in its own right.
+"""
+
+import os.path
+import sys
+
+import TestCmd
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.subdir('reftree',
+ ['reftree', 'include'],
+ 'src',
+ ['src', 'lib_geng'])
+
+test.write('SConstruct', """\
+###
+### QQQ !@#$!@#$! I need to move the SConstruct file to be "above"
+### both the source and install dirs, or the install dependencies
+### don't seem to work well! ARRGH!!!!
+###
+
+experimenttop = r"%s"
+
+import os
+import os.path
+import string
+import Mylib
+
+BStaticLibMerge = Builder(generator = Mylib.Gen_StaticLibMerge)
+builders = Environment().Dictionary('BUILDERS')
+builders["StaticLibMerge"] = BStaticLibMerge
+
+env = Environment(BUILDERS = builders)
+e = env.Dictionary() # Slightly easier to type
+
+global_env = env
+e["GlobalEnv"] = global_env
+
+e["REF_INCLUDE"] = os.path.join(experimenttop, "reftree", "include")
+e["REF_LIB"] = os.path.join(experimenttop, "reftree", "lib")
+e["EXPORT_INCLUDE"] = os.path.join(experimenttop, "export", "include")
+e["EXPORT_LIB"] = os.path.join(experimenttop, "export", "lib")
+e["INSTALL_BIN"] = os.path.join(experimenttop, "install", "bin")
+
+build_dir = os.path.join(experimenttop, "tmp-bld-dir")
+src_dir = os.path.join(experimenttop, "src")
+
+env.Append(CPPPATH = [e["EXPORT_INCLUDE"]])
+env.Append(CPPPATH = [e["REF_INCLUDE"]])
+Mylib.AddLibDirs(env, "/via/Mylib.AddLibPath")
+env.Append(LIBPATH = [e["EXPORT_LIB"]])
+env.Append(LIBPATH = [e["REF_LIB"]])
+
+Mylib.Subdirs(env, "src")
+""" % test.workpath())
+
+test.write('Mylib.py', """\
+import os
+import string
+import re
+
+def Subdirs(env, dirlist):
+ for file in _subconf_list(dirlist):
+ env.SConscript(file, "env")
+
+def _subconf_list(dirlist):
+ return map(lambda x: os.path.join(x, "SConscript"), string.split(dirlist))
+
+def StaticLibMergeMembers(local_env, libname, hackpath, files):
+ for file in string.split(files):
+ # QQQ Fix limits in grok'ed regexp
+ tmp = re.sub(".c$", ".o", file)
+ objname = re.sub(".cpp", ".o", tmp)
+ local_env.Object(target = objname, source = file)
+ e = 'local_env["GlobalEnv"].Append(%s = ["%s"])' % (libname, os.path.join(hackpath, objname))
+ exec(e)
+
+def CreateMergedStaticLibrary(env, libname):
+ objpaths = env["GlobalEnv"][libname]
+ libname = "lib%s.a" % (libname)
+ env.StaticLibMerge(target = libname, source = objpaths)
+
+# I put the main body of the generator code here to avoid
+# namespace problems
+def Gen_StaticLibMerge(source, target, env, for_signature):
+ target_string = ""
+ for t in target:
+ target_string = str(t)
+ subdir = os.path.dirname(target_string)
+ srclist = []
+ for src in source:
+ srclist.append(src)
+ return [["ar", "cq"] + target + srclist, ["ranlib"] + target]
+
+def StaticLibrary(env, target, source):
+ env.StaticLibrary(target, string.split(source))
+
+def SharedLibrary(env, target, source):
+ env.SharedLibrary(target, string.split(source))
+
+def ExportHeader(env, headers):
+ env.Install(dir = env["EXPORT_INCLUDE"], source = string.split(headers))
+
+def ExportLib(env, libs):
+ env.Install(dir = env["EXPORT_LIB"], source = string.split(libs))
+
+def InstallBin(env, bins):
+ env.Install(dir = env["INSTALL_BIN"], source = string.split(bins))
+
+def Program(env, target, source):
+ env.Program(target, string.split(source))
+
+def AddCFlags(env, str):
+ env.Append(CPPFLAGS = " " + str)
+
+# QQQ Synonym needed?
+#def AddCFLAGS(env, str):
+# AddCFlags(env, str)
+
+def AddIncludeDirs(env, str):
+ env.Append(CPPPATH = string.split(str))
+
+def AddLibs(env, str):
+ env.Append(LIBS = string.split(str))
+
+def AddLibDirs(env, str):
+ env.Append(LIBPATH = string.split(str))
+
+""")
+
+test.write(['reftree', 'include', 'lib_a.h'], """\
+char *a_letter(void);
+""")
+
+test.write(['reftree', 'include', 'lib_b.h'], """\
+char *b_letter(void);
+""")
+
+test.write(['reftree', 'include', 'lib_ja.h'], """\
+char *j_letter_a(void);
+""")
+
+test.write(['reftree', 'include', 'lib_jb.h.intentionally-moved'], """\
+char *j_letter_b(void);
+""")
+
+test.write(['src', 'SConscript'], """\
+# --- Begin SConscript boilerplate ---
+import Mylib
+Import("env")
+
+#env = env.Copy() # Yes, clobber intentionally
+#Make environment changes, such as: Mylib.AddCFlags(env, "-g -D_TEST")
+#Mylib.Subdirs(env, "lib_a lib_b lib_mergej prog_x")
+Mylib.Subdirs(env, "lib_geng")
+
+env = env.Copy() # Yes, clobber intentionally
+# --- End SConscript boilerplate ---
+
+""")
+
+test.write(['src', 'lib_geng', 'SConscript'], """\
+# --- Begin SConscript boilerplate ---
+import string
+import sys
+import Mylib
+Import("env")
+
+#env = env.Copy() # Yes, clobber intentionally
+#Make environment changes, such as: Mylib.AddCFlags(env, "-g -D_TEST")
+#Mylib.Subdirs(env, "foo_dir")
+
+env = env.Copy() # Yes, clobber intentionally
+# --- End SConscript boilerplate ---
+
+Mylib.AddCFlags(env, "-DGOOFY_DEMO")
+Mylib.AddIncludeDirs(env, ".")
+
+# Not part of Scott Lystig Fritchies's original stuff:
+# On Windows, it's import to use the original test environment
+# when we invoke SCons recursively.
+import os
+recurse_env = env.Copy()
+recurse_env["ENV"] = os.environ
+
+# Icky code to set up process environment for "make"
+# I really ought to drop this into Mylib....
+
+fromdict = env.Dictionary()
+todict = env["ENV"]
+import SCons.Util
+import re
+for k in fromdict.keys():
+ if k != "ENV" and k != "SCANNERS" and k != "CFLAGS" and k != "CXXFLAGS" \
+ and not SCons.Util.is_Dict(fromdict[k]):
+ # The next line can fail on some systems because it would try to
+ # do env.subst on:
+ # $RMIC $RMICFLAGS -d ${TARGET.attributes.java_lookupdir} ...
+ # When $TARGET is None, so $TARGET.attributes would throw an
+ # exception.
+ f = fromdict[k]
+ if SCons.Util.is_String(f) and \
+ string.find(f, "TARGET") == -1 and \
+ string.find(f, "SOURCE") == -1:
+ todict[k] = env.subst(f)
+todict["CFLAGS"] = fromdict["CPPFLAGS"] + " " + \
+ string.join(map(lambda x: "-I" + x, env["CPPPATH"])) + " " + \
+ string.join(map(lambda x: "-L" + x, env["LIBPATH"]))
+todict["CXXFLAGS"] = todict["CFLAGS"]
+
+generated_hdrs = "libg_gx.h libg_gy.h libg_gz.h"
+static_hdrs = "libg_w.h"
+#exported_hdrs = generated_hdrs + " " + static_hdrs
+exported_hdrs = static_hdrs
+lib_name = "g"
+lib_fullname = env.subst("${LIBPREFIX}g${LIBSUFFIX}")
+lib_srcs = string.split("libg_1.c libg_2.c libg_3.c")
+import re
+lib_objs = map(lambda x: re.sub("\.c$", ".o", x), lib_srcs)
+
+Mylib.ExportHeader(env, exported_hdrs)
+Mylib.ExportLib(env, lib_fullname)
+
+# The following were the original commands from Scott Lystic Fritchie,
+# making use of a shell script and a Makefile to build the library.
+# These have been preserved, commented out below, but in order to make
+# this test portable, we've replaced them with a Python script and a
+# recursive invocation of SCons (!).
+#cmd_both = "cd %s ; make generated ; make" % Dir(".")
+#cmd_generated = "cd %s ; sh MAKE-HEADER.sh" % Dir(".")
+#cmd_justlib = "cd %s ; make" % Dir(".")
+
+_ws = re.compile('\s')
+
+def escape(s):
+ if _ws.search(s):
+ s = '"' + s + '"'
+ return s
+
+cmd_generated = "%s $SOURCE" % escape(sys.executable)
+cmd_justlib = "%s %s -C ${SOURCES[0].dir}" % (escape(sys.executable),
+ escape(sys.argv[0]))
+
+##### Deps appear correct ... but wacky scanning?
+# Why?
+#
+# SCons bug??
+
+env.Command(string.split(generated_hdrs),
+ ["MAKE-HEADER.py"],
+ cmd_generated)
+recurse_env.Command([lib_fullname] + lib_objs,
+ lib_srcs + string.split(generated_hdrs + " " + static_hdrs),
+ cmd_justlib)
+""")
+
+test.write(['src', 'lib_geng', 'MAKE-HEADER.py'], """\
+#!/usr/bin/env python
+
+import os
+import os.path
+import sys
+
+# chdir to the directory in which this script lives
+os.chdir(os.path.split(sys.argv[0])[0])
+
+for h in ['libg_gx.h', 'libg_gy.h', 'libg_gz.h']:
+ open(h, 'w').write('')
+""")
+
+test.write(['src', 'lib_geng', 'SConstruct'], """\
+import os
+
+Scanned = {}
+
+def write_out(file, dict):
+ keys = dict.keys()
+ keys.sort()
+ f = open(file, 'wb')
+ for k in keys:
+ file = os.path.split(k)[1]
+ f.write(file + ": " + str(dict[k]) + "\\n")
+ f.close()
+
+orig_function = CScan.scan
+
+def MyCScan(node, paths, orig_function=orig_function):
+ deps = orig_function(node, paths)
+
+ global Scanned
+ n = str(node)
+ try:
+ Scanned[n] = Scanned[n] + 1
+ except KeyError:
+ Scanned[n] = 1
+ write_out(r'%s', Scanned)
+
+ return deps
+
+CScan.scan = MyCScan
+
+env = Environment(CPPPATH = ".")
+l = env.StaticLibrary("g", Split("libg_1.c libg_2.c libg_3.c"))
+Default(l)
+""" % test.workpath('MyCScan.out'))
+
+# These were the original shell script and Makefile from SLF's original
+# bug report. We're not using them--in order to make this script as
+# portable as possible, we're using a Python script and a recursive
+# invocation of SCons--but we're preserving them here for history.
+#test.write(['src', 'lib_geng', 'MAKE-HEADER.sh'], """\
+##!/bin/sh
+#
+#exec touch $*
+#""")
+#
+#test.write(['src', 'lib_geng', 'Makefile'], """\
+#all: libg.a
+#
+#GEN_HDRS = libg_gx.h libg_gy.h libg_gz.h
+#STATIC_HDRS = libg_w.h
+#
+#$(GEN_HDRS): generated
+#
+#generated: MAKE-HEADER.sh
+# sh ./MAKE-HEADER.sh $(GEN_HDRS)
+#
+#libg.a: libg_1.o libg_2.o libg_3.o
+# ar r libg.a libg_1.o libg_2.o libg_3.o
+#
+#libg_1.c: $(STATIC_HDRS) $(GEN_HDRS)
+#libg_2.c: $(STATIC_HDRS) $(GEN_HDRS)
+#libg_3.c: $(STATIC_HDRS) $(GEN_HDRS)
+#
+#clean:
+# -rm -f $(GEN_HDRS)
+# -rm -f libg.a *.o core core.*
+#""")
+
+test.write(['src', 'lib_geng', 'libg_w.h'], """\
+""")
+
+test.write(['src', 'lib_geng', 'libg_1.c'], """\
+#include <libg_w.h>
+#include <libg_gx.h>
+
+int g_1()
+{
+ return 1;
+}
+""")
+
+test.write(['src', 'lib_geng', 'libg_2.c'], """\
+#include <libg_w.h>
+#include <libg_gx.h>
+#include <libg_gy.h>
+#include <libg_gz.h>
+
+int g_2()
+{
+ return 2;
+}
+""")
+
+test.write(['src', 'lib_geng', 'libg_3.c'], """\
+#include <libg_w.h>
+#include <libg_gx.h>
+
+int g_3()
+{
+ return 3;
+}
+""")
+
+test.run(stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
+
+# XXX Note that the generated .h files still get scanned twice,
+# once before they're generated and once after. That's the
+# next thing to fix here.
+
+test.must_match("MyCScan.out", """\
+libg_1.c: 1
+libg_2.c: 1
+libg_3.c: 1
+libg_gx.h: 1
+libg_gy.h: 1
+libg_gz.h: 1
+libg_w.h: 1
+""")
+
+test.pass_test()
diff --git a/test/Scanner/multi-env.py b/test/Scanner/multi-env.py
new file mode 100644
index 0000000..514fbca
--- /dev/null
+++ b/test/Scanner/multi-env.py
@@ -0,0 +1,116 @@
+#!/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 using the same source file in different environments
+will get the proper scanner for the environment being used.
+"""
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons()
+
+
+test.write('SConstruct', """
+import re
+
+include_re = re.compile(r'^include\s+(\S+)$', re.M)
+input_re = re.compile(r'^input\s+(\S+)$', re.M)
+
+scan1 = Scanner(name = 'Include',
+ function = lambda N,E,P,A: A.findall(N.get_contents()),
+ argument = include_re,
+ skeys = ['.inp'])
+
+scan2 = Scanner(name = 'Input',
+ function = lambda N,E,P,A: A.findall(N.get_contents()),
+ argument = input_re,
+ skeys = ['.inp'])
+
+env1 = Environment()
+env2 = Environment()
+
+env1.Append(SCANNERS=scan1)
+env2.Append(SCANNERS=scan2)
+
+env1.Command('frog.1', 'frog.inp', r'%(_python_)s do_incl.py $TARGET $SOURCES')
+env2.Command('frog.2', 'frog.inp', r'%(_python_)s do_inp.py $TARGET $SOURCES')
+
+""" % locals())
+
+process = r"""
+import sys
+
+def process(infp, outfp):
+ prefix = '%(command)s '
+ l = len(prefix)
+ for line in infp.readlines():
+ if line[:l] == prefix:
+ process(open(line[l:-1], 'rb'), outfp)
+ else:
+ outfp.write(line)
+
+process(open(sys.argv[2], 'rb'),
+ open(sys.argv[1], 'wb'))
+sys.exit(0)
+"""
+
+test.write('do_incl.py', process % { 'command' : 'include' })
+test.write('do_inp.py', process % { 'command' : 'input' })
+
+test.write('frog.inp', """\
+include sound1
+input sound2
+""")
+
+test.write('sound1', 'croak\n')
+test.write('sound2', 'ribbet\n')
+
+expect = test.wrap_stdout("""\
+%(_python_)s do_incl.py frog.1 frog.inp
+%(_python_)s do_inp.py frog.2 frog.inp
+""" % locals())
+
+test.run(arguments='.', stdout=expect)
+
+test.must_match('frog.1', 'croak\ninput sound2\n')
+test.must_match('frog.2', 'include sound1\nribbet\n')
+
+test.write('sound2', 'rudeep\n')
+
+expect = test.wrap_stdout("""\
+%(_python_)s do_inp.py frog.2 frog.inp
+""" % locals())
+
+test.run(arguments='.', stdout=expect)
+
+test.must_match('frog.1', 'croak\ninput sound2\n')
+test.must_match('frog.2', 'include sound1\nrudeep\n')
+
+test.pass_test()
diff --git a/test/Scanner/parallel-rescan.py b/test/Scanner/parallel-rescan.py
new file mode 100644
index 0000000..4a1f27e
--- /dev/null
+++ b/test/Scanner/parallel-rescan.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__"
+
+"""
+Verify that when a source file is generated and the -j option is used,
+the source file correctly gets re-scanned for implicit dependencies
+after it's built.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """\
+env = Environment()
+env['BUILDERS']['COPY'] = Builder(action = Copy("$TARGET", "$SOURCE"))
+
+env.COPY('a.c', 'a.in')
+env.COPY('b.c', 'b.in')
+
+env.StaticLibrary('lib', ['a.c', 'b.c'])
+""")
+
+test.write("a.in", """\
+#include "a.h"
+""")
+
+test.write("b.in", """\
+#include "b.h"
+""")
+
+test.write("a.h", """\
+char *A_FILE = "b.in";
+""")
+
+test.write("b.h", """\
+char *B_FILE = "b.in";
+""")
+
+test.run(arguments = '-j4 .',
+ stderr=TestSCons.noisy_ar,
+ match=TestSCons.match_re_dotall)
+
+# If the dependencies weren't re-scanned properly, the .h files won't
+# show up in the previous run's dependency lists, and the .o files and
+# library will get rebuilt here.
+test.up_to_date(arguments = '.')
+
+test.pass_test()
diff --git a/test/Scanner/scan-once.py b/test/Scanner/scan-once.py
new file mode 100644
index 0000000..7e02dd2
--- /dev/null
+++ b/test/Scanner/scan-once.py
@@ -0,0 +1,94 @@
+#!/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__"
+
+"""
+Verify that Scanners are called just once.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', r"""
+import os.path
+
+def scan(node, env, envkey, arg):
+ print 'XScanner: node =', os.path.split(str(node))[1]
+ return []
+
+def exists_check(node, env):
+ return os.path.exists(str(node))
+
+XScanner = Scanner(name = 'XScanner',
+ function = scan,
+ argument = None,
+ scan_check = exists_check,
+ skeys = ['.x'])
+
+def echo(env, target, source):
+ t = os.path.split(str(target[0]))[1]
+ s = os.path.split(str(source[0]))[1]
+ print 'create %s from %s' % (t, s)
+
+Echo = Builder(action = Action(echo, None),
+ src_suffix = '.x',
+ suffix = '.x')
+
+env = Environment(BUILDERS = {'Echo':Echo}, SCANNERS = [XScanner])
+
+f1 = env.Echo(source=['file1'], target=['file2'])
+f2 = env.Echo(source=['file2'], target=['file3'])
+f3 = env.Echo(source=['file3'], target=['file4'])
+""")
+
+test.write('file1.x', 'file1.x\n')
+
+test.run(stdout = test.wrap_stdout("""\
+XScanner: node = file1.x
+create file2.x from file1.x
+create file3.x from file2.x
+create file4.x from file3.x
+"""))
+
+test.write('file2.x', 'file2.x\n')
+
+test.run(stdout = test.wrap_stdout("""\
+XScanner: node = file1.x
+XScanner: node = file2.x
+create file3.x from file2.x
+create file4.x from file3.x
+"""))
+
+test.write('file3.x', 'file3.x\n')
+
+test.run(stdout = test.wrap_stdout("""\
+XScanner: node = file1.x
+XScanner: node = file2.x
+XScanner: node = file3.x
+create file4.x from file3.x
+"""))
+
+test.pass_test()