added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / Climb / option-u.py
blobb7298d280104efb1771ce45f2dfe8991e25bb5d1
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 """
27 Test that the -u option only builds targets at or below
28 the current directory.
29 """
31 import os
33 import TestSCons
35 test = TestSCons.TestSCons()
37 test.subdir('sub1',
38 'sub2', ['sub2', 'dir'],
39 'sub3',
40 'sub4', ['sub4', 'dir'])
42 test.write('SConstruct', """
43 DefaultEnvironment(tools=[])
44 def cat(env, source, target):
45 target = str(target[0])
46 with open(target, 'wb') as ofp:
47 for src in source:
48 with open(str(src), 'rb') as ifp:
49 ofp.write(ifp.read())
50 env = Environment(tools=[])
51 env.Append(BUILDERS = {'Cat' : Builder(action=cat)})
52 env.Cat(target = 'sub1/f1a.out', source = 'sub1/f1a.in')
53 env.Cat(target = 'sub1/f1b.out', source = 'sub1/f1b.in')
54 Export('env')
55 SConscript('sub2/SConscript')
56 f3 = env.Cat(target = 'sub3/f3.out', source = 'sub3/f3.in')
57 env.Alias('my_alias', f3)
58 VariantDir('build', 'sub4')
59 SConscript('build/SConscript')
60 """)
62 test.write(['sub2', 'SConscript'], """
63 Import('env')
64 env.Cat(target = 'f2a.out', source = 'f2a.in')
65 env.Cat(target = 'dir/f2b.out', source = 'dir/f2b.in')
66 """)
68 test.write(['sub4', 'SConscript'], """
69 Import('env')
70 env.Cat(target = 'f4a.out', source = 'f4a.in')
71 f4b_in = File('dir/f4b.in')
72 f4b_in.exists()
73 f4b_in.is_derived()
74 env.Cat(target = 'dir/f4b.out', source = f4b_in)
75 """)
77 test.write(['sub1', 'f1a.in'], "sub1/f1a.in")
78 test.write(['sub1', 'f1b.in'], "sub1/f1b.in")
79 test.write(['sub2', 'f2a.in'], "sub2/f2a.in")
80 test.write(['sub2', 'dir', 'f2b.in'], "sub2/dir/f2b.in")
81 test.write(['sub3', 'f3.in'], "sub3/f3.in")
82 test.write(['sub4', 'f4a.in'], "sub4/f4a.in")
83 test.write(['sub4', 'dir', 'f4b.in'], "sub4/dir/f4b.in")
85 # Verify that we only build the specified local argument.
86 test.run(chdir = 'sub1', arguments = '-u f1a.out')
88 test.must_match(['sub1', 'f1a.out'], "sub1/f1a.in")
89 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
90 test.must_not_exist(test.workpath('sub2', 'f2a.out'))
91 test.must_not_exist(test.workpath('sub2', 'dir', 'f2b.out'))
92 test.must_not_exist(test.workpath('sub3', 'f3.out'))
93 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
94 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
95 test.must_not_exist(test.workpath('build', 'f4a.out'))
96 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
98 # Verify that we build everything at or below our current directory.
99 test.run(chdir = 'sub2', arguments = '-u')
101 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
102 test.must_match(['sub2', 'f2a.out'], "sub2/f2a.in")
103 test.must_match(['sub2', 'dir', 'f2b.out'], "sub2/dir/f2b.in")
104 test.must_not_exist(test.workpath('sub3', 'f3.out'))
105 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
106 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
107 test.must_not_exist(test.workpath('build', 'f4a.out'))
108 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
110 # Verify that we build a specified alias, regardless of where.
111 test.run(chdir = 'sub2', arguments = '-u my_alias')
113 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
114 test.must_match(['sub3', 'f3.out'], "sub3/f3.in")
115 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
116 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
117 test.must_not_exist(test.workpath('build', 'f4a.out'))
118 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
120 # Verify that we build things in a linked VariantDir.
121 f4a_in = os.path.join('build', 'f4a.in')
122 f4a_out = os.path.join('build', 'f4a.out')
123 f4b_in = os.path.join('build', 'dir', 'f4b.in')
124 f4b_out = os.path.join('build', 'dir', 'f4b.out')
125 test.run(chdir = 'sub4',
126 arguments = '-u',
127 stdout = "scons: Entering directory `%s'\n" % test.workpath() + \
128 test.wrap_stdout("""\
129 scons: building associated VariantDir targets: build
130 cat(["%s"], ["%s"])
131 cat(["%s"], ["%s"])
132 scons: `sub4' is up to date.
133 """ % (f4b_out, f4b_in, f4a_out, f4a_in)))
135 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
136 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
137 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
138 test.must_match(['build', 'f4a.out'], "sub4/f4a.in")
139 test.must_match(['build', 'dir', 'f4b.out'], "sub4/dir/f4b.in")
142 test.pass_test()
144 # Local Variables:
145 # tab-width:4
146 # indent-tabs-mode:nil
147 # End:
148 # vim: set expandtab tabstop=4 shiftwidth=4: