llvm.org GIT mirror llvm / af03e79
[lit] Update clang and lld to use new config helpers. NFC intended here, this only updates clang and lld's lit configs to use some helper functionality in the lit.llvm submodule. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313579 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
2 changed file(s) with 66 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
3838 # Propagate some variables from the host environment.
3939 llvm_config.with_system_environment(['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
4040
41 # Propagate LLVM_SRC_ROOT into the environment.
42 config.environment['LLVM_SRC_ROOT'] = config.llvm_src_root
4341
4442 # Set up OCAMLPATH to include newly built OCaml libraries.
4543 top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml')
329327 config.available_features.add('ld64_plugin')
330328
331329 # 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')
330 llvm_config.feature_config(
331 [('--assertion-mode', {'ON' : 'asserts'}),
332 ('--has-global-isel', {'ON' : 'global-isel'})])
334333
335334 if 'darwin' == sys.platform:
336335 try:
0 import os
1 import platform
12 import re
23 import subprocess
34 import sys
3738 if not self.use_lit_shell:
3839 features.add('shell')
3940
41
42 # Running on Darwin OS
43 if platform.system() in ['Darwin']:
44 # FIXME: lld uses the first, other projects use the second.
45 # We should standardize on the former.
46 features.add('system-linker-mach-o')
47 features.add('system-darwin')
48 elif platform.system() in ['Windows']:
49 # For tests that require Windows to run.
50 features.add('system-windows')
51
4052 # Native compilation: host arch == default triple arch
41 # FIXME: Consider cases that target can be executed
42 # even if host_triple were different from target_triple.
43 if config.host_triple == config.target_triple:
53 # Both of these values should probably be in every site config (e.g. as
54 # part of the standard header. But currently they aren't)
55 host_triple = getattr(config, 'host_triple', None)
56 target_triple = getattr(config, 'target_triple', None)
57 if host_triple and host_triple == target_triple:
4458 features.add("native")
4559
4660 # Sanitizers.
47 sanitizers = frozenset(x.lower() for x in getattr(config, 'llvm_use_sanitizer', []).split(';'))
61 sanitizers = getattr(config, 'llvm_use_sanitizer', '')
62 sanitizers = frozenset(x.lower() for x in sanitizers.split(';'))
4863 features.add(binary_feature('address' in sanitizers, 'asan', 'not_'))
4964 features.add(binary_feature('memory' in sanitizers, 'msan', 'not_'))
5065 features.add(binary_feature('undefined' in sanitizers, 'ubsan', 'not_'))
5772 if lit.util.pythonize_bool(long_tests):
5873 features.add("long_tests")
5974
60 target_triple = getattr(config, 'target_triple', None)
6175 if target_triple:
6276 if re.match(r'^x86_64.*-linux', target_triple):
6377 features.add("x86_64-linux")
7892 features.add('abi-breaking-checks')
7993
8094 def with_environment(self, variable, value, append_path = False):
81 if append_path and variable in self.config.environment:
95 if append_path:
96 # For paths, we should be able to take a list of them and process all
97 # of them.
98 paths_to_add = value
99 if isinstance(paths_to_add, basestring):
100 paths_to_add = [paths_to_add]
101
82102 def norm(x):
83103 return os.path.normcase(os.path.normpath(x))
84104
85 # Move it to the front if it already exists, otherwise insert it at the
86 # beginning.
87 value = norm(value)
88 current_value = self.config.environment[variable]
89 items = [norm(x) for x in current_value.split(os.path.pathsep)]
90 try:
91 items.remove(value)
92 except ValueError:
93 pass
94 value = os.path.pathsep.join([value] + items)
105 current_paths = self.config.environment.get(variable, "")
106 current_paths = current_paths.split(os.path.pathsep)
107 paths = [norm(p) for p in current_paths]
108 for p in paths_to_add:
109 # Move it to the front if it already exists, otherwise insert it at the
110 # beginning.
111 p = norm(p)
112 try:
113 paths.remove(p)
114 except ValueError:
115 pass
116 paths = [p] + paths
117 value = os.pathsep.join(paths)
95118 self.config.environment[variable] = value
96119
97120
103126 if value:
104127 self.with_environment(v, value, append_path)
105128
106 def feature_config(self, flag, feature):
107 # Ask llvm-config about assertion mode.
129 def clear_environment(self, variables):
130 for name in variables:
131 if name in self.config.environment:
132 del self.config.environment[name]
133
134 def feature_config(self, features, encoding = 'ascii'):
135 # Ask llvm-config about the specified feature.
136 arguments = [x for (x, _) in features]
108137 try:
138 config_path = os.path.join(self.config.llvm_tools_dir, 'llvm-config')
139
109140 llvm_config_cmd = subprocess.Popen(
110 [os.path.join(self.config.llvm_tools_dir, 'llvm-config'), flag],
141 [config_path] + arguments,
111142 stdout = subprocess.PIPE,
112143 env=self.config.environment)
113144 except OSError:
114145 self.lit_config.fatal("Could not find llvm-config in " + self.config.llvm_tools_dir)
115146
116147 output, _ = llvm_config_cmd.communicate()
117 if re.search(r'ON', output.decode('ascii')):
118 self.config.available_features.add(feature)
148 output = output.decode(encoding)
149 lines = output.split('\n')
150 for (line, (_, patterns)) in zip(lines, features):
151 # We should have either a callable or a dictionary. If it's a
152 # dictionary, grep each key against the output and use the value if
153 # it matches. If it's a callable, it does the entire translation.
154 if callable(patterns):
155 features_to_add = patterns(line)
156 self.config.available_features.update(features_to_add)
157 else:
158 for (match, feature) in patterns.items():
159 if re.search(line, match):
160 self.config.available_features.add(feature)