Add Variables.defualted attribute
[scons.git] / test / Alias / Alias.py
blob5915b2df7ecfd67fd7dd97239d3825c280b79c14
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 import os
28 import TestSCons
29 import TestCmd
31 _python_ = TestSCons._python_
33 test = TestSCons.TestSCons(match=TestCmd.match_re)
35 test.subdir('sub1', 'sub2')
37 test.write('build.py', r"""
38 import sys
39 with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp:
40 f.write(ifp.read())
41 sys.exit(0)
42 """)
44 test.write('SConstruct', """
45 B = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES')
46 DefaultEnvironment(tools=[]) # test speedup
47 env = Environment(tools=[])
48 env['BUILDERS']['B'] = B
49 env.B(target = 'f1.out', source = 'f1.in')
50 env.B(target = 'f2.out', source = 'f2.in')
51 env.B(target = 'f3.out', source = 'f3.in')
52 SConscript('sub1/SConscript', "env")
53 SConscript('sub2/SConscript', "env")
55 foo = Alias('foo')
56 foo2 = env.Alias('foo', ['f2.out', 'sub1'])
57 assert foo == foo2
58 bar = Alias('bar', ['sub2', 'f3.out'])
59 env.Alias('blat', ['sub2', 'f3.out'])
60 env.Alias('blat', ['f2.out', 'sub1'])
61 env.Depends('f1.out', 'bar')
63 assert Alias('foo') == foo
64 assert Alias('bar') == bar
66 """ % locals())
68 test.write(['sub1', 'SConscript'], """
69 Import("env")
70 env.B(target = 'f4.out', source = 'f4.in')
71 env.B(target = 'f5.out', source = 'f5.in')
72 env.B(target = 'f6.out', source = 'f6.in')
73 """)
75 test.write(['sub2', 'SConscript'], """
76 Import("env")
77 env.B(target = 'f7.out', source = 'f7.in')
78 env.B(target = 'f8.out', source = 'f8.in')
79 env.B(target = 'f9.out', source = 'f9.in')
80 """)
82 test.write('f1.in', "f1.in\n")
83 test.write('f2.in', "f2.in\n")
84 test.write('f3.in', "f3.in\n")
86 test.write(['sub1', 'f4.in'], "sub1/f4.in\n")
87 test.write(['sub1', 'f5.in'], "sub1/f5.in\n")
88 test.write(['sub1', 'f6.in'], "sub1/f6.in\n")
90 test.write(['sub2', 'f7.in'], "sub2/f7.in\n")
91 test.write(['sub2', 'f8.in'], "sub2/f8.in\n")
92 test.write(['sub2', 'f9.in'], "sub2/f9.in\n")
94 test.run(arguments = 'foo')
96 test.fail_test(os.path.exists(test.workpath('f1.out')))
97 test.fail_test(not os.path.exists(test.workpath('f2.out')))
98 test.fail_test(os.path.exists(test.workpath('f3.out')))
100 test.fail_test(not os.path.exists(test.workpath('sub1', 'f4.out')))
101 test.fail_test(not os.path.exists(test.workpath('sub1', 'f5.out')))
102 test.fail_test(not os.path.exists(test.workpath('sub1', 'f6.out')))
104 test.fail_test(os.path.exists(test.workpath('sub2', 'f7.out')))
105 test.fail_test(os.path.exists(test.workpath('sub2', 'f8.out')))
106 test.fail_test(os.path.exists(test.workpath('sub2', 'f9.out')))
108 test.up_to_date(arguments = 'foo')
110 test.run(arguments = 'f1.out')
112 test.fail_test(not os.path.exists(test.workpath('f1.out')))
113 test.fail_test(not os.path.exists(test.workpath('f3.out')))
115 test.fail_test(not os.path.exists(test.workpath('sub2', 'f7.out')))
116 test.fail_test(not os.path.exists(test.workpath('sub2', 'f8.out')))
117 test.fail_test(not os.path.exists(test.workpath('sub2', 'f9.out')))
119 test.up_to_date(arguments = 'f1.out')
121 os.unlink(test.workpath('f2.out'))
122 os.unlink(test.workpath('f3.out'))
124 test.run(arguments = 'blat')
126 test.fail_test(not os.path.exists(test.workpath('f2.out')))
127 test.fail_test(not os.path.exists(test.workpath('f3.out')))
129 test.write('f3.in', "f3.in 2 \n")
131 test.run(arguments = 'f1.out',
132 stdout = test.wrap_stdout(".* build.py f3.out f3.in\n.* build.py f1.out f1.in\n"))
134 test.up_to_date(arguments = 'f1.out')
136 test.write('SConstruct', """
137 Decider('content')
138 B = Builder(action = r'%(_python_)s build.py $TARGET $SOURCES')
139 DefaultEnvironment(tools=[]) # test speedup
140 env = Environment(tools=[])
141 env['BUILDERS']['B'] = B
142 env.B(target = 'f1.out', source = 'f1.in')
143 env.B(target = 'f2.out', source = 'f2.in')
144 env.B(target = 'f3.out', source = 'f3.in')
145 SConscript('sub1/SConscript', "env")
146 SConscript('sub2/SConscript', "env")
147 env.Alias('foo', ['f2.out', 'sub1'])
148 env.Alias('bar', ['sub2', 'f3.out'])
149 env.Alias('blat', ['sub2', 'f3.out'])
150 env.Alias('blat', ['f2.out', 'sub1'])
151 env.Depends('f1.out', 'bar')
152 """ % locals())
154 os.unlink(test.workpath('f1.out'))
156 test.run(arguments = 'f1.out')
158 test.fail_test(not os.path.exists(test.workpath('f1.out')))
160 test.write('f3.in', "f3.in 3 \n")
162 expect = test.wrap_stdout("""\
163 %(_python_)s build.py f3.out f3.in
164 %(_python_)s build.py f1.out f1.in
165 """ % locals())
167 test.run(arguments = 'f1.out', match = TestCmd.match_exact, stdout = expect)
169 test.up_to_date(arguments = 'f1.out')
171 test.pass_test()
173 # Local Variables:
174 # tab-width:4
175 # indent-tabs-mode:nil
176 # End:
177 # vim: set expandtab tabstop=4 shiftwidth=4: