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 Test fetching source files using the SourceCode() method.
35 test = TestSCons.TestSCons()
37 test.subdir('sub', 'sub2')
39 test.write('SConstruct', """\
42 def cat(env, source, target):
43 target = str(target[0])
44 f = open(target, "wb")
46 f.write(open(str(src), "rb").read())
49 def sc_cat(env, source, target):
52 head, tail = os.path.split(str(t))
53 source.append(os.path.join(head, 'sc-' + tail))
54 cat(env, source, target)
56 env = Environment(BUILDERS={'Cat':Builder(action=cat)}, SUBDIR='sub')
57 env.SourceCode('$SUBDIR', Builder(action=sc_cat, env=env))
58 env.Cat('aaa.out', 'sub/aaa.in')
59 bbb_in = File('sub/bbb.in')
61 env.Cat('bbb.out', bbb_in)
62 env.Cat('ccc.out', 'sub/ccc.in')
63 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
64 SConscript('sub/SConscript', "env")
66 SourceCode('sub2', Builder(action=sc_cat, env=env))
67 env.Cat('ddd.out', 'sub2/ddd.in')
70 test.write(['sub', 'sc-aaa.in'], "sub/sc-aaa.in\n")
71 test.write(['sub', 'sc-bbb.in'], "sub/sc-bbb.in\n")
72 test.write(['sub', 'sc-ccc.in'], "sub/sc-ccc.in\n")
73 test.write(['sub2', 'sc-ddd.in'], "sub2/sc-ddd.in\n")
75 test.write(['sub', 'sc-SConscript'], "'sub/sc-SConscript'\n")
77 test.run(arguments = '.',
78 stdout = test.wrap_stdout(read_str = """\
80 """ % (os.path.join('sub', 'SConscript')),
83 cat(["aaa.out"], ["%s"])
85 cat(["bbb.out"], ["%s"])
87 cat(["ccc.out"], ["%s"])
88 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
90 cat(["ddd.out"], ["%s"])
91 """ % (os.path.join('sub', 'aaa.in'),
92 os.path.join('sub', 'aaa.in'),
93 os.path.join('sub', 'bbb.in'),
94 os.path.join('sub', 'bbb.in'),
95 os.path.join('sub', 'ccc.in'),
96 os.path.join('sub', 'ccc.in'),
97 os.path.join('sub2', 'ddd.in'),
98 os.path.join('sub2', 'ddd.in'))))
100 test.must_match(['sub', 'SConscript'], "'sub/sc-SConscript'\n")
101 test.must_match('all', "sub/sc-aaa.in\nsub/sc-bbb.in\nsub/sc-ccc.in\n")
102 test.must_match('ddd.out', "sub2/sc-ddd.in\n")
108 # indent-tabs-mode:nil
110 # vim: set expandtab tabstop=4 shiftwidth=4: