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.
36 test = TestSCons.TestSCons()
40 test.write('SConstruct', """\
43 def cat(env, source, target):
44 target = str(target[0])
45 source = map(str, source)
46 f = open(target, "wb")
48 f.write(open(src, "rb").read())
51 def sc_cat(env, source, target):
54 head, tail = os.path.split(str(t))
55 source.append(os.path.join(head, 'sc-' + tail))
56 cat(env, source, target)
58 env = Environment(BUILDERS={'Cat':Builder(action=cat)}, SUBDIR='sub')
59 env.Cat('aaa.out', 'sub/aaa.in')
60 env.Cat('bbb.out', 'sub/bbb.in')
61 env.Cat('ccc.out', 'sub/ccc.in')
62 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
63 env.SourceCode('$SUBDIR', Builder(action=sc_cat, env=env))
64 SConscript('sub/SConscript', "env")
67 test.write(['sub', 'sc-aaa.in'], "sub/sc-aaa.in\n")
68 test.write(['sub', 'sc-bbb.in'], "sub/sc-bbb.in\n")
69 test.write(['sub', 'sc-ccc.in'], "sub/sc-ccc.in\n")
71 test.write(['sub', 'sc-SConscript'], "'sub/sc-SConscript'\n")
73 test.run(arguments = '.',
74 stdout = test.wrap_stdout(read_str = """\
76 """ % (os.path.join('sub', 'SConscript')),
84 cat("all", ["aaa.out", "bbb.out", "ccc.out"])
85 """ % (os.path.join('sub', 'aaa.in'),
86 os.path.join('sub', 'aaa.in'),
87 os.path.join('sub', 'bbb.in'),
88 os.path.join('sub', 'bbb.in'),
89 os.path.join('sub', 'ccc.in'),
90 os.path.join('sub', 'ccc.in'))))
92 test.fail_test(test.read(['sub', 'SConscript']) != "'sub/sc-SConscript'\n")
93 test.fail_test(test.read('all') != "sub/sc-aaa.in\nsub/sc-bbb.in\nsub/sc-ccc.in\n")