Remove unnecessary imports.
[scons.git] / test / Fortran / F90PATH.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 os
28 import string
29
30 import TestSCons
31
32 _exe = TestSCons._exe
33 prog = 'prog' + _exe
34 subdir_prog = os.path.join('subdir', 'prog' + _exe)
35 variant_prog = os.path.join('variant', 'prog' + _exe)
36
37 args = prog + ' ' + subdir_prog + ' ' + variant_prog
38
39 test = TestSCons.TestSCons()
40
41 fc = 'f90'
42 if not test.detect_tool(fc):
43     test.skip_test('Could not find a f90 tool; skipping test.\n')
44     
45 test.subdir('include',
46             'subdir',
47             ['subdir', 'include'],
48             'foobar',
49             'inc2')
50
51
52
53 test.write('SConstruct', """
54 env = Environment(F90 = r'%s',
55                   F90PATH = ['$FOO', '${TARGET.dir}', '${SOURCE.dir}'],
56                   LINK = '$F90',
57                   FOO='include')
58 obj = env.Object(target='foobar/prog', source='subdir/prog.f90')
59 env.Program(target='prog', source=obj)
60 SConscript('subdir/SConscript', "env")
61
62 VariantDir('variant', 'subdir', 0)
63 include = Dir('include')
64 env = Environment(F90 = r'%s',
65                   F90PATH=[include, '#foobar', '#subdir'],
66                   LINK = '$F90')
67 SConscript('variant/SConscript', "env")
68 """ % (fc, fc, ))
69
70 test.write(['subdir', 'SConscript'],
71 """
72 Import("env")
73 env.Program(target='prog', source='prog.f90')
74 """)
75
76 test.write(['include', 'foo.f90'],
77 r"""
78       PRINT *, 'include/foo.f90 1'
79       INCLUDE 'bar.f90'
80 """)
81
82 test.write(['include', 'bar.f90'],
83 r"""
84       PRINT *, 'include/bar.f90 1'
85 """)
86
87 test.write(['subdir', 'prog.f90'],
88 r"""
89       PROGRAM PROG
90       PRINT *, 'subdir/prog.f90'
91       include 'foo.f90'
92       include 'sss.f90'
93       include 'ttt.f90'
94       STOP
95       END
96 """)
97
98 test.write(['subdir', 'include', 'foo.f90'],
99 r"""
100       PRINT *, 'subdir/include/foo.f90 1'
101       INCLUDE 'bar.f90'
102 """)
103
104 test.write(['subdir', 'include', 'bar.f90'],
105 r"""
106       PRINT *, 'subdir/include/bar.f90 1'
107 """)
108
109 test.write(['subdir', 'sss.f90'],
110 r"""
111       PRINT *, 'subdir/sss.f90'
112 """)
113
114 test.write(['subdir', 'ttt.f90'],
115 r"""
116       PRINT *, 'subdir/ttt.f90'
117 """)
118
119
120
121 test.run(arguments = args)
122
123 test.run(program = test.workpath(prog),
124          stdout = """\
125  subdir/prog.f90
126  include/foo.f90 1
127  include/bar.f90 1
128  subdir/sss.f90
129  subdir/ttt.f90
130 """)
131
132 test.run(program = test.workpath(subdir_prog),
133          stdout = """\
134  subdir/prog.f90
135  subdir/include/foo.f90 1
136  subdir/include/bar.f90 1
137  subdir/sss.f90
138  subdir/ttt.f90
139 """)
140
141 test.run(program = test.workpath(variant_prog),
142          stdout = """\
143  subdir/prog.f90
144  include/foo.f90 1
145  include/bar.f90 1
146  subdir/sss.f90
147  subdir/ttt.f90
148 """)
149
150 # Make sure we didn't duplicate the source file in the variant subdirectory.
151 test.must_not_exist(test.workpath('variant', 'prog.f90'))
152
153 test.up_to_date(arguments = args)
154
155
156
157 test.write(['include', 'foo.f90'],
158 r"""
159       PRINT *, 'include/foo.f90 2'
160       INCLUDE 'bar.f90'
161 """)
162
163 test.run(arguments = args)
164
165 test.run(program = test.workpath(prog),
166          stdout = """\
167  subdir/prog.f90
168  include/foo.f90 2
169  include/bar.f90 1
170  subdir/sss.f90
171  subdir/ttt.f90
172 """)
173
174 test.run(program = test.workpath(subdir_prog),
175          stdout = """\
176  subdir/prog.f90
177  subdir/include/foo.f90 1
178  subdir/include/bar.f90 1
179  subdir/sss.f90
180  subdir/ttt.f90
181 """)
182
183 test.run(program = test.workpath(variant_prog),
184          stdout = """\
185  subdir/prog.f90
186  include/foo.f90 2
187  include/bar.f90 1
188  subdir/sss.f90
189  subdir/ttt.f90
190 """)
191
192 # Make sure we didn't duplicate the source file in the variant subdirectory.
193 test.must_not_exist(test.workpath('variant', 'prog.f90'))
194
195 test.up_to_date(arguments = args)
196
197
198
199 #
200 test.write(['include', 'bar.f90'],
201 r"""
202       PRINT *, 'include/bar.f90 2'
203 """)
204
205 test.run(arguments = args)
206
207 test.run(program = test.workpath(prog),
208          stdout = """\
209  subdir/prog.f90
210  include/foo.f90 2
211  include/bar.f90 2
212  subdir/sss.f90
213  subdir/ttt.f90
214 """)
215
216 test.run(program = test.workpath(subdir_prog),
217          stdout = """\
218  subdir/prog.f90
219  subdir/include/foo.f90 1
220  subdir/include/bar.f90 1
221  subdir/sss.f90
222  subdir/ttt.f90
223 """)
224
225 test.run(program = test.workpath(variant_prog),
226          stdout = """\
227  subdir/prog.f90
228  include/foo.f90 2
229  include/bar.f90 2
230  subdir/sss.f90
231  subdir/ttt.f90
232 """)
233
234 # Make sure we didn't duplicate the source file in the variant subdirectory.
235 test.must_not_exist(test.workpath('variant', 'prog.f90'))
236
237 test.up_to_date(arguments = args)
238
239
240
241 # Change F90PATH and make sure we don't rebuild because of it.
242 test.write('SConstruct', """
243 env = Environment(F90 = r'%s',
244                   F90PATH = Split('inc2 include ${TARGET.dir} ${SOURCE.dir}'),
245                   LINK = '$F90')
246 obj = env.Object(target='foobar/prog', source='subdir/prog.f90')
247 env.Program(target='prog', source=obj)
248 SConscript('subdir/SConscript', "env")
249
250 VariantDir('variant', 'subdir', 0)
251 include = Dir('include')
252 env = Environment(F90 = r'%s',
253                   F90PATH=['inc2', include, '#foobar', '#subdir'],
254                   LINK = '$F90')
255 SConscript('variant/SConscript', "env")
256 """ % (fc, fc))
257
258 test.up_to_date(arguments = args)
259
260
261
262 #
263 test.write(['inc2', 'foo.f90'],
264 r"""
265       PRINT *, 'inc2/foo.f90 1'
266       INCLUDE 'bar.f90'
267 """)
268
269 test.run(arguments = args)
270
271 test.run(program = test.workpath(prog),
272          stdout = """\
273  subdir/prog.f90
274  inc2/foo.f90 1
275  include/bar.f90 2
276  subdir/sss.f90
277  subdir/ttt.f90
278 """)
279
280 test.run(program = test.workpath(subdir_prog),
281          stdout = """\
282  subdir/prog.f90
283  subdir/include/foo.f90 1
284  subdir/include/bar.f90 1
285  subdir/sss.f90
286  subdir/ttt.f90
287 """)
288
289 test.run(program = test.workpath(variant_prog),
290          stdout = """\
291  subdir/prog.f90
292  include/foo.f90 2
293  include/bar.f90 2
294  subdir/sss.f90
295  subdir/ttt.f90
296 """)
297
298 test.up_to_date(arguments = args)
299
300
301
302 test.pass_test()