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__"
28 Verify that a source_scanner that uses a dictionary to select more
29 specific scanners for source file suffixes works correctly, even
30 when it's handed a file suffix that it doesn't know how to scan
31 (i.e., for which it doesn't have a specific scanner in its dictionary).
36 _python_ = TestSCons._python_
38 test = TestSCons.TestSCons()
40 test.write('build.py', r"""
42 output = open(sys.argv[1], 'wb')
43 for infile in sys.argv[2:]:
44 input = open(infile, 'rb')
46 include_prefix = 'include%s ' % infile[-1]
48 def process(infp, outfp, include_prefix=include_prefix):
49 for line in infp.readlines():
50 if line[:len(include_prefix)] == include_prefix:
51 file = line[len(include_prefix):-1]
52 process(open(file, 'rb'), outfp)
56 process(input, output)
61 # Execute a subsidiary SConscript just to make sure we can
62 # get at the Scanner keyword from there.
64 test.write('SConstruct', """
65 SConscript('SConscript')
68 test.write('SConscript', """
71 include1_re = re.compile(r'^include1\s+(\S+)$', re.M)
72 include2_re = re.compile(r'^include2\s+(\S+)$', re.M)
73 include3_re = re.compile(r'^include3\s+(\S+)$', re.M)
75 def k1_scan(node, env, scanpaths, arg=None):
76 contents = node.get_text_contents()
77 includes = include1_re.findall(contents)
80 def k2_scan(node, env, scanpaths, arg=None):
81 contents = node.get_text_contents()
82 includes = include2_re.findall(contents)
85 def k3_scan(node, env, scanpaths, arg=None):
86 contents = node.get_text_contents()
87 includes = include3_re.findall(contents)
90 kscanner = Scanner({'.k1' : Scanner(k1_scan), '.k2': Scanner(k2_scan)})
92 b = Builder(action=r'%(_python_)s build.py $TARGET $SOURCES',
93 source_scanner=kscanner)
94 env = Environment(BUILDERS={'Build':b})
96 kscanner.add_scanner('.k3', Scanner(k3_scan))
98 env.Build('aaa', 'aaa.k1')
99 env.Build('bbb', 'bbb.k2')
100 env.Build('ccc', 'ccc.k3')
101 env.Build('ddd', ['ddd.k4', 'aaa.k1', 'bbb.k2', 'ccc.k3'])
137 test.write('xxx', "xxx 1\n")
138 test.write('yyy', "yyy 1\n")
139 test.write('zzz', "zzz 1\n")
144 expect = test.wrap_stdout("""\
145 %(_python_)s build.py aaa aaa.k1
146 %(_python_)s build.py bbb bbb.k2
147 %(_python_)s build.py ccc ccc.k3
148 %(_python_)s build.py ddd ddd.k4 aaa.k1 bbb.k2 ccc.k3
151 test.run(stdout=expect)
153 expect_aaa = 'aaa.k1 1\nline 2\nxxx 1\ninclude2 yyy\ninclude3 zzz\nline 6\n'
154 expect_bbb = 'bbb.k2 1\nline 2\ninclude1 xxx\nyyy 1\ninclude3 zzz\nline 6\n'
155 expect_ccc = 'ccc.k3 1\nline 2\ninclude1 xxx\ninclude2 yyy\nzzz 1\nline 6\n'
156 expect_ddd = 'ddd.k4 1\nline 2\nline 3\n' + expect_aaa + expect_bbb + expect_ccc
158 test.must_match('aaa', expect_aaa)
159 test.must_match('bbb', expect_bbb)
160 test.must_match('ccc', expect_ccc)
161 test.must_match('ddd', expect_ddd)
163 test.up_to_date(arguments = '.')
167 test.write('zzz', "zzz 2\n")
169 expect = test.wrap_stdout("""\
170 %(_python_)s build.py ccc ccc.k3
171 %(_python_)s build.py ddd ddd.k4 aaa.k1 bbb.k2 ccc.k3
174 test.run(stdout=expect)
176 expect_ccc = 'ccc.k3 1\nline 2\ninclude1 xxx\ninclude2 yyy\nzzz 2\nline 6\n'
177 expect_ddd = 'ddd.k4 1\nline 2\nline 3\n' + expect_aaa + expect_bbb + expect_ccc
179 test.must_match('bbb', expect_bbb)
180 test.must_match('ddd', expect_ddd)
184 test.write('yyy', "yyy 2\n")
186 expect = test.wrap_stdout("""\
187 %(_python_)s build.py bbb bbb.k2
188 %(_python_)s build.py ddd ddd.k4 aaa.k1 bbb.k2 ccc.k3
191 test.run(stdout=expect)
193 expect_bbb = 'bbb.k2 1\nline 2\ninclude1 xxx\nyyy 2\ninclude3 zzz\nline 6\n'
194 expect_ddd = 'ddd.k4 1\nline 2\nline 3\n' + expect_aaa + expect_bbb + expect_ccc
196 test.must_match('bbb', expect_bbb)
197 test.must_match('ddd', expect_ddd)
201 test.write('xxx', "xxx 2\n")
203 expect = test.wrap_stdout("""\
204 %(_python_)s build.py aaa aaa.k1
205 %(_python_)s build.py ddd ddd.k4 aaa.k1 bbb.k2 ccc.k3
208 test.run(stdout=expect)
210 expect_aaa = 'aaa.k1 1\nline 2\nxxx 2\ninclude2 yyy\ninclude3 zzz\nline 6\n'
211 expect_ddd = 'ddd.k4 1\nline 2\nline 3\n' + expect_aaa + expect_bbb + expect_ccc
213 test.must_match('aaa', expect_aaa)
214 test.must_match('ddd', expect_ddd)
222 # indent-tabs-mode:nil
224 # vim: set expandtab tabstop=4 shiftwidth=4: