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