llvm.org GIT mirror llvm / 591b934
Revert lit changes related to lit.llvm module. It looks like this is going to be non-trivial to get working in both Py2 and Py3, so for now I'm reverting until I have time to fully test it under Python 3. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313429 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
6 changed file(s) with 158 addition(s) and 173 deletion(s). Raw diff Collapse all Expand all
11721172 set(TARGET_TRIPLE "\"+config.target_triple+\"")
11731173 endif()
11741174
1175 string(CONCAT LIT_SITE_CFG_IN_FOOTER
1176 "import lit.llvm\n"
1177 "lit.llvm.initialize(lit_config, config)\n")
1178
11791175 configure_file(${input} ${output} @ONLY)
11801176 get_filename_component(INPUT_DIR ${input} DIRECTORY)
11811177 if (EXISTS "${INPUT_DIR}/lit.cfg")
99
1010 import lit.util
1111 import lit.formats
12 from lit.llvm import llvm_config
1312
1413 # name: The name of this test suite.
1514 config.name = 'LLVM'
1615
16 # Tweak PATH for Win32 to decide to use bash.exe or not.
17 if sys.platform in ['win32']:
18 # Seek sane tools in directories and set to $PATH.
19 path = getattr(config, 'lit_tools_dir', None)
20 path = lit_config.getToolsPath(path,
21 config.environment['PATH'],
22 ['cmp.exe', 'grep.exe', 'sed.exe'])
23 if path is not None:
24 path = os.path.pathsep.join((path,
25 config.environment['PATH']))
26 config.environment['PATH'] = path
27
28 # Choose between lit's internal shell pipeline runner and a real shell. If
29 # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
30 use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
31 if use_lit_shell:
32 # 0 is external, "" is default, and everything else is internal.
33 execute_external = (use_lit_shell == "0")
34 else:
35 # Otherwise we default to internal on Windows and external elsewhere, as
36 # bash on Windows is usually very slow.
37 execute_external = (not sys.platform in ['win32'])
38
1739 # testFormat: The test format to use to interpret tests.
18 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
40 config.test_format = lit.formats.ShTest(execute_external)
1941
2042 # suffixes: A list of file extensions to treat as test files. This is overriden
2143 # by individual lit.local.cfg files in the test subdirectories.
3355 config.test_exec_root = os.path.join(config.llvm_obj_root, 'test')
3456
3557 # Tweak the PATH to include the tools dir.
36 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
37
38 # Propagate some variables from the host environment.
39 llvm_config.with_system_environment(['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
58 path = os.path.pathsep.join((config.llvm_tools_dir, config.environment['PATH']))
59 config.environment['PATH'] = path
60
61 # Propagate 'HOME' through the environment.
62 if 'HOME' in os.environ:
63 config.environment['HOME'] = os.environ['HOME']
64
65 # Propagate 'INCLUDE' through the environment.
66 if 'INCLUDE' in os.environ:
67 config.environment['INCLUDE'] = os.environ['INCLUDE']
68
69 # Propagate 'LIB' through the environment.
70 if 'LIB' in os.environ:
71 config.environment['LIB'] = os.environ['LIB']
72
73 # Propagate the temp directory. Windows requires this because it uses \Windows\
74 # if none of these are present.
75 if 'TMP' in os.environ:
76 config.environment['TMP'] = os.environ['TMP']
77 if 'TEMP' in os.environ:
78 config.environment['TEMP'] = os.environ['TEMP']
4079
4180 # Propagate LLVM_SRC_ROOT into the environment.
4281 config.environment['LLVM_SRC_ROOT'] = config.llvm_src_root
82
83 # Propagate PYTHON_EXECUTABLE into the environment
84 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
85 '')
86
87 # Propagate path to symbolizer for ASan/MSan.
88 for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
89 if symbolizer in os.environ:
90 config.environment[symbolizer] = os.environ[symbolizer]
4391
4492 # Set up OCAMLPATH to include newly built OCaml libraries.
4593 top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml')
4694 llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
47
48 llvm_config.with_system_environment('OCAMLPATH')
49 llvm_config.with_environment('OCAMLPATH', top_ocaml_lib, append_path=True)
50 llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True)
51
52 llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH')
53 llvm_config.with_environment('CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
95 ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, top_ocaml_lib))
96 if 'OCAMLPATH' in os.environ:
97 ocamlpath = os.path.pathsep.join((ocamlpath, os.environ['OCAMLPATH']))
98 config.environment['OCAMLPATH'] = ocamlpath
99
100 if 'CAML_LD_LIBRARY_PATH' in os.environ:
101 caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,
102 os.environ['CAML_LD_LIBRARY_PATH']))
103 config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path
104 else:
105 config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib
54106
55107 # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
56 llvm_config.with_environment('OCAMLRUNPARAM', 'b')
108 config.environment['OCAMLRUNPARAM'] = 'b'
57109
58110 # Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
59111 # available. This is darwin specific since it's currently only needed on darwin.
247299
248300 ### Features
249301
302 # Shell execution
303 if execute_external:
304 config.available_features.add('shell')
305
250306 # Others/can-execute.txt
251307 if sys.platform not in ['win32']:
252308 config.available_features.add('can-execute')
266322 if not config.build_shared_libs:
267323 config.available_features.add("static-libs")
268324
325 # Sanitizers.
326 if 'Address' in config.llvm_use_sanitizer:
327 config.available_features.add("asan")
328 else:
329 config.available_features.add("not_asan")
330 if 'Memory' in config.llvm_use_sanitizer:
331 config.available_features.add("msan")
332 else:
333 config.available_features.add("not_msan")
334 if 'Undefined' in config.llvm_use_sanitizer:
335 config.available_features.add("ubsan")
336 else:
337 config.available_features.add("not_ubsan")
338
339 # Check if we should run long running tests.
340 if lit_config.params.get("run_long_tests", None) == "true":
341 config.available_features.add("long_tests")
342
269343 # Direct object generation
270344 if not 'hexagon' in config.target_triple:
271345 config.available_features.add("object-emission")
346
347 if config.have_zlib:
348 config.available_features.add("zlib")
349 else:
350 config.available_features.add("nozlib")
272351
273352 # LLVM can be configured with an empty default triple
274353 # Some tests are "generic" and require a valid default triple
275354 if config.target_triple:
276355 config.available_features.add("default_triple")
356 if re.match(r'^x86_64.*-linux', config.target_triple):
357 config.available_features.add("x86_64-linux")
358
359 # Native compilation: host arch == default triple arch
360 # FIXME: Consider cases that target can be executed
361 # even if host_triple were different from target_triple.
362 if config.host_triple == config.target_triple:
363 config.available_features.add("native")
277364
278365 import subprocess
279366
328415 if have_ld64_plugin_support():
329416 config.available_features.add('ld64_plugin')
330417
331 # Ask llvm-config about asserts and global-isel.
332 llvm_config.feature_config('--assertion-mode', 'asserts')
333 llvm_config.feature_config('--has-global-isel', 'global-isel')
418 # Ask llvm-config about assertion mode.
419 try:
420 llvm_config_cmd = subprocess.Popen(
421 [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
422 stdout = subprocess.PIPE,
423 env=config.environment)
424 except OSError:
425 print("Could not find llvm-config in " + config.llvm_tools_dir)
426 exit(42)
427
428 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
429 config.available_features.add('asserts')
430 llvm_config_cmd.wait()
334431
335432 if 'darwin' == sys.platform:
336433 try:
343440 config.available_features.add('fma3')
344441 sysctl_cmd.wait()
345442
443 if platform.system() in ['Windows']:
444 if re.match(r'.*-win32$', config.target_triple):
445 config.available_features.add('target-windows')
446 # For tests that require Windows to run.
447 config.available_features.add('system-windows')
448
346449 # .debug_frame is not emitted for targeting Windows x64.
347450 if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
348451 config.available_features.add('debug_frame')
349452
453 # Check if we should use gmalloc.
454 use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
455 if use_gmalloc_str is not None:
456 if use_gmalloc_str.lower() in ('1', 'true'):
457 use_gmalloc = True
458 elif use_gmalloc_str.lower() in ('', '0', 'false'):
459 use_gmalloc = False
460 else:
461 lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
462 else:
463 # Default to not using gmalloc
464 use_gmalloc = False
465
466 # Allow use of an explicit path for gmalloc library.
467 # Will default to '/usr/lib/libgmalloc.dylib' if not set.
468 gmalloc_path_str = lit_config.params.get('gmalloc_path',
469 '/usr/lib/libgmalloc.dylib')
470
471 if use_gmalloc:
472 config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})
473
474 # Ask llvm-config about global-isel.
475 try:
476 llvm_config_cmd = subprocess.Popen(
477 [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--has-global-isel'],
478 stdout = subprocess.PIPE,
479 env=config.environment)
480 except OSError:
481 print("Could not find llvm-config in " + config.llvm_tools_dir)
482 exit(42)
483
484 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
485 config.available_features.add('global-isel')
486 llvm_config_cmd.wait()
487
350488 if config.have_libxar:
351489 config.available_features.add('xar')
352490
491 if config.enable_abi_breaking_checks == "1":
492 config.available_features.add('abi-breaking-checks')
493
353494 if config.llvm_libxml2_enabled == "1":
354495 config.available_features.add('libxml2')
5151 key, = e.args
5252 lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
5353
54 @LIT_SITE_CFG_IN_FOOTER@
55
5654 # Let the main config do the real work.
5755 lit_config.load_config(config, "@LLVM_SOURCE_DIR@/test/lit.cfg")
+0
-9
utils/lit/lit/llvm/__init__.py less more
None
1 from lit.llvm import config
2
3 llvm_config = None
4
5 def initialize(lit_config, test_config):
6 global llvm_config
7 llvm_config = config.LLVMConfig(lit_config, test_config)
8
+0
-117
utils/lit/lit/llvm/config.py less more
None import os
1 import re
2 import subprocess
3 import sys
4
5 import lit.util
6
7 # Choose between lit's internal shell pipeline runner and a real shell. If
8 # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
9 litshenv = os.environ.get("LIT_USE_INTERNAL_SHELL")
10 litsh = lit.util.pythonize_bool(litshenv) if litshenv else (sys.platform == 'win32')
11
12 def binary_feature(on, feature, off_prefix):
13 return feature if on else off_prefix + feature
14
15 class LLVMConfig(object):
16
17 def __init__(self, lit_config, config):
18 self.lit_config = lit_config
19 self.config = config
20
21 features = config.available_features
22
23 # Tweak PATH for Win32 to decide to use bash.exe or not.
24 if sys.platform == 'win32':
25 # For tests that require Windows to run.
26 features.add('system-windows')
27
28 # Seek sane tools in directories and set to $PATH.
29 path = self.lit_config.getToolsPath(config.lit_tools_dir,
30 config.environment['PATH'],
31 ['cmp.exe', 'grep.exe', 'sed.exe'])
32 self.with_environment('PATH', path, append_path=True)
33
34 self.use_lit_shell = litsh
35 if not self.use_lit_shell:
36 features.add('shell')
37
38 # Native compilation: host arch == default triple arch
39 # FIXME: Consider cases that target can be executed
40 # even if host_triple were different from target_triple.
41 if config.host_triple == config.target_triple:
42 features.add("native")
43
44 # Sanitizers.
45 sanitizers = frozenset(x.lower() for x in getattr(config, 'llvm_use_sanitizer', []).split(';'))
46 features.add(binary_feature('address' in sanitizers, 'asan', 'not_'))
47 features.add(binary_feature('memory' in sanitizers, 'msan', 'not_'))
48 features.add(binary_feature('undefined' in sanitizers, 'ubsan', 'not_'))
49
50 have_zlib = getattr(config, 'have_zlib', None)
51 features.add(binary_feature(have_zlib, 'zlib', 'no'))
52
53 # Check if we should run long running tests.
54 long_tests = lit_config.params.get("run_long_tests", None)
55 if lit.util.pythonize_bool(long_tests):
56 features.add("long_tests")
57
58 target_triple = getattr(config, 'target_triple', None)
59 if target_triple:
60 if re.match(r'^x86_64.*-linux', target_triple):
61 features.add("x86_64-linux")
62 if re.match(r'.*-win32$', target_triple):
63 features.add('target-windows')
64
65 use_gmalloc = lit_config.params.get('use_gmalloc', None)
66 if lit.util.pythonize_bool(use_gmalloc):
67 # Allow use of an explicit path for gmalloc library.
68 # Will default to '/usr/lib/libgmalloc.dylib' if not set.
69 gmalloc_path_str = lit_config.params.get('gmalloc_path',
70 '/usr/lib/libgmalloc.dylib')
71 if gmalloc_path_str is not None:
72 self.with_environment('DYLD_INSERT_LIBRARIES', gmalloc_path_str)
73
74 breaking_checks = getattr(config, 'enable_abi_breaking_checks', None)
75 if lit.util.pythonize_bool(breaking_checks):
76 features.add('abi-breaking-checks')
77
78 def with_environment(self, variable, value, append_path = False):
79 if append_path and variable in self.config.environment:
80 def norm(x):
81 return os.path.normcase(os.path.normpath(x))
82
83 # Move it to the front if it already exists, otherwise insert it at the
84 # beginning.
85 value = norm(value)
86 current_value = self.config.environment[variable]
87 items = [norm(x) for x in current_value.split(os.path.pathsep)]
88 try:
89 items.remove(value)
90 except ValueError:
91 pass
92 value = os.path.pathsep.join([value] + items)
93 self.config.environment[variable] = value
94
95
96 def with_system_environment(self, variables, append_path = False):
97 if isinstance(variables, basestring):
98 variables = [variables]
99 for v in variables:
100 value = os.environ.get(v)
101 if value:
102 self.with_environment(v, value, append_path)
103
104 def feature_config(self, flag, feature):
105 # Ask llvm-config about assertion mode.
106 try:
107 llvm_config_cmd = subprocess.Popen(
108 [os.path.join(self.config.llvm_tools_dir, 'llvm-config'), flag],
109 stdout = subprocess.PIPE,
110 env=self.config.environment)
111 except OSError:
112 self.lit_config.fatal("Could not find llvm-config in " + self.config.llvm_tools_dir)
113
114 output, _ = llvm_config_cmd.communicate()
115 if re.search(r'ON', output.decode('ascii')):
116 self.config.available_features.add(feature)
0 import errno
11 import itertools
22 import math
3 import numbers
43 import os
54 import platform
65 import signal
76 import subprocess
87 import sys
98 import threading
10
11
12 def pythonize_bool(value):
13 def is_string(value):
14 try:
15 # Python 2 and Python 3 are different here.
16 return isinstance(value, basestring)
17 except NameError:
18 return isinstance(value, str)
19
20 if value is None:
21 return False
22 if type(value) is bool:
23 return value
24 if isinstance(value, numbers.Number):
25 return value != 0
26 if is_string(value):
27 if value.lower() in ('1', 'true', 'on', 'yes'):
28 return True
29 if value.lower() in ('', '0', 'false', 'off', 'no'):
30 return False
31 raise ValueError('"{}" is not a valid boolean'.format(value))
32
339
3410 def to_bytes(s):
3511 """Return the parameter as type 'bytes', possibly encoding it.