f6546ed307b3e2851dc782880c108de97d444028
[scons.git] / test / option--U.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2001, 2002 Steven Knight
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 import os
28 import os.path
29 import sys
30
31 import TestSCons
32
33 test = TestSCons.TestSCons()
34
35 python = TestSCons.python
36
37 test.subdir('sub1', 'sub2', 'sub3')
38
39 test.write('build.py', r"""
40 import sys
41 contents = open(sys.argv[2], 'rb').read()
42 file = open(sys.argv[1], 'wb')
43 file.write(contents)
44 file.close()
45 """)
46
47 test.write('SConstruct', r"""
48 import SCons.Defaults
49 env = Environment()
50 env['BUILDERS']['B'] = Builder(action=r'%s build.py $TARGET $SOURCES', multi=1)
51 Default(env.B(target = 'sub1/foo.out', source = 'sub1/foo.in'))
52 Export('env')
53 SConscript('sub2/SConscript')
54 Default(env.B(target = 'sub3/baz.out', source = 'sub3/baz.in'))
55 BuildDir('sub2b', 'sub2')
56 SConscript('sub2b/SConscript')
57 Default(env.B(target = 'sub2/xxx.out', source = 'xxx.in'))
58 SConscript('SConscript')
59 """ % python)
60
61 test.write(['sub2', 'SConscript'], """
62 Import('env')
63 bar = env.B(target = 'bar.out', source = 'bar.in')
64 Default(bar)
65 env.Alias('bar', bar)
66 Default(env.B(target = '../bar.out', source = 'bar.in'))
67 """)
68
69
70 test.write(['sub1', 'foo.in'], "sub1/foo.in\n")
71 test.write(['sub2', 'bar.in'], "sub2/bar.in\n")
72 test.write(['sub3', 'baz.in'], "sub3/baz.in\n")
73 test.write('xxx.in', "xxx.in\n")
74
75 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub1'))
76 test.run(arguments = '-U foo.out', chdir = 'sub1')
77
78 test.fail_test(not os.path.exists(test.workpath('sub1', 'foo.out')))
79 test.fail_test(os.path.exists(test.workpath('sub2', 'bar.out')))
80 test.fail_test(os.path.exists(test.workpath('sub2b', 'bar.out')))
81 test.fail_test(os.path.exists(test.workpath('sub3', 'baz.out')))
82 test.fail_test(os.path.exists(test.workpath('bar.out')))
83 test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
84
85 test.unlink(['sub1', 'foo.out'])
86
87 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub1'))
88 test.run(arguments = '-U', chdir = 'sub1', stderr = None, status = 2)
89 test.fail_test(os.path.exists(test.workpath('sub1', 'foo.out')))
90 test.fail_test(os.path.exists(test.workpath('sub2', 'bar.out')))
91 test.fail_test(os.path.exists(test.workpath('sub2b', 'bar.out')))
92 test.fail_test(os.path.exists(test.workpath('sub3', 'baz.out')))
93 test.fail_test(os.path.exists(test.workpath('bar.out')))
94 test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
95
96
97 if sys.platform == 'win32':
98     test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('SUB2'))
99     test.run(chdir = 'SUB2', arguments = '-U')
100 else:
101     test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub2'))
102     test.run(chdir = 'sub2', arguments = '-U')
103 test.fail_test(os.path.exists(test.workpath('sub1', 'foo.out')))
104 test.fail_test(not os.path.exists(test.workpath('sub2', 'bar.out')))
105 test.fail_test(not os.path.exists(test.workpath('sub2b', 'bar.out')))
106 test.fail_test(os.path.exists(test.workpath('sub3', 'baz.out')))
107 test.fail_test(not os.path.exists(test.workpath('bar.out')))
108 test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
109
110 test.unlink(['sub2', 'bar.out'])
111 test.unlink(['sub2b', 'bar.out'])
112 test.unlink('bar.out')
113
114 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath())
115 test.run(arguments='-U')
116 test.fail_test(not os.path.exists(test.workpath('sub1', 'foo.out')))
117 test.fail_test(os.path.exists(test.workpath('sub2', 'bar.out')))
118 test.fail_test(os.path.exists(test.workpath('sub2b', 'bar.out')))
119 test.fail_test(not os.path.exists(test.workpath('sub3', 'baz.out')))
120 test.fail_test(os.path.exists(test.workpath('bar.out')))
121 test.fail_test(not os.path.exists(test.workpath('sub2/xxx.out')))
122
123 test.unlink(['sub1', 'foo.out'])
124 test.unlink(['sub3', 'baz.out'])
125 test.unlink(['sub2', 'xxx.out'])
126
127 test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub3'))
128 test.run(chdir = 'sub3', arguments='-U bar')
129 test.fail_test(os.path.exists(test.workpath('sub1', 'foo.out')))
130 test.fail_test(not os.path.exists(test.workpath('sub2', 'bar.out')))
131 test.fail_test(not os.path.exists(test.workpath('sub2b', 'bar.out')))
132 test.fail_test(os.path.exists(test.workpath('sub3', 'baz.out')))
133 test.fail_test(os.path.exists(test.workpath('bar.out')))
134 test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
135
136
137 # Make sure that a Default() directory doesn't cause an exception.
138 test.subdir('sub4')
139
140 test.write(['sub4', 'SConstruct'], """
141 Default('.')
142 """)
143
144 test.run(chdir = 'sub4', arguments = '-U')
145
146 test.write('SConstruct', """
147 Default('not_a_target.in')
148 """)
149
150 test.run(arguments = '-U', status=2, stderr="""\
151 scons: *** Do not know how to make target `not_a_target.in'.  Stop.
152 """)
153
154 test.pass_test()