Added fix for TeX includes with same name as subdirs.
[scons.git] / test / gnutools.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 """
28 Testing the gnu tool chain, i.e. the tools 'gcc', 'g++' and 'gnulink'.
29 """
30
31 import TestSCons
32 import sys
33
34 _python_ = TestSCons._python_
35 _exe = TestSCons._exe
36
37 def dll(s):
38     return TestSCons.dll_ + s + TestSCons._dll
39
40 test = TestSCons.TestSCons()
41
42 test.subdir('gnutools')
43
44 test.write(['gnutools','mygcc.py'], """
45 import getopt
46 import sys
47 cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
48 output = None
49 opt_string = ''
50 for opt, arg in cmd_opts:
51     if opt == '-o': output = open(arg, 'wb')
52     else: opt_string = opt_string + ' ' + opt + arg
53 output.write('gcc ' + opt_string + '\\n')
54 for a in args:
55     contents = open(a, 'rb').read()
56     output.write(contents)
57 output.close()
58 sys.exit(0)
59 """)
60
61 test.write(['gnutools','myg++.py'], """
62 import getopt
63 import sys
64 cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
65 output = None
66 opt_string = ''
67 for opt, arg in cmd_opts:
68     if opt == '-o': output = open(arg, 'wb')
69     else: opt_string = opt_string + ' ' + opt + arg
70 output.write('g++ ' + opt_string + '\\n')
71 for a in args:
72     contents = open(a, 'rb').read()
73     output.write(contents)
74 output.close()
75 sys.exit(0)
76 """)
77
78 test.subdir('work1')
79
80 test.write(['work1', 'cfile1.c'],"""
81 /* c file 1 */
82 """)
83
84 test.write(['work1', 'cfile2.c'],"""
85 /* c file 2 */
86 """)
87
88 test.write(['work1', 'cppfile1.cpp'],"""
89 /* cpp file 1 */
90 """)
91
92 test.write(['work1', 'cppfile2.cpp'],"""
93 /* cpp file 2 */
94 """)
95
96 mygcc_py = test.workpath('gnutools','mygcc.py')
97 mygxx_py = test.workpath('gnutools','myg++.py')
98
99 test.write(['work1', 'SConstruct'],"""
100 env = Environment(tools=['gcc','g++','gnulink'],
101                   CC=r'%(_python_)s %(mygcc_py)s',
102                   CXX=r'%(_python_)s %(mygxx_py)s',
103                   OBJSUFFIX='.o',
104                   SHOBJSUFFIX='.os')
105 env.Program('c-only', Split('cfile1.c cfile2.c'))
106 env.Program('cpp-only', Split('cppfile1.cpp cppfile2.cpp'))
107 env.Program('c-and-cpp', Split('cfile1.c cppfile1.cpp'))
108
109 env.SharedLibrary('c-only', Split('cfile1.c cfile2.c'))
110 env.SharedLibrary('cpp-only', Split('cppfile1.cpp cppfile2.cpp'))
111 env.SharedLibrary('c-and-cpp', Split('cfile1.c cppfile1.cpp'))
112 """ % locals())
113
114 test.run(chdir='work1')
115
116 def testObject(test, obj, expect):
117     contents = test.read(test.workpath('work1', obj))
118     line1 = contents.split('\n')[0]
119     actual = ' '.join(line1.split())
120     if not expect == actual:
121         print "%s:  %s != %s\n" % (obj, repr(expect), repr(actual))
122         test.fail_test()
123
124 if sys.platform in ('win32', 'cygwin'):
125     c_fpic = ''
126 else:
127     c_fpic = ' -fPIC'
128
129 testObject(test, 'cfile1.o',            'gcc -c')
130 testObject(test, 'cfile2.o',            'gcc -c')
131 testObject(test, 'cppfile1.o',          'g++ -c')
132 testObject(test, 'cppfile2.o',          'g++ -c')
133 testObject(test, 'cfile1.os',           'gcc -c' + c_fpic)
134 testObject(test, 'cfile2.os',           'gcc -c' + c_fpic)
135 testObject(test, 'cppfile1.os',         'g++ -c' + c_fpic)
136 testObject(test, 'cppfile2.os',         'g++ -c' + c_fpic)
137 testObject(test, 'c-only' + _exe,       'gcc')
138 testObject(test, 'cpp-only' + _exe,     'g++')
139 testObject(test, 'c-and-cpp' + _exe,    'g++')
140 testObject(test, dll('c-only'),         'gcc -shared')
141 testObject(test, dll('cpp-only'),       'g++ -shared')
142 testObject(test, dll('c-and-cpp'),      'g++ -shared')
143
144 test.pass_test()
145
146 # Local Variables:
147 # tab-width:4
148 # indent-tabs-mode:nil
149 # End:
150 # vim: set expandtab tabstop=4 shiftwidth=4: