Issue 2168: Mac OS X fixes for SWIG tests. (Greg Noel)
[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 VariantDir('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 env.Cat(target = 'dir/f4b.out', source = f4b_in)
77 """)
78
79 test.write(['sub1', 'f1a.in'], "sub1/f1a.in")
80 test.write(['sub1', 'f1b.in'], "sub1/f1b.in")
81 test.write(['sub2', 'f2a.in'], "sub2/f2a.in")
82 test.write(['sub2', 'dir', 'f2b.in'], "sub2/dir/f2b.in")
83 test.write(['sub3', 'f3.in'], "sub3/f3.in")
84 test.write(['sub4', 'f4a.in'], "sub4/f4a.in")
85 test.write(['sub4', 'dir', 'f4b.in'], "sub4/dir/f4b.in")
86
87 # Verify that we only build the specified local argument.
88 test.run(chdir = 'sub1', arguments = '-u f1a.out')
89
90 test.must_match(['sub1', 'f1a.out'], "sub1/f1a.in")
91 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
92 test.must_not_exist(test.workpath('sub2', 'f2a.out'))
93 test.must_not_exist(test.workpath('sub2', 'dir', 'f2b.out'))
94 test.must_not_exist(test.workpath('sub3', 'f3.out'))
95 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
96 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
97 test.must_not_exist(test.workpath('build', 'f4a.out'))
98 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
99
100 # Verify that we build everything at or below our current directory.
101 test.run(chdir = 'sub2', arguments = '-u')
102
103 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
104 test.must_match(['sub2', 'f2a.out'], "sub2/f2a.in")
105 test.must_match(['sub2', 'dir', 'f2b.out'], "sub2/dir/f2b.in")
106 test.must_not_exist(test.workpath('sub3', 'f3.out'))
107 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
108 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
109 test.must_not_exist(test.workpath('build', 'f4a.out'))
110 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
111
112 # Verify that we build a specified alias, regardless of where.
113 test.run(chdir = 'sub2', arguments = '-u my_alias')
114
115 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
116 test.must_match(['sub3', 'f3.out'], "sub3/f3.in")
117 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
118 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
119 test.must_not_exist(test.workpath('build', 'f4a.out'))
120 test.must_not_exist(test.workpath('build', 'dir', 'f4b.out'))
121
122 # Verify that we build things in a linked VariantDir.
123 f4a_in = os.path.join('build', 'f4a.in')
124 f4a_out = os.path.join('build', 'f4a.out')
125 f4b_in = os.path.join('build', 'dir', 'f4b.in')
126 f4b_out = os.path.join('build', 'dir', 'f4b.out')
127 test.run(chdir = 'sub4',
128          arguments = '-u',
129          stdout = "scons: Entering directory `%s'\n" % test.workpath() + \
130                   test.wrap_stdout("""\
131 scons: building associated VariantDir targets: build
132 cat(["%s"], ["%s"])
133 cat(["%s"], ["%s"])
134 scons: `sub4' is up to date.
135 """ % (f4b_out, f4b_in, f4a_out, f4a_in)))
136
137 test.must_not_exist(test.workpath('sub1', 'sub1/f1b.out'))
138 test.must_not_exist(test.workpath('sub4', 'f4a.out'))
139 test.must_not_exist(test.workpath('sub4', 'dir', 'f4b.out'))
140 test.must_match(['build', 'f4a.out'], "sub4/f4a.in")
141 test.must_match(['build', 'dir', 'f4b.out'], "sub4/dir/f4b.in")
142
143 # Make sure explicit targets beginning with ../ get built.
144 test.subdir('sub6', ['sub6', 'dir'])
145
146 test.write(['sub6', 'SConstruct'], """\
147 def cat(env, source, target):
148     target = str(target[0])
149     source = map(str, source)
150     f = open(target, "wb")
151     for src in source:
152         f.write(open(src, "rb").read())
153     f.close()
154 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
155 env.Cat('f1.out', 'f1.in')
156 env.Cat('f2.out', 'f2.in')
157 SConscript('dir/SConscript', "env")
158 """)
159
160 test.write(['sub6', 'f1.in'], "f1.in\n")
161 test.write(['sub6', 'f2.in'], "f2.in\n")
162
163 test.write(['sub6', 'dir', 'SConscript'], """\
164 Import("env")
165 env.Cat('f3.out', 'f3.in')
166 env.Cat('f4.out', 'f4.in')
167 """)
168
169 test.write(['sub6', 'dir', 'f3.in'], "f3.in\n")
170 test.write(['sub6', 'dir', 'f4.in'], "f4.in\n")
171
172 test.run(chdir = 'sub6/dir', arguments = '-u ../f2.out')
173
174 test.must_not_exist(test.workpath('sub6', 'f1.out'))
175 test.must_exist(test.workpath('sub6', 'f2.out'))
176 test.must_not_exist(test.workpath('sub6', 'dir', 'f3.out'))
177 test.must_not_exist(test.workpath('sub6', 'dir', 'f4.out'))
178
179 test.pass_test()