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__"
33 _python_
= TestSCons
._python
_
35 test
= TestSCons
.TestSCons()
37 test
.write('build.py', r
"""
40 include_prefix = 'include%s ' % sys.argv[1][-1]
42 def process(infp, outfp):
43 for line in infp.readlines():
44 if line[:len(include_prefix)] == include_prefix:
45 file = line[len(include_prefix):-1]
46 with open(file, 'r') as f:
51 with open(sys.argv[2], 'w') as ofp, open(sys.argv[1], 'r') as ifp:
57 # Execute a subsidiary SConscript just to make sure we can
58 # get at the Scanner keyword from there.
60 test
.write('SConstruct', """
61 SConscript('SConscript')
64 test
.write('SConscript', r
"""
67 include1_re = re.compile(r'^include1\s+(\S+)$', re.M)
68 include2_re = re.compile(r'^include2\s+(\S+)$', re.M)
69 include3_re = re.compile(r'^include3\s+(\S+)$', re.M)
71 def kfile_scan1(node, env, scanpaths, arg=None):
72 contents = node.get_text_contents()
73 includes = include1_re.findall(contents)
76 def kfile_scan2(node, env, scanpaths, arg=None):
77 contents = node.get_text_contents()
78 includes = include2_re.findall(contents)
81 def kfile_scan3(node, env, scanpaths, arg=None):
82 contents = node.get_text_contents()
83 includes = include3_re.findall(contents)
86 scan1 = Scanner(kfile_scan1)
88 scan2 = Scanner(kfile_scan2)
90 scan3 = Scanner(kfile_scan3)
92 kscanner = Scanner({'.k1' : scan1, '.k2': scan2})
94 env = Environment(SCANNERS = [kscanner])
96 kscanner.add_scanner('.k3', scan3)
98 env.Command('aaa', 'aaa.k1', r'%(_python_)s build.py $SOURCES $TARGET')
99 env.Command('bbb', 'bbb.k2', r'%(_python_)s build.py $SOURCES $TARGET')
100 env.Command('ccc', 'ccc.k3', r'%(_python_)s build.py $SOURCES $TARGET')
130 test
.write('xxx', "xxx 1\n")
131 test
.write('yyy', "yyy 1\n")
132 test
.write('zzz', "zzz 1\n")
137 expect
= test
.wrap_stdout("""\
138 %(_python_)s build.py aaa.k1 aaa
139 %(_python_)s build.py bbb.k2 bbb
140 %(_python_)s build.py ccc.k3 ccc
143 test
.run(stdout
=expect
)
145 expect_aaa
= 'aaa.k1 1\nline 2\nxxx 1\ninclude2 yyy\ninclude3 zzz\nline 6\n'
146 expect_bbb
= 'bbb.k2 1\nline 2\ninclude1 xxx\nyyy 1\ninclude3 zzz\nline 6\n'
147 expect_ccc
= 'ccc.k3 1\nline 2\ninclude1 xxx\ninclude2 yyy\nzzz 1\nline 6\n'
149 test
.must_match('aaa', expect_aaa
, mode
='r')
150 test
.must_match('bbb', expect_bbb
, mode
='r')
151 test
.must_match('ccc', expect_ccc
, mode
='r')
153 test
.up_to_date(arguments
= '.')
157 test
.write('zzz', "zzz 2\n")
159 expect
= test
.wrap_stdout("""\
160 %(_python_)s build.py ccc.k3 ccc
163 test
.run(stdout
=expect
)
165 expect_ccc
= 'ccc.k3 1\nline 2\ninclude1 xxx\ninclude2 yyy\nzzz 2\nline 6\n'
167 test
.must_match('bbb', expect_bbb
, mode
='r')
171 test
.write('yyy', "yyy 2\n")
173 expect
= test
.wrap_stdout("""\
174 %(_python_)s build.py bbb.k2 bbb
177 test
.run(stdout
=expect
)
179 expect_bbb
= 'bbb.k2 1\nline 2\ninclude1 xxx\nyyy 2\ninclude3 zzz\nline 6\n'
181 test
.must_match('bbb', expect_bbb
, mode
='r')
185 test
.write('xxx', "xxx 2\n")
187 expect
= test
.wrap_stdout("""\
188 %(_python_)s build.py aaa.k1 aaa
191 test
.run(stdout
=expect
)
193 expect_aaa
= 'aaa.k1 1\nline 2\nxxx 2\ninclude2 yyy\ninclude3 zzz\nline 6\n'
195 test
.must_match('bbb', expect_bbb
, mode
='r')
203 # indent-tabs-mode:nil
205 # vim: set expandtab tabstop=4 shiftwidth=4: