Added fix for TeX includes with same name as subdirs.
[scons.git] / test / SourceCode.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Test fetching source files using the SourceCode() method.
29 """
30
31 import os
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 test.subdir('sub', 'sub2')
38
39 test.write('SConstruct', """\
40 import os
41
42 def cat(env, source, target):
43     target = str(target[0])
44     f = open(target, "wb")
45     for src in source:
46         f.write(open(str(src), "rb").read())
47     f.close()
48
49 def sc_cat(env, source, target):
50     source = []
51     for t in target:
52         head, tail = os.path.split(str(t))
53         source.append(os.path.join(head, 'sc-' + tail))
54     cat(env, source, target)
55
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')
60 bbb_in.is_derived()
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")
65
66 SourceCode('sub2', Builder(action=sc_cat, env=env))
67 env.Cat('ddd.out', 'sub2/ddd.in')
68 """)
69
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")
74
75 test.write(['sub', 'sc-SConscript'], "'sub/sc-SConscript'\n")
76
77 test.run(arguments = '.',
78          stdout = test.wrap_stdout(read_str = """\
79 sc_cat(["%s"], [])
80 """ % (os.path.join('sub', 'SConscript')),
81                                    build_str = """\
82 sc_cat(["%s"], [])
83 cat(["aaa.out"], ["%s"])
84 sc_cat(["%s"], [])
85 cat(["bbb.out"], ["%s"])
86 sc_cat(["%s"], [])
87 cat(["ccc.out"], ["%s"])
88 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
89 sc_cat(["%s"], [])
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'))))
99
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")
103
104 test.pass_test()
105
106 # Local Variables:
107 # tab-width:4
108 # indent-tabs-mode:nil
109 # End:
110 # vim: set expandtab tabstop=4 shiftwidth=4: