added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / Fortran / module-subdir.py
blob0b87aa2f19412a2afc30b09a884eeec9704b9bac
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Validate that $FORTRANMODDIR values get expanded correctly on Fortran
29 command lines relative to the appropriate subdirectory.
30 """
32 import os
34 import TestSCons
36 _python_ = TestSCons._python_
38 test = TestSCons.TestSCons()
40 test.subdir('subdir',
41 ['subdir', 'src'],
42 ['subdir', 'build'])
44 test.write('myfortran.py', r"""
45 import getopt
46 import os
47 import sys
48 comment = ('#' + sys.argv[1]).encode()
49 length = len(comment)
50 opts, args = getopt.getopt(sys.argv[2:], 'cM:o:')
51 for opt, arg in opts:
52 if opt == '-o': out = arg
53 elif opt == '-M': modsubdir = arg
54 import os
55 with open(out, 'wb') as ofp, open(args[0], 'rb') as ifp:
56 for l in ifp.readlines():
57 if l[:7] == b'module ':
58 module = modsubdir + os.sep + l[7:-1].decode() + '.mod'
59 with open(module, 'wb') as f:
60 f.write(('myfortran.py wrote %s\n' % module).encode())
61 if l[:length] != comment:
62 ofp.write(l)
63 sys.exit(0)
64 """)
66 test.write('myar.py', """\
67 import sys
68 with open(sys.argv[1], 'wb') as ofp:
69 for s in sys.argv[2:]:
70 with open(s, 'rb') as ifp:
71 ofp.write(ifp.read())
72 sys.exit(0)
73 """)
75 test.write('SConstruct', """\
76 env = Environment(FORTRANMODDIRPREFIX = '-M',
77 FORTRANMODDIR = 'modules',
78 FORTRAN = r'%(_python_)s myfortran.py fortran',
79 AR = 'myar.py',
80 ARCOM = r'%(_python_)s $AR $TARGET $SOURCES',
81 RANLIBCOM = '')
82 Export('env')
83 objs = SConscript('subdir/SConscript')
84 env.Library('bidule', objs)
85 """ % locals())
87 test.write(['subdir', 'SConscript'], """\
88 Import('env')
90 env['FORTRANMODDIR'] = 'build'
91 sources = ['src/modfile.f']
92 objs = env.Object(sources)
93 Return("objs")
94 """)
96 test.write(['subdir', 'src', 'modfile.f'], """\
97 #fortran comment
98 module somemodule
100 integer :: nothing
102 end module
103 """)
106 test.run(arguments = '.')
108 somemodule = os.path.join('subdir', 'build', 'somemodule.mod')
110 expect = "myfortran.py wrote %s\n" % somemodule
112 test.must_match(['subdir', 'build', 'somemodule.mod'], expect)
114 test.pass_test()
116 # Local Variables:
117 # tab-width:4
118 # indent-tabs-mode:nil
119 # End:
120 # vim: set expandtab tabstop=4 shiftwidth=4: