added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / import.py
blob50d7b2178cff1cb7def77ec099e927b33dbbd9a4
1 #!/usr/bin/env python
3 # Permission is hereby granted, free of charge, to any person obtaining
4 # a copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish,
7 # distribute, sublicense, and/or sell copies of the Software, and to
8 # permit persons to whom the Software is furnished to do so, subject to
9 # the following conditions:
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
15 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
16 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 """
24 Verify that we can import and use the contents of Platform and Tool
25 modules directly.
26 """
28 import os
29 import re
31 # must do this here, since TestSCons will chdir
32 tooldir = os.path.join(os.getcwd(), 'SCons', 'Tool')
34 import TestSCons
35 test = TestSCons.TestSCons()
37 # Before executing any of the platform or tool modules, add some
38 # null entries to the environment $PATH variable to make sure there's
39 # no code that tries to index elements from the list before making sure
40 # they're non-null.
41 # (This was a problem in checkpoint release 0.97.d020070809.)
42 os.environ['PATH'] = os.pathsep + os.environ['PATH'] + \
43 os.pathsep + os.pathsep + '/no/such/dir' + os.pathsep
45 SConstruct_path = test.workpath('SConstruct')
47 platforms = [
48 'aix',
49 'cygwin',
50 'darwin',
51 'hpux',
52 'irix',
53 'os2',
54 'posix',
55 'sunos',
56 'win32'
59 for platform in platforms:
60 test.write('SConstruct', """
61 DefaultEnvironment(tools=[])
62 print("Platform %(platform)s")
63 env = Environment(platform = '%(platform)s', tools=[])
64 import SCons.Platform.%(platform)s
65 x = SCons.Platform.%(platform)s.generate
66 """ % locals())
67 test.run()
69 ignore = ('__init__.py',
70 # Can't import these everywhere due to Windows registry dependency.
71 '386asm.py', 'linkloc.py',
72 # Directory of common stuff for MSVC and MSVS
73 'MSCommon',
74 # clang common
75 "clangCommon",
76 # link common logic
77 "linkCommon",
78 # Sun pkgchk and pkginfo common stuff
79 'sun_pkg.py',
80 # RPM utilities
81 'rpmutils.py',
83 tools = []
84 for name in os.listdir(tooldir):
85 if name in ignore: continue
86 if name[0] == '#': continue
87 if name[0:1] == '.': continue
88 if name[-1] == '~' : continue
89 if name[-3:] == '.py':
90 if name[-8:] not in ('Tests.py', 'ommon.py'):
91 tools.append(name[:-3])
92 elif os.path.exists(os.path.join(tooldir,name,'__init__.py')):
93 tools.append(name)
94 tools.sort() # why not?
96 #if sys.platform == 'win32':
97 # Just comment out (for now?) due to registry dependency.
98 # tools.extend([
99 # '386asm',
100 # 'linkloc',
101 # ])
103 # Intel no compiler warning..
104 intel_no_compiler_warning = """
105 scons: warning: Failed to find Intel compiler for version='None', abi='[^']*'
106 """ + TestSCons.file_expr
108 # Intel no top dir warning.
109 intel_no_top_dir_warning = """
110 scons: warning: Can't find Intel compiler top dir for version='None', abi='[^']*'
111 """ + TestSCons.file_expr
113 # Intel no license directory warning
114 intel_license_warning = re.escape(
115 r"""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.
116 """) + TestSCons.file_expr
118 intel_warnings = [
119 re.compile(intel_license_warning),
120 re.compile(intel_no_compiler_warning),
121 re.compile(intel_no_compiler_warning + intel_license_warning),
122 re.compile(intel_no_top_dir_warning),
123 re.compile(intel_no_top_dir_warning + intel_license_warning),
126 moc = test.where_is('moc')
127 if moc:
128 import os.path
130 qtdir = os.path.dirname(os.path.dirname(moc))
131 qt3_err = fr"""
132 scons: warning: Could not detect qt3, using moc executable as a hint \(QT3DIR={qtdir}\)
134 else:
135 qt3_err = r"""
136 scons: warning: Could not detect qt3, using empty QT3DIR
139 qt_moved = r"""
140 scons: \*\*\* Deprecated tool 'qt' renamed to 'qt3'. Please update your build accordingly. 'qt3' will be removed entirely in a future release.
143 qt3_warnings = [re.compile(qt3_err + TestSCons.file_expr)]
144 qt_error = [re.compile(qt_moved + TestSCons.file_expr)]
146 error_output = {
147 'icl': intel_warnings,
148 'intelc': intel_warnings,
149 'qt3': qt3_warnings,
150 'qt': qt_error,
153 # An SConstruct for importing Tool names that have illegal characters
154 # for Python variable names.
155 indirect_import = """\
156 DefaultEnvironment(tools=[])
157 print("Tool %(tool)s (indirect)")
158 env = Environment(tools = ['%(tool)s'])
160 SCons = __import__('SCons.Tool.%(tool)s', globals(), locals(), [])
161 m = getattr(SCons.Tool, '%(tool)s')
162 env = Environment(tools=[])
163 m.generate(env)
166 # An SConstruct for importing Tool names "normally."
167 direct_import = """\
168 DefaultEnvironment(tools=[])
169 print("Tool %(tool)s (direct)")
170 env = Environment(tools = ['%(tool)s'])
172 import SCons.Tool.%(tool)s
173 env = Environment(tools=[])
174 SCons.Tool.%(tool)s.exists(env)
175 SCons.Tool.%(tool)s.generate(env)
178 failures = []
179 for tool in tools:
180 if tool[0] in '0123456789' or '+' in tool or tool in ('as',):
181 test.write('SConstruct', indirect_import % locals())
182 else:
183 test.write('SConstruct', direct_import % locals())
184 test.run(stderr=None, status=None)
185 stderr = test.stderr()
186 if stderr or test.status:
187 matched = None
188 for expression in error_output.get(tool, []):
189 if expression.match(stderr):
190 matched = 1
191 break
192 if not matched:
193 print(f"Failed importing '{tool}', stderr:")
194 print(stderr)
195 failures.append(tool)
197 test.fail_test(len(failures))
199 test.pass_test()
201 # Local Variables:
202 # tab-width:4
203 # indent-tabs-mode:nil
204 # End:
205 # vim: set expandtab tabstop=4 shiftwidth=4: