Eliminate unnecessary WIN32/Win32/win32 references in tests, too.
[scons.git] / test / import.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 Verify that we can import and use the contents of Platform and Tool
29 modules directly.
30 """
31
32 import TestSCons
33
34 test = TestSCons.TestSCons()
35
36 platforms = [
37     'aix',
38     'cygwin',
39     'darwin',
40     'hpux',
41     'irix',
42     'os2',
43     'posix',
44     'sunos',
45     'win32'
46 ]
47
48 for platform in platforms:
49     test.write('SConstruct', """
50 env = Environment(platform = '%s')
51 import SCons.Platform.%s
52 x = SCons.Platform.%s.generate
53 """ % (platform, platform, platform))
54     test.run()
55
56 tools = [
57     # Can't import '386asm' everywhere due to Windows registry dependency.
58     'aixc++',
59     'aixcc',
60     'aixf77',
61     'aixlink',
62     'applelink',
63     'ar',
64     'as',
65     'bcc32',
66     'BitKeeper',
67     'c++',
68     'cc',
69     'cvf',
70     'CVS',
71     'default',
72     'dmd',
73     'dvi',
74     'dvipdf',
75     'dvips',
76     'f77',
77     'f90',
78     'f95',
79     'fortran',
80     'g++',
81     'g77',
82     'gas',
83     'gcc',
84     'gnulink',
85     'gs',
86     'hpc++',
87     'hpcc',
88     'hplink',
89     'icc',
90     'icl',
91     'ifort',
92     'ifl',
93     'ilink',
94     'ilink32',
95     'intelc',
96     'jar',
97     'javac',
98     'javah',
99     'latex',
100     'lex',
101     'link',
102     # Can't import 'linkloc' everywhere due to Windows registry dependency.
103     'm4',
104     'masm',
105     'midl',
106     'mingw',
107     'mslib',
108     'mslink',
109     'msvc',
110     'msvs',
111     'mwcc',
112     'mwld',
113     'nasm',
114     'pdf',
115     'pdflatex',
116     'pdftex',
117     'Perforce',
118     'qt',
119     'RCS',
120     'rmic',
121     'rpcgen',
122     'SCCS',
123     'sgiar',
124     'sgic++',
125     'sgicc',
126     'sgilink',
127     'Subversion',
128     'sunar',
129     'sunc++',
130     'suncc',
131     'sunlink',
132     'swig',
133     'tar',
134     'tex',
135     'tlib',
136     'yacc',
137     'zip',
138 ]
139
140 # Intel no compiler warning..
141 intel_no_compiler_fmt = """
142 scons: warning: Failed to find Intel compiler for version='None', abi='%s'
143 File "SConstruct", line 1, in ?
144 """
145
146 intel_no_compiler_32_warning = intel_no_compiler_fmt % 'ia32'
147 intel_no_compiler_64_warning = intel_no_compiler_fmt % 'x86_64'
148
149 # Intel no top dir warning.
150 intel_no_top_dir_fmt = """
151 scons: warning: Can't find Intel compiler top dir for version='None', abi='%s'
152 File "SConstruct", line 1, in ?
153 """
154
155 intel_no_top_dir_32_warning = intel_no_top_dir_fmt % 'ia32'
156 intel_no_top_dir_64_warning = intel_no_top_dir_fmt % 'x86_64'
157
158 # Intel no license directory warning
159 intel_license_warning = """
160 scons: warning: Intel license dir was not found.  Tried using the INTEL_LICENSE_FILE environment variable (), the registry () and the default path (C:\Program Files\Common Files\Intel\Licenses).  Using the default path as a last resort.
161 File "SConstruct", line 1, in ?
162 """
163
164 intel_warnings = [
165     intel_license_warning,
166     intel_no_compiler_32_warning,
167     intel_no_compiler_32_warning + intel_license_warning,
168     intel_no_compiler_64_warning,
169     intel_no_compiler_64_warning + intel_license_warning,
170     intel_no_top_dir_32_warning,
171     intel_no_top_dir_32_warning + intel_license_warning,
172     intel_no_top_dir_64_warning,
173     intel_no_top_dir_64_warning + intel_license_warning,
174 ]
175
176 moc = test.where_is('moc')
177 if moc:
178     import os.path
179     qt_err = """
180 scons: warning: Could not detect qt, using moc executable as a hint (QTDIR=%s)
181 File "SConstruct", line 1, in ?
182 """ % os.path.dirname(os.path.dirname(moc))
183 else:
184     qt_err = """
185 scons: warning: Could not detect qt, using empty QTDIR
186 File "SConstruct", line 1, in ?
187 """
188
189 error_output = {
190     'icl' : intel_warnings,
191     'intelc' : intel_warnings,
192     'qt' : [qt_err],
193 }
194
195 # An SConstruct for importing Tool names that have illegal characters
196 # for Python variable names.
197 indirect_import = """\
198 env = Environment(tools = ['%s'])
199 SCons = __import__('SCons.Tool.%s', globals(), locals(), [])
200 m = getattr(SCons.Tool, '%s')
201 x = m.generate
202 """
203
204 # An SConstruct for importing Tool names "normally."
205 direct_import = """\
206 env = Environment(tools = ['%s'])
207 import SCons.Tool.%s
208 x = SCons.Tool.%s.generate
209 """
210
211 failures = []
212 for tool in tools:
213     if tool[0] in '0123456789' or '+' in tool:
214         test.write('SConstruct', indirect_import % (tool, tool, tool))
215     else:
216         test.write('SConstruct', direct_import % (tool, tool, tool))
217     test.run(stderr=None)
218     stderr = test.stderr()
219     if not stderr in [''] + error_output.get(tool, []):
220         print "Failed importing '%s', stderr:" % tool
221         print stderr
222         failures.append(tool)
223
224 test.fail_test(len(failures))
225
226 test.pass_test()