[ci skip] Add note that this change may break SetOption() + ninja usage with fix
[scons.git] / test / Fortran / FORTRANPATH.py
blobf0f8b3ed08863fb9c5ea8653218267e36bec35fc
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 import os
28 import TestSCons
30 _exe = TestSCons._exe
31 prog = 'prog' + _exe
32 subdir_prog = os.path.join('subdir', 'prog' + _exe)
33 variant_prog = os.path.join('variant', 'prog' + _exe)
35 args = prog + ' ' + subdir_prog + ' ' + variant_prog
37 test = TestSCons.TestSCons()
39 fc = 'f77'
40 if not test.detect_tool(fc):
41 # gfortran names all variants the same, try it too
42 fc = 'gfortran'
43 if not test.detect_tool(fc):
44 test.skip_test('Could not find a f77 tool; skipping test.\n')
46 test.subdir('include', 'subdir', ['subdir', 'include'], 'foobar', 'inc2')
48 test.write('SConstruct', """\
49 DefaultEnvironment(tools=[]) # test speedup
50 env = Environment(
51 FORTRAN='%s',
52 FORTRANPATH=['$FOO', '${TARGET.dir}', '${SOURCE.dir}'],
53 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")
59 VariantDir('variant', 'subdir', 0)
60 include = Dir('include')
61 env = Environment(FORTRAN='%s', FORTRANPATH=[include, '#foobar', '#subdir'])
62 SConscript('variant/SConscript', "env")
63 """ % (fc, fc))
65 test.write(['subdir', 'SConscript'],
66 """
67 Import("env")
68 env.Program(target='prog', source='prog.f')
69 """)
71 test.write(['include', 'foo.f'],
72 r"""
73 PRINT *, 'include/foo.f 1'
74 INCLUDE 'bar.f'
75 """)
77 test.write(['include', 'bar.f'],
78 r"""
79 PRINT *, 'include/bar.f 1'
80 """)
82 test.write(['subdir', 'prog.f'],
83 r"""
84 PROGRAM PROG
85 PRINT *, 'subdir/prog.f'
86 include 'foo.f'
87 include 'sss.f'
88 include 'ttt.f'
89 STOP
90 END
91 """)
93 test.write(['subdir', 'include', 'foo.f'],
94 r"""
95 PRINT *, 'subdir/include/foo.f 1'
96 INCLUDE 'bar.f'
97 """)
99 test.write(['subdir', 'include', 'bar.f'],
100 r"""
101 PRINT *, 'subdir/include/bar.f 1'
102 """)
104 test.write(['subdir', 'sss.f'],
105 r"""
106 PRINT *, 'subdir/sss.f'
107 """)
109 test.write(['subdir', 'ttt.f'],
110 r"""
111 PRINT *, 'subdir/ttt.f'
112 """)
115 import sys
116 if sys.platform[:5] == 'sunos':
117 # Sun f77 always put some junk in stderr
118 test.run(arguments = args, stderr = None)
119 else:
120 test.run(arguments = args)
122 test.run(program = test.workpath(prog),
123 stdout = """\
124 subdir/prog.f
125 include/foo.f 1
126 include/bar.f 1
127 subdir/sss.f
128 subdir/ttt.f
129 """)
131 test.run(program = test.workpath(subdir_prog),
132 stdout = """\
133 subdir/prog.f
134 subdir/include/foo.f 1
135 subdir/include/bar.f 1
136 subdir/sss.f
137 subdir/ttt.f
138 """)
140 test.run(program = test.workpath(variant_prog),
141 stdout = """\
142 subdir/prog.f
143 include/foo.f 1
144 include/bar.f 1
145 subdir/sss.f
146 subdir/ttt.f
147 """)
149 # Make sure we didn't duplicate the source file in the variant subdirectory.
150 test.must_not_exist(test.workpath('variant', 'prog.f'))
152 test.up_to_date(arguments = args)
154 test.write(['include', 'foo.f'],
155 r"""
156 PRINT *, 'include/foo.f 2'
157 INCLUDE 'bar.f'
158 """)
160 if sys.platform[:5] == 'sunos':
161 # Sun f77 always put some junk in stderr
162 test.run(arguments = args, stderr = None)
163 else:
164 test.run(arguments = args)
166 test.run(program = test.workpath(prog),
167 stdout = """\
168 subdir/prog.f
169 include/foo.f 2
170 include/bar.f 1
171 subdir/sss.f
172 subdir/ttt.f
173 """)
175 test.run(program = test.workpath(subdir_prog),
176 stdout = """\
177 subdir/prog.f
178 subdir/include/foo.f 1
179 subdir/include/bar.f 1
180 subdir/sss.f
181 subdir/ttt.f
182 """)
184 test.run(program = test.workpath(variant_prog),
185 stdout = """\
186 subdir/prog.f
187 include/foo.f 2
188 include/bar.f 1
189 subdir/sss.f
190 subdir/ttt.f
191 """)
193 # Make sure we didn't duplicate the source file in the variant subdirectory.
194 test.must_not_exist(test.workpath('variant', 'prog.f'))
196 test.up_to_date(arguments = args)
198 test.write(['include', 'bar.f'],
199 r"""
200 PRINT *, 'include/bar.f 2'
201 """)
203 if sys.platform[:5] == 'sunos':
204 # Sun f77 always put some junk in stderr
205 test.run(arguments = args, stderr = None)
206 else:
207 test.run(arguments = args)
210 test.run(program = test.workpath(prog),
211 stdout = """\
212 subdir/prog.f
213 include/foo.f 2
214 include/bar.f 2
215 subdir/sss.f
216 subdir/ttt.f
217 """)
219 test.run(program = test.workpath(subdir_prog),
220 stdout = """\
221 subdir/prog.f
222 subdir/include/foo.f 1
223 subdir/include/bar.f 1
224 subdir/sss.f
225 subdir/ttt.f
226 """)
228 test.run(program = test.workpath(variant_prog),
229 stdout = """\
230 subdir/prog.f
231 include/foo.f 2
232 include/bar.f 2
233 subdir/sss.f
234 subdir/ttt.f
235 """)
237 # Make sure we didn't duplicate the source file in the variant subdirectory.
238 test.must_not_exist(test.workpath('variant', 'prog.f'))
240 test.up_to_date(arguments = args)
244 # Change FORTRANPATH and make sure we don't rebuild because of it.
245 test.write('SConstruct', """\
246 DefaultEnvironment(tools=[]) # test speedup
247 env = Environment(
248 FORTRAN='%s',
249 FORTRANPATH=Split('inc2 include ${TARGET.dir} ${SOURCE.dir}'),
251 obj = env.Object(target='foobar/prog', source='subdir/prog.f')
252 env.Program(target='prog', source=obj)
253 SConscript('subdir/SConscript', "env")
255 VariantDir('variant', 'subdir', 0)
256 include = Dir('include')
257 env = Environment(
258 FORTRAN='%s',
259 FORTRANPATH=['inc2', include, '#foobar', '#subdir'],
261 SConscript('variant/SConscript', "env")
262 """ % (fc, fc))
264 test.up_to_date(arguments = args)
266 test.write(['inc2', 'foo.f'],
267 r"""
268 PRINT *, 'inc2/foo.f 1'
269 INCLUDE 'bar.f'
270 """)
272 if sys.platform[:5] == 'sunos':
273 # Sun f77 always put some junk in stderr
274 test.run(arguments = args, stderr = None)
275 else:
276 test.run(arguments = args)
279 test.run(program = test.workpath(prog),
280 stdout = """\
281 subdir/prog.f
282 inc2/foo.f 1
283 include/bar.f 2
284 subdir/sss.f
285 subdir/ttt.f
286 """)
288 test.run(program = test.workpath(subdir_prog),
289 stdout = """\
290 subdir/prog.f
291 subdir/include/foo.f 1
292 subdir/include/bar.f 1
293 subdir/sss.f
294 subdir/ttt.f
295 """)
297 test.run(program = test.workpath(variant_prog),
298 stdout = """\
299 subdir/prog.f
300 include/foo.f 2
301 include/bar.f 2
302 subdir/sss.f
303 subdir/ttt.f
304 """)
306 test.up_to_date(arguments = args)
308 # Check that a null-string FORTRANPATH doesn't blow up.
309 test.write('SConstruct', """
310 DefaultEnvironment(tools=[]) # test speedup
311 env = Environment(FORTRANPATH = '')
312 env.Object('foo', source = 'empty.f')
313 """)
315 test.write('empty.f', '')
317 if sys.platform[:5] == 'sunos':
318 # Sun f77 always put some junk in stderr
319 test.run(arguments = '.', stderr = None)
320 else:
321 test.run(arguments = '.')
323 test.pass_test()
325 # Local Variables:
326 # tab-width:4
327 # indent-tabs-mode:nil
328 # End:
329 # vim: set expandtab tabstop=4 shiftwidth=4: