5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
30 python = TestSCons.python
32 test = TestSCons.TestSCons()
34 test.write('build.py', r"""
36 input = open(sys.argv[1], 'rb')
37 output = open(sys.argv[2], 'wb')
39 def process(infp, outfp):
40 for line in infp.readlines():
41 if line[:8] == 'include ':
43 process(open(file, 'rb'), outfp)
47 process(input, output)
52 # Execute a subsidiary SConscript just to make sure we can
53 # get at the Scanner keyword from there.
55 test.write('SConstruct', """
56 SConscript('SConscript')
59 test.write('SConscript', """
62 include_re = re.compile(r'^include\s+(\S+)$', re.M)
64 def kfile_scan(node, env, target, arg):
65 contents = node.get_contents()
66 includes = include_re.findall(contents)
69 kscan = Scanner(name = 'kfile',
70 function = kfile_scan,
73 scanners = Environment().Dictionary('SCANNERS')
74 env = Environment(SCANNERS = scanners + [kscan])
76 env.Command('foo', 'foo.k', r'%s build.py $SOURCES $TARGET')
78 bar_in = File('bar.in')
79 env.Command('bar', bar_in, r'%s build.py $SOURCES $TARGET')
80 bar_in.source_scanner = kscan
81 """ % (python, python))
97 test.write('xxx', "xxx 1\n")
99 test.write('yyy', "yyy 1\n")
101 test.write('zzz', "zzz 1\n")
103 test.run(arguments = '.')
105 test.fail_test(test.read('foo') != "foo.k 1 line 1\nxxx 1\nyyy 1\nfoo.k 1 line 4\n")
107 test.fail_test(test.read('bar') != "yyy 1\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
109 test.up_to_date(arguments = '.')
111 test.write('xxx', "xxx 2\n")
113 test.run(arguments = '.')
115 test.fail_test(test.read('foo') != "foo.k 1 line 1\nxxx 2\nyyy 1\nfoo.k 1 line 4\n")
117 test.fail_test(test.read('bar') != "yyy 1\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
119 test.write('yyy', "yyy 2\n")
121 test.run(arguments = '.')
123 test.fail_test(test.read('foo') != "foo.k 1 line 1\nxxx 2\nyyy 2\nfoo.k 1 line 4\n")
125 test.fail_test(test.read('bar') != "yyy 2\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
127 test.write('zzz', "zzz 2\n")
129 test.run(arguments = '.')
131 test.fail_test(test.read('foo') != "foo.k 1 line 1\nxxx 2\nyyy 2\nfoo.k 1 line 4\n")
133 test.fail_test(test.read('bar') != "yyy 2\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 2\n")
135 test.up_to_date(arguments = 'foo')