Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[scons.git] / test / CPPFLAGS.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 string
29 import sys
30 import TestSCons
31
32 python = TestSCons.python
33 _exe   = TestSCons._exe
34 _obj   = TestSCons._obj
35 _shobj = TestSCons._shobj
36
37 test = TestSCons.TestSCons()
38
39 # Writing this to accomodate both our in-line tool chain and the
40 # MSVC command lines is too hard, and will be completely unnecessary
41 # some day when we separate our tests.  Punt for now.
42 test.no_result(sys.platform == 'win32')
43
44
45
46 if sys.platform == 'win32':
47
48     test.write('mylink.py', r"""
49 import getopt
50 import os
51 import sys
52 args = sys.argv[1:]
53 while args:
54     a = args[0]
55     if a[0] != '/':
56         break
57     args.pop(0)
58     if a[:5] == '/OUT:': out = a[5:]
59 infile = open(args[0], 'rb')
60 outfile = open(out, 'wb')
61 for l in infile.readlines():
62     if l[:5] != '#link':
63         outfile.write(l)
64 sys.exit(0)
65 """)
66
67 else:
68
69     test.write('mylink.py', r"""
70 import getopt
71 import os
72 import sys
73 opts, args = getopt.getopt(sys.argv[1:], 'o:s:')
74 for opt, arg in opts:
75     if opt == '-o': out = arg
76 outfile = open(out, 'wb')
77 for f in args:
78     infile = open(f, 'rb')
79     for l in infile.readlines():
80         if l[:5] != '#link':
81             outfile.write(l)
82 sys.exit(0)
83 """)
84
85 test.write('mygcc.py', r"""
86 import getopt
87 import os
88 import sys
89 compiler = sys.argv[1]
90 clen = len(compiler) + 1
91 opts, args = getopt.getopt(sys.argv[2:], 'co:xf:')
92 for opt, arg in opts:
93     if opt == '-o': out = arg
94     elif opt == '-x': open('mygcc.out', 'ab').write(compiler + "\n")
95 infile = open(args[0], 'rb')
96 outfile = open(out, 'wb')
97 for l in infile.readlines():
98     if l[:clen] != '#' + compiler:
99         outfile.write(l)
100 sys.exit(0)
101 """)
102
103 test.write('SConstruct', """
104 env = Environment(CPPFLAGS = '-x',
105                   LINK = r'%s mylink.py',
106                   LINKFLAGS = [],
107                   CC = r'%s mygcc.py cc',
108                   CXX = r'%s mygcc.py c++',
109                   CXXFLAGS = [],
110                   FORTRAN = r'%s mygcc.py g77')
111 env.Program(target = 'foo', source = Split('test1.c test2.cpp test3.F'))
112 """ % (python, python, python, python))
113
114 test.write('test1.c', r"""test1.c
115 #cc
116 #link
117 """)
118
119 test.write('test2.cpp', r"""test2.cpp
120 #c++
121 #link
122 """)
123
124 test.write('test3.F', r"""test3.F
125 #g77
126 #link
127 """)
128
129 test.run(arguments = '.', stderr=None)
130
131 test.must_match('test1' + _obj, "test1.c\n#link\n")
132 test.must_match('test2' + _obj, "test2.cpp\n#link\n")
133 test.must_match('test3' + _obj, "test3.F\n#link\n")
134 test.must_match('foo' + _exe,   "test1.c\ntest2.cpp\ntest3.F\n")
135 if TestSCons.case_sensitive_suffixes('.F', '.f'):
136     test.must_match('mygcc.out', "cc\nc++\ng77\n")
137 else:
138     test.must_match('mygcc.out', "cc\nc++\n")   
139
140 test.write('SConstruct', """
141 env = Environment(CPPFLAGS = '-x',
142                   SHLINK = r'%s mylink.py',
143                   SHLINKFLAGS = [],
144                   CC = r'%s mygcc.py cc',
145                   CXX = r'%s mygcc.py c++',
146                   CXXFLAGS = [],
147                   FORTRAN = r'%s mygcc.py g77')
148 env.SharedLibrary(target = File('foo.bar'),
149                   source = Split('test1.c test2.cpp test3.F'))
150 """ % (python, python, python, python))
151
152 test.write('test1.c', r"""test1.c
153 #cc
154 #link
155 """)
156
157 test.write('test2.cpp', r"""test2.cpp
158 #c++
159 #link
160 """)
161
162 test.write('test3.F', r"""test3.F
163 #g77
164 #link
165 """)
166
167 test.unlink('mygcc.out')
168 test.unlink('test1' + _obj)
169 test.unlink('test2' + _obj)
170 test.unlink('test3' + _obj)
171
172 test.run(arguments = '.', stderr = None)
173
174 test.must_match('test1' + _shobj, "test1.c\n#link\n")
175 test.must_match('test2' + _shobj, "test2.cpp\n#link\n")
176 test.must_match('test3' + _shobj, "test3.F\n#link\n")
177 test.must_match('foo.bar',        "test1.c\ntest2.cpp\ntest3.F\n")
178 if TestSCons.case_sensitive_suffixes('.F', '.f'):
179     test.must_match('mygcc.out', "cc\nc++\ng77\n")
180 else:
181     test.must_match('mygcc.out', "cc\nc++\n")   
182
183 test.pass_test()