[ci skip] Add note that this change may break SetOption() + ninja usage with fix
[scons.git] / test / Fortran / F77PATH.py
blobcce5f134195cf9d498ffda2a450ae323043909e9
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 + ' ' + variant_prog + ' ' + subdir_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 F77='%s',
52 F77PATH=['$FOO', '${TARGET.dir}', '${SOURCE.dir}'],
53 FOO='include',
54 F77FLAGS='-x f77',
56 obj = env.Object(target='foobar/prog', source='subdir/prog.f77')
57 env.Program(target='prog', source=obj)
58 SConscript('subdir/SConscript', "env")
60 VariantDir('variant', 'subdir', 0)
61 include = Dir('include')
62 env = Environment(F77='%s', F77PATH=[include, '#foobar', '#subdir'], F77FLAGS='-x f77')
63 SConscript('variant/SConscript', "env")
64 """ % (fc, fc))
66 test.write(['subdir', 'SConscript'],
67 """
68 Import("env")
69 env.Program(target='prog', source='prog.f77')
70 """)
72 test.write(['include', 'foo.f77'],
73 r"""
74 PRINT *, 'include/foo.f77 1'
75 INCLUDE 'bar.f77'
76 """)
78 test.write(['include', 'bar.f77'],
79 r"""
80 PRINT *, 'include/bar.f77 1'
81 """)
83 test.write(['subdir', 'prog.f77'],
84 r"""
85 PROGRAM PROG
86 PRINT *, 'subdir/prog.f77'
87 include 'foo.f77'
88 include 'sss.f77'
89 include 'ttt.f77'
90 STOP
91 END
92 """)
94 test.write(['subdir', 'include', 'foo.f77'],
95 r"""
96 PRINT *, 'subdir/include/foo.f77 1'
97 INCLUDE 'bar.f77'
98 """)
100 test.write(['subdir', 'include', 'bar.f77'],
101 r"""
102 PRINT *, 'subdir/include/bar.f77 1'
103 """)
105 test.write(['subdir', 'sss.f77'],
106 r"""
107 PRINT *, 'subdir/sss.f77'
108 """)
110 test.write(['subdir', 'ttt.f77'],
111 r"""
112 PRINT *, 'subdir/ttt.f77'
113 """)
115 test.run(arguments = args)
117 test.run(program = test.workpath(prog),
118 stdout = """\
119 subdir/prog.f77
120 include/foo.f77 1
121 include/bar.f77 1
122 subdir/sss.f77
123 subdir/ttt.f77
124 """)
126 test.run(program = test.workpath(subdir_prog),
127 stdout = """\
128 subdir/prog.f77
129 subdir/include/foo.f77 1
130 subdir/include/bar.f77 1
131 subdir/sss.f77
132 subdir/ttt.f77
133 """)
135 test.run(program = test.workpath(variant_prog),
136 stdout = """\
137 subdir/prog.f77
138 include/foo.f77 1
139 include/bar.f77 1
140 subdir/sss.f77
141 subdir/ttt.f77
142 """)
144 # Make sure we didn't duplicate the source file in the variant subdirectory.
145 test.must_not_exist(test.workpath('variant', 'prog.f77'))
147 test.up_to_date(arguments = args)
149 test.write(['include', 'foo.f77'],
150 r"""
151 PRINT *, 'include/foo.f77 2'
152 INCLUDE 'bar.f77'
153 """)
155 test.run(arguments = args)
157 test.run(program = test.workpath(prog),
158 stdout = """\
159 subdir/prog.f77
160 include/foo.f77 2
161 include/bar.f77 1
162 subdir/sss.f77
163 subdir/ttt.f77
164 """)
166 test.run(program = test.workpath(subdir_prog),
167 stdout = """\
168 subdir/prog.f77
169 subdir/include/foo.f77 1
170 subdir/include/bar.f77 1
171 subdir/sss.f77
172 subdir/ttt.f77
173 """)
175 test.run(program = test.workpath(variant_prog),
176 stdout = """\
177 subdir/prog.f77
178 include/foo.f77 2
179 include/bar.f77 1
180 subdir/sss.f77
181 subdir/ttt.f77
182 """)
184 # Make sure we didn't duplicate the source file in the variant subdirectory.
185 test.must_not_exist(test.workpath('variant', 'prog.f77'))
187 test.up_to_date(arguments = args)
189 test.write(['include', 'bar.f77'],
190 r"""
191 PRINT *, 'include/bar.f77 2'
192 """)
194 test.run(arguments = args)
196 test.run(program = test.workpath(prog),
197 stdout = """\
198 subdir/prog.f77
199 include/foo.f77 2
200 include/bar.f77 2
201 subdir/sss.f77
202 subdir/ttt.f77
203 """)
205 test.run(program = test.workpath(subdir_prog),
206 stdout = """\
207 subdir/prog.f77
208 subdir/include/foo.f77 1
209 subdir/include/bar.f77 1
210 subdir/sss.f77
211 subdir/ttt.f77
212 """)
214 test.run(program = test.workpath(variant_prog),
215 stdout = """\
216 subdir/prog.f77
217 include/foo.f77 2
218 include/bar.f77 2
219 subdir/sss.f77
220 subdir/ttt.f77
221 """)
223 # Make sure we didn't duplicate the source file in the variant subdirectory.
224 test.must_not_exist(test.workpath('variant', 'prog.f77'))
226 test.up_to_date(arguments = args)
228 # Change F77PATH and make sure we don't rebuild because of it.
229 test.write('SConstruct', """\
230 DefaultEnvironment(tools=[]) # test speedup
231 env = Environment(
232 F77='%s',
233 F77PATH=Split('inc2 include ${TARGET.dir} ${SOURCE.dir}'),
234 F77FLAGS='-x f77',
236 obj = env.Object(target='foobar/prog', source='subdir/prog.f77')
237 env.Program(target='prog', source=obj)
238 SConscript('subdir/SConscript', "env")
240 VariantDir('variant', 'subdir', 0)
241 include = Dir('include')
242 env = Environment(
243 F77='%s', F77PATH=['inc2', include, '#foobar', '#subdir'], F77FLAGS='-x f77'
245 SConscript('variant/SConscript', "env")
246 """ % (fc, fc))
248 test.up_to_date(arguments = args)
251 test.write(['inc2', 'foo.f77'],
252 r"""
253 PRINT *, 'inc2/foo.f77 1'
254 INCLUDE 'bar.f77'
255 """)
257 test.run(arguments = args)
259 test.run(program = test.workpath(prog),
260 stdout = """\
261 subdir/prog.f77
262 inc2/foo.f77 1
263 include/bar.f77 2
264 subdir/sss.f77
265 subdir/ttt.f77
266 """)
268 test.run(program = test.workpath(subdir_prog),
269 stdout = """\
270 subdir/prog.f77
271 subdir/include/foo.f77 1
272 subdir/include/bar.f77 1
273 subdir/sss.f77
274 subdir/ttt.f77
275 """)
277 test.run(program = test.workpath(variant_prog),
278 stdout = """\
279 subdir/prog.f77
280 include/foo.f77 2
281 include/bar.f77 2
282 subdir/sss.f77
283 subdir/ttt.f77
284 """)
286 test.up_to_date(arguments = args)
288 # Check that a null-string F77PATH doesn't blow up.
289 test.write('SConstruct', """\
290 DefaultEnvironment(tools=[]) # test speedup
291 env = Environment(tools=['%s'], F77PATH='', F77FLAGS='-x f77')
292 env.Object('foo', source='empty.f77')
293 """ % fc)
295 test.write('empty.f77', '')
296 test.run(arguments = '.')
298 test.pass_test()
300 # Local Variables:
301 # tab-width:4
302 # indent-tabs-mode:nil
303 # End:
304 # vim: set expandtab tabstop=4 shiftwidth=4: