Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[scons.git] / test / option-u.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 that the -u option only builds targets at or below
29 the current directory.
30 """
31
32 import os.path
33 import sys
34
35 import TestSCons
36
37 test = TestSCons.TestSCons()
38
39 test.subdir('sub1',
40             'sub2', ['sub2', 'dir'],
41             'sub3',
42             'sub4', ['sub4', 'dir'])
43
44 test.write('SConstruct', """
45 def cat(env, source, target):
46     target = str(target[0])
47     source = map(str, source)
48     f = open(target, "wb")
49     for src in source:
50         f.write(open(src, "rb").read())
51     f.close()
52 env = Environment()
53 env.Append(BUILDERS = {'Cat' : Builder(action=cat)})
54 env.Cat(target = 'sub1/f1a.out', source = 'sub1/f1a.in')
55 env.Cat(target = 'sub1/f1b.out', source = 'sub1/f1b.in')
56 Export('env')
57 SConscript('sub2/SConscript')
58 f3 = env.Cat(target = 'sub3/f3.out', source = 'sub3/f3.in')
59 env.Alias('my_alias', f3)
60 BuildDir('build', 'sub4')
61 SConscript('build/SConscript')
62 """)
63
64 test.write(['sub2', 'SConscript'], """
65 Import('env')
66 env.Cat(target = 'f2a.out', source = 'f2a.in')
67 env.Cat(target = 'dir/f2b.out', source = 'dir/f2b.in')
68 """)
69
70 test.write(['sub4', 'SConscript'], """
71 Import('env')
72 env.Cat(target = 'f4a.out', source = 'f4a.in')
73 f4b_in = File('dir/f4b.in')
74 f4b_in.exists()
75 f4b_in.is_derived()
76 f4b_in.is_pseudo_derived()
77 env.Cat(target = 'dir/f4b.out', source = f4b_in)
78 """)
79
80 test.write(['sub1', 'f1a.in'], "sub1/f1a.in")
81 test.write(['sub1', 'f1b.in'], "sub1/f1b.in")
82 test.write(['sub2', 'f2a.in'], "sub2/f2a.in")
83 test.write(['sub2', 'dir', 'f2b.in'], "sub2/dir/f2b.in")
84 test.write(['sub3', 'f3.in'], "sub3/f3.in")
85 test.write(['sub4', 'f4a.in'], "sub4/f4a.in")
86 test.write(['sub4', 'dir', 'f4b.in'], "sub4/dir/f4b.in")
87
88 # Verify that we only build the specified local argument.
89 test.run(chdir = 'sub1', arguments = '-u f1a.out')
90
91 test.must_match(['sub1', 'f1a.out'], "sub1/f1a.in")
92 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
93 test.must_not_exist(test.workpath('sub2', 'f2a.out'))
94 test.must_not_exist(test.workpath('sub2', 'dir', 'f2b.out'))
95 test.must_not_exist(test.workpath('sub3', 'f3.out'))
96 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
97 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
98 test.must_not_exist(test.workpath('build', 'f4a.out'))
99 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
100
101 # Verify that we build everything at or below our current directory.
102 test.run(chdir = 'sub2', arguments = '-u')
103
104 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
105 test.must_match(['sub2', 'f2a.out'], "sub2/f2a.in")
106 test.must_match(['sub2', 'dir', 'f2b.out'], "sub2/dir/f2b.in")
107 test.must_not_exist(test.workpath('sub3', 'f3.out'))
108 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
109 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
110 test.must_not_exist(test.workpath('build', 'f4a.out'))
111 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
112
113 # Verify that we build a specified alias, regardless of where.
114 test.run(chdir = 'sub2', arguments = '-u my_alias')
115
116 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
117 test.must_match(['sub3', 'f3.out'], "sub3/f3.in")
118 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
119 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
120 test.must_not_exist(test.workpath('build', 'f4a.out'))
121 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
122
123 # Verify that we build things in a linked BuildDir.
124 f4a_in = os.path.join('build', 'f4a.in')
125 f4a_out = os.path.join('build', 'f4a.out')
126 f4b_in = os.path.join('build', 'dir', 'f4b.in')
127 f4b_out = os.path.join('build', 'dir', 'f4b.out')
128 test.run(chdir = 'sub4',
129          arguments = '-u',
130          stdout = "scons: Entering directory `%s'\n" % test.workpath() + \
131                   test.wrap_stdout("""\
132 scons: building associated BuildDir targets: build
133 cat(["%s"], ["%s"])
134 cat(["%s"], ["%s"])
135 scons: `sub4' is up to date.
136 """ % (f4b_out, f4b_in, f4a_out, f4a_in)))
137
138 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
139 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
140 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
141 test.must_match(['build', 'f4a.out'], "sub4/f4a.in")
142 test.must_match(['build', 'dir', 'f4b.out'], "sub4/dir/f4b.in")
143
144 # Make sure explicit targets beginning with ../ get built.
145 test.subdir('sub6', ['sub6', 'dir'])
146
147 test.write(['sub6', 'SConstruct'], """\
148 def cat(env, source, target):
149     target = str(target[0])
150     source = map(str, source)
151     f = open(target, "wb")
152     for src in source:
153         f.write(open(src, "rb").read())
154     f.close()
155 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
156 env.Cat('f1.out', 'f1.in')
157 env.Cat('f2.out', 'f2.in')
158 SConscript('dir/SConscript', "env")
159 """)
160
161 test.write(['sub6', 'f1.in'], "f1.in\n")
162 test.write(['sub6', 'f2.in'], "f2.in\n")
163
164 test.write(['sub6', 'dir', 'SConscript'], """\
165 Import("env")
166 env.Cat('f3.out', 'f3.in')
167 env.Cat('f4.out', 'f4.in')
168 """)
169
170 test.write(['sub6', 'dir', 'f3.in'], "f3.in\n")
171 test.write(['sub6', 'dir', 'f4.in'], "f4.in\n")
172
173 test.run(chdir = 'sub6/dir', arguments = '-u ../f2.out')
174
175 test.must_not_exist(test.workpath('sub6', 'f1.out'))
176 test.must_exist(test.workpath('sub6', 'f2.out'))
177 test.must_not_exist(test.workpath('sub6', 'dir', 'f3.out'))
178 test.must_not_exist(test.workpath('sub6', 'dir', 'f4.out'))
179
180 test.pass_test()