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