fa7e9144cd3b6b65444236caeb5c71dc80cb3a9c
[scons.git] / test / SConscript / SConscript.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 import TestSCons
28
29 test = TestSCons.TestSCons()
30
31 test.write('foo.py', "foo = 4\n")
32
33
34 test.write('SConstruct', """\
35 import os
36 import foo
37
38 assert foo.foo == 4
39
40 print "SConstruct", os.getcwd()
41 SConscript('SConscript')
42
43 x1 = "SConstruct x1"
44 x2 = "SConstruct x2"
45 x3,x4 = SConscript('SConscript1', "x1 x2")
46 assert x3 == "SConscript1 x3", x3
47 assert x4 == "SConscript1 x4", x4
48
49 (x3,x4) = SConscript('SConscript2', ["x1","x2"])
50 assert x3 == "SConscript2 x3", x3
51 assert x4 == "SConscript2 x4", x4
52
53 Export("x1 x2")
54 SConscript('SConscript3')
55 Import("x1 x2")
56 assert x1 == "SConscript3 x1", x1
57 assert x2 == "SConscript3 x2", x2
58
59 x1 = "SConstruct x1"
60 x2 = "SConstruct x2"
61 Export("x1","x2")
62 SConscript('SConscript4')
63 Import("x1"," x2")
64 assert x1 == "SConscript4 x1", x1
65 assert x2 == "SConscript4 x2", x2
66
67 subdir = Dir('subdir')
68 script = File('SConscript', subdir)
69 foo = SConscript(script)
70 assert foo == "subdir/SConscript foo"
71
72 SConscript('SConscript5')
73
74 import UserList
75 x7 = "SConstruct x7"
76 x8 = "SConstruct x8"
77 x9 = SConscript('SConscript6', UserList.UserList(["x7", "x8"]))
78 assert x9 == "SConscript6 x9", x9
79
80 SConscript('SConscript7')
81 """)
82
83
84 test.write('SConscript', """\
85 # os should not be automajically imported:
86 assert not globals().has_key("os")
87
88 import os
89 print "SConscript " + os.getcwd()
90 """)
91
92 test.write('SConscript1', """
93 Import("x1 x2")
94 assert x1 == "SConstruct x1", x1
95 assert x2 == "SConstruct x2", x2
96
97 x3 = "SConscript1 x3"
98 x4 = "SConscript1 x4"
99 Return("x3 x4")
100 """)
101
102
103 test.write('SConscript2', """\
104 Import("x1","x2")
105 assert x1 == "SConstruct x1", x1
106 assert x2 == "SConstruct x2", x2
107 x3 = "SConscript2 x3"
108 x4 = "SConscript2 x4"
109 Return("x3","x4")
110 """)
111
112
113 test.write('SConscript3', """\
114 Import("x1 x2")
115 assert x1 == "SConstruct x1", x1
116 assert x2 == "SConstruct x2", x2
117 x1 = "SConscript3 x1"
118 x2 = "SConscript3 x2"
119
120 x5 = SConscript('SConscript31', "x1")
121 Import("x6")
122 assert x5 == "SConscript31 x5", x5
123 assert x6 == "SConscript31 x6", x6
124
125 Export("x1 x2")
126 """)
127
128
129 test.write('SConscript31', """\
130 Import("x1 x2")
131 assert x1 == "SConscript3 x1", x1
132 assert x2 == "SConstruct x2", x2
133 x5 = "SConscript31 x5"
134 x6 = "SConscript31 x6"
135 Export("x6")
136 Return("x5")
137 """)
138
139
140 test.write('SConscript4', """\
141 Import("x1", "x2")
142 assert x1 == "SConstruct x1", x1
143 assert x2 == "SConstruct x2", x2
144 x1 = "SConscript4 x1"
145 x2 = "SConscript4 x2"
146 Export("x1", "x2")
147 """)
148
149
150 test.subdir('subdir')
151 test.write(['subdir', 'SConscript'], """\
152 foo = 'subdir/SConscript foo'
153 Return('foo')
154 """)
155
156
157 test.write('SConscript5', """\
158 B = Builder(action = 'B')
159 def scan():
160     pass
161 S = Scanner(function = scan)
162 A = Action("A")
163 """)
164
165
166 test.write('SConscript6', """\
167 Import("x7 x8")
168 assert x7 == "SConstruct x7", x7
169 assert x8 == "SConstruct x8", x8
170 x9 = "SConscript6 x9"
171 Return("x9")
172 """)
173
174
175 test.write('SConscript7', """\
176 result1 = ((1, 3), -4)
177 result2 = ((2, 3), -4)
178 assert result1 == SConscript(Split('foo/SConscript bar/SConscript'))
179 assert result1 == SConscript(['foo/SConscript', 'bar/SConscript'])
180 assert result1 == SConscript([File('foo/SConscript'), File('bar/SConscript')])
181 assert result1 == SConscript(dirs = Split('foo bar'))
182 assert result1 == SConscript(dirs = ['foo', 'bar'])
183 assert result2 == SConscript(dirs = Split('foo bar'), name = 'subscript')
184 assert result2 == SConscript(dirs = ['foo', 'bar'], name = 'subscript')
185 assert result1 == SConscript(dirs = ['foo', Dir('bar')])
186 assert result2 == SConscript(dirs = [Dir('foo'), 'bar'], name = 'subscript')
187 assert 5 == SConscript('w s/SConscript')
188 assert (-4, 5) == SConscript(['bar/SConscript', 'w s/SConscript'])
189
190 x1 = 3
191 x2 = 2
192 assert (3, 2) == SConscript(dirs = 'baz', exports = "x1 x2")
193 assert (3, 2) == SConscript('baz/SConscript', 'x1', exports = 'x2')
194 assert (3, 2) == SConscript('baz/SConscript', exports = 'x1 x2')
195 """)
196
197 fooscript = "x = %d; y = 3; Return('x y')\n"
198 barscript = "x = -4; Return('x')\n"
199
200 test.subdir('foo', 'bar', 'baz', 'w s')
201 test.write(['foo', 'SConscript'], fooscript % 1)
202 test.write(['foo', 'subscript'],  fooscript % 2)
203 test.write(['bar', 'SConscript'], barscript)
204 test.write(['bar', 'subscript'],  barscript)
205 test.write(['baz', 'SConscript'], """\
206 Import("x1 x2")
207 result = (x1, x2)
208 Return("result")
209 """)
210 test.write(['w s', 'SConscript'], "x = 5; Return('x')\n")
211
212
213 wpath = test.workpath()
214
215 test.run(arguments = ".",
216          stdout = test.wrap_stdout(read_str = 'SConstruct %s\nSConscript %s\n' % (wpath, wpath),
217                                    build_str = "scons: `.' is up to date.\n"))
218
219 test.pass_test()
220
221 # Local Variables:
222 # tab-width:4
223 # indent-tabs-mode:nil
224 # End:
225 # vim: set expandtab tabstop=4 shiftwidth=4: