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__"
29 _python_ = TestSCons._python_
31 test = TestSCons.TestSCons()
33 test.write('build.py', r"""
35 input = open(sys.argv[1], 'rb')
36 output = open(sys.argv[2], 'wb')
38 def process(infp, outfp):
39 for line in infp.readlines():
40 if line[:8] == 'include ':
42 process(open(file, 'rb'), outfp)
43 elif line[:8] == 'getfile ':
44 outfp.write('include ')
46 # note: converted, but not acted upon
50 process(input, output)
55 # Execute a subsidiary SConscript just to make sure we can
56 # get at the Scanner keyword from there.
58 test.write('SConstruct', """
59 SConscript('SConscript')
62 test.write('SConscript', """
65 include_re = re.compile(r'^include\s+(\S+)$', re.M)
67 def kfile_scan(node, env, scanpaths, arg):
68 contents = node.get_text_contents()
69 includes = include_re.findall(contents)
72 kscan = Scanner(name = 'kfile',
73 function = kfile_scan,
77 env = Environment(K2SCAN=kfile_scan)
79 k2scan = env.Scanner(name = 'k2',
80 # We'd like to do the following, but it will take
81 # some major surgery to subst() and subst_list(),
82 # so comment it out for now.
83 # function = '$K2SCAN',
84 function = kfile_scan,
88 ##########################################################
89 # Test scanner as found automatically from the environment
90 # (backup_source_scanner)
93 env.Append(SCANNERS = kscan)
95 env.Command('foo', 'foo.k', r'%(_python_)s build.py $SOURCES $TARGET')
97 ##########################################################
98 # Test resetting the environment scanners (and specifying as a list).
101 env2.Append(SCANNERS = [k2scan])
102 env2.Command('junk', 'junk.k2', r'%(_python_)s build.py $SOURCES $TARGET')
104 ##########################################################
105 # Test specifying a specific source scanner for a target Node
107 barbld = Builder(action=r'%(_python_)s build.py $SOURCES $TARGET',
108 source_scanner=kscan)
109 env.Append(BUILDERS={'BarBld':barbld})
110 bar = env.BarBld(target='bar', source='bar.in')
112 ##########################################################
113 # Test specifying a source scanner for a Builder that gets
114 # automatically applied to targets generated from that Builder
118 def blork(env, target, source):
119 open(str(target[0]), 'wb').write(
120 string.replace(source[0].get_text_contents(), 'getfile', 'MISSEDME'))
122 kbld = Builder(action=r'%(_python_)s build.py $SOURCES $TARGET',
125 source_scanner=kscan)
126 blorkbld = Builder(action=blork,
130 env.Append(BUILDERS={'BLORK':blorkbld, 'KB':kbld})
132 blork = env.KB('moo.lork')
133 ork = env.BLORK(blork)
134 Alias('make_ork', ork)
152 test.write('junk.k2',
159 test.write('moo.lork',
167 test.write('moo.inc',
171 test.write('xxx', "xxx 1\n")
172 test.write('yyy', "yyy 1\n")
173 test.write('zzz', "zzz 1\n")
175 expect = test.wrap_stdout("""\
176 %(_python_)s build.py bar.in bar
177 %(_python_)s build.py foo.k foo
178 %(_python_)s build.py junk.k2 junk
179 %(_python_)s build.py moo.lork moo.blork
180 blork(["moo.ork"], ["moo.blork"])
183 test.run(arguments = '.', stdout=expect)
185 test.must_match('foo', "foo.k 1 line 1\nxxx 1\nyyy 1\nfoo.k 1 line 4\n")
186 test.must_match('bar', "yyy 1\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
187 test.must_match('junk', "yyy 1\njunk.k2 1 line 2\njunk.k2 1 line 3\nzzz 1\n")
188 test.must_match('moo.ork', "xxx 1\nmoo.lork 1 line 2\nyyy 1\nmoo.lork 1 line 4\ninclude zzz\n")
190 test.up_to_date(arguments = '.')
192 test.write('xxx', "xxx 2\n")
194 expect = test.wrap_stdout("""\
195 %(_python_)s build.py foo.k foo
196 %(_python_)s build.py moo.lork moo.blork
197 blork(["moo.ork"], ["moo.blork"])
200 test.run(arguments = '.', stdout=expect)
202 test.must_match('foo', "foo.k 1 line 1\nxxx 2\nyyy 1\nfoo.k 1 line 4\n")
203 test.must_match('bar', "yyy 1\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
204 test.must_match('junk', "yyy 1\njunk.k2 1 line 2\njunk.k2 1 line 3\nzzz 1\n")
205 test.must_match('moo.ork', "xxx 2\nmoo.lork 1 line 2\nyyy 1\nmoo.lork 1 line 4\ninclude zzz\n")
207 test.write('yyy', "yyy 2\n")
209 expect = test.wrap_stdout("""\
210 %(_python_)s build.py bar.in bar
211 %(_python_)s build.py foo.k foo
212 %(_python_)s build.py junk.k2 junk
213 %(_python_)s build.py moo.lork moo.blork
214 blork(["moo.ork"], ["moo.blork"])
217 test.run(arguments = '.', stdout=expect)
219 test.must_match('foo', "foo.k 1 line 1\nxxx 2\nyyy 2\nfoo.k 1 line 4\n")
220 test.must_match('bar', "yyy 2\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 1\n")
221 test.must_match('junk', "yyy 2\njunk.k2 1 line 2\njunk.k2 1 line 3\nzzz 1\n")
222 test.must_match('moo.ork', "xxx 2\nmoo.lork 1 line 2\nyyy 2\nmoo.lork 1 line 4\ninclude zzz\n")
224 test.write('zzz', "zzz 2\n")
226 expect = test.wrap_stdout("""\
227 %(_python_)s build.py bar.in bar
228 %(_python_)s build.py junk.k2 junk
231 test.run(arguments = '.', stdout=expect)
233 test.must_match('foo', "foo.k 1 line 1\nxxx 2\nyyy 2\nfoo.k 1 line 4\n")
234 test.must_match('bar', "yyy 2\nbar.in 1 line 2\nbar.in 1 line 3\nzzz 2\n")
235 test.must_match('junk', "yyy 2\njunk.k2 1 line 2\njunk.k2 1 line 3\nzzz 2\n")
236 test.must_match('moo.ork', "xxx 2\nmoo.lork 1 line 2\nyyy 2\nmoo.lork 1 line 4\ninclude zzz\n")
238 test.up_to_date(arguments = 'foo')
244 # indent-tabs-mode:nil
246 # vim: set expandtab tabstop=4 shiftwidth=4: