llvm.org GIT mirror llvm / 4d15ba8
Revert "[lit] Refactor out some more common lit configuration code." This is breaking several bots. I have enough information to investigate, so I'm reverting to green until I get it figured out. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313922 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 2 years ago
4 changed file(s) with 112 addition(s) and 172 deletion(s). Raw diff Collapse all Expand all
1010 import lit.util
1111 import lit.formats
1212 from lit.llvm import llvm_config
13 from lit.llvm import ToolFilter
1413
1514 # name: The name of this test suite.
1615 config.name = 'LLVM'
134133 # The regex is a pre-assertion to avoid matching a preceding
135134 # dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns
136135 # also have a post-assertion to not match a trailing hyphen (foo-).
137 JUNKCHARS = r".-^/<"
138
139 required_tools = [
140 'lli', 'llvm-ar', 'llvm-as', 'llvm-bcanalyzer', 'llvm-config', 'llvm-cov',
141 'llvm-cxxdump', 'llvm-cvtres', 'llvm-diff', 'llvm-dis', 'llvm-dsymutil',
142 'llvm-dwarfdump', 'llvm-extract', 'llvm-isel-fuzzer', 'llvm-lib',
143 'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mcmarkup',
144 'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump',
145 'llvm-pdbutil', 'llvm-profdata', 'llvm-ranlib', 'llvm-readobj',
146 'llvm-rtdyld', 'llvm-size', 'llvm-split', 'llvm-strings', 'llvm-tblgen',
147 'llvm-c-test', 'llvm-cxxfilt', 'llvm-xray', 'yaml2obj', 'obj2yaml',
148 'FileCheck', 'yaml-bench', 'verify-uselistorder',
149 ToolFilter('bugpoint', post='-'),
150 ToolFilter('llc', pre=JUNKCHARS),
151 ToolFilter('llvm-symbolizer', pre=JUNKCHARS),
152 ToolFilter('opt', JUNKCHARS),
153 ToolFilter('sancov', pre=JUNKCHARS),
154 ToolFilter('sanstats', pre=JUNKCHARS),
155 # Handle these specially as they are strings searched for during testing.
156 ToolFilter(r'\| \bcount\b', verbatim=True),
157 ToolFilter(r'\| \bnot\b', verbatim=True)]
158
159 llvm_config.add_tool_substitutions(required_tools, config.llvm_tools_dir)
136 NOJUNK = r"(?
137
138
139 def find_tool_substitution(pattern):
140 # Extract the tool name from the pattern. This relies on the tool
141 # name being surrounded by \b word match operators. If the
142 # pattern starts with "| ", include it in the string to be
143 # substituted.
144 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
145 pattern)
146 tool_pipe = tool_match.group(2)
147 tool_name = tool_match.group(4)
148 # Did the user specify the tool path + arguments? This allows things like
149 # llvm-lit "-Dllc=llc -enable-misched -verify-machineinstrs"
150 tool_path = lit_config.params.get(tool_name)
151 if tool_path is None:
152 tool_path = lit.util.which(tool_name, config.llvm_tools_dir)
153 if tool_path is None:
154 return tool_name, tool_path, tool_pipe
155 if (tool_name == "llc" and
156 'LLVM_ENABLE_MACHINE_VERIFIER' in os.environ and
157 os.environ['LLVM_ENABLE_MACHINE_VERIFIER'] == "1"):
158 tool_path += " -verify-machineinstrs"
159 if (tool_name == "llvm-go"):
160 tool_path += " go=" + config.go_executable
161 return tool_name, tool_path, tool_pipe
162
163
164 for pattern in [r"\bbugpoint\b(?!-)",
165 NOJUNK + r"\bllc\b",
166 r"\blli\b",
167 r"\bllvm-ar\b",
168 r"\bllvm-as\b",
169 r"\bllvm-bcanalyzer\b",
170 r"\bllvm-config\b",
171 r"\bllvm-cov\b",
172 r"\bllvm-cxxdump\b",
173 r"\bllvm-cvtres\b",
174 r"\bllvm-diff\b",
175 r"\bllvm-dis\b",
176 r"\bllvm-dsymutil\b",
177 r"\bllvm-dwarfdump\b",
178 r"\bllvm-extract\b",
179 r"\bllvm-isel-fuzzer\b",
180 r"\bllvm-lib\b",
181 r"\bllvm-link\b",
182 r"\bllvm-lto\b",
183 r"\bllvm-lto2\b",
184 r"\bllvm-mc\b",
185 r"\bllvm-mcmarkup\b",
186 r"\bllvm-modextract\b",
187 r"\bllvm-nm\b",
188 r"\bllvm-objcopy\b",
189 r"\bllvm-objdump\b",
190 r"\bllvm-pdbutil\b",
191 r"\bllvm-profdata\b",
192 r"\bllvm-ranlib\b",
193 r"\bllvm-readobj\b",
194 r"\bllvm-rtdyld\b",
195 r"\bllvm-size\b",
196 r"\bllvm-split\b",
197 r"\bllvm-strings\b",
198 r"\bllvm-tblgen\b",
199 r"\bllvm-c-test\b",
200 r"\bllvm-cxxfilt\b",
201 r"\bllvm-xray\b",
202 NOJUNK + r"\bllvm-symbolizer\b",
203 NOJUNK + r"\bopt\b",
204 r"\bFileCheck\b",
205 r"\bobj2yaml\b",
206 NOJUNK + r"\bsancov\b",
207 NOJUNK + r"\bsanstats\b",
208 r"\byaml2obj\b",
209 r"\byaml-bench\b",
210 r"\bverify-uselistorder\b",
211 # Handle these specially as they are strings searched
212 # for during testing.
213 r"\| \bcount\b",
214 r"\| \bnot\b"]:
215 tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
216 if not tool_path:
217 # Warn, but still provide a substitution.
218 lit_config.note('Did not find ' + tool_name + ' in ' + config.llvm_tools_dir)
219 tool_path = config.llvm_tools_dir + '/' + tool_name
220 config.substitutions.append((pattern, tool_pipe + tool_path))
160221
161222 # For tools that are optional depending on the config, we won't warn
162223 # if they're missing.
163
164 optional_tools = [
165 'llvm-go', 'llvm-mt', 'Kaleidoscope-Ch3', 'Kaleidoscope-Ch4',
166 'Kaleidoscope-Ch5', 'Kaleidoscope-Ch6', 'Kaleidoscope-Ch7',
167 'Kaleidoscope-Ch8']
168 llvm_config.add_tool_substitutions(optional_tools, config.llvm_tools_dir,
169 warn_missing=False)
224 for pattern in [r"\bllvm-go\b",
225 r"\bllvm-mt\b",
226 r"\bKaleidoscope-Ch3\b",
227 r"\bKaleidoscope-Ch4\b",
228 r"\bKaleidoscope-Ch5\b",
229 r"\bKaleidoscope-Ch6\b",
230 r"\bKaleidoscope-Ch7\b",
231 r"\bKaleidoscope-Ch8\b"]:
232 tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
233 if not tool_path:
234 # Provide a substitution anyway, for the sake of consistent errors.
235 tool_path = config.llvm_tools_dir + '/' + tool_name
236 config.substitutions.append((pattern, tool_pipe + tool_path))
237
170238
171239 ### Targets
172240
0
1 from lit.llvm import config
1 import lit.util
2 import re
32
43 llvm_config = None
54
6 class ToolFilter(object):
7 """
8 String-like class used to build regex substitution patterns for
9 llvm tools. Handles things like adding word-boundary patterns,
10 and filtering characters from the beginning an end of a tool name
11 """
12
13 def __init__(self, name, pre=None, post=None, verbatim=False):
14 """
15 Construct a ToolFilter.
16
17 name: the literal name of the substitution to look for.
18
19 pre: If specified, the substitution will not find matches where
20 the character immediately preceding the word-boundary that begins
21 `name` is any of the characters in the string `pre`.
22
23 post: If specified, the substitution will not find matches where
24 the character immediately after the word-boundary that ends `name`
25 is any of the characters specified in the string `post`.
26
27 verbatim: If True, `name` is an exact regex that is passed to the
28 underlying substitution
29 """
30 if verbatim:
31 self.regex = name
32 return
33
34 def not_in(chars, where=''):
35 if not chars:
36 return ''
37 pattern_str = '|'.join(re.escape(x) for x in chars)
38 return r'(?{}!({}))'.format(where, pattern_str)
39
40 self.regex = not_in(pre, '<') + r'\b' + name + r'\b' + not_in(post)
41
42 def __str__(self):
43 return self.regex
44
45
465 def initialize(lit_config, test_config):
476 global llvm_config
48
497 llvm_config = config.LLVMConfig(lit_config, test_config)
508
135135 if name in self.config.environment:
136136 del self.config.environment[name]
137137
138 def get_process_output(self, command):
139 try:
140 cmd = subprocess.Popen(
141 command, stdout=subprocess.PIPE,
142 stderr=subprocess.PIPE, env=self.config.environment)
143 stdout, stderr = cmd.communicate()
144 return (stdout, stderr)
145 except OSError:
146 self.lit_config.fatal("Could not run process %s" % command)
147
148 def feature_config(self, features):
138 def feature_config(self, features, encoding = 'ascii'):
149139 # Ask llvm-config about the specified feature.
150140 arguments = [x for (x, _) in features]
151 config_path = os.path.join(self.config.llvm_tools_dir, 'llvm-config')
141 try:
142 config_path = os.path.join(self.config.llvm_tools_dir, 'llvm-config')
152143
153 output, _ = self.get_process_output([config_path] + arguments)
144 llvm_config_cmd = subprocess.Popen(
145 [config_path] + arguments,
146 stdout = subprocess.PIPE,
147 env=self.config.environment)
148 except OSError:
149 self.lit_config.fatal("Could not find llvm-config in " + self.config.llvm_tools_dir)
150
151 output, _ = llvm_config_cmd.communicate()
152 output = output.decode(encoding)
154153 lines = output.split('\n')
155
156154 for (feature_line, (_, patterns)) in zip(lines, features):
157155 # We should have either a callable or a dictionary. If it's a
158156 # dictionary, grep each key against the output and use the value if
164162 for (re_pattern, feature) in patterns.items():
165163 if re.search(re_pattern, feature_line):
166164 self.config.available_features.add(feature)
167
168
169 # Note that when substituting %clang_cc1 also fill in the include directory of
170 # the builtin headers. Those are part of even a freestanding environment, but
171 # Clang relies on the driver to locate them.
172 def get_clang_builtin_include_dir(self, clang):
173 # FIXME: Rather than just getting the version, we should have clang print
174 # out its resource dir here in an easy to scrape form.
175 clang_dir, _ = self.get_process_output([clang, '-print-file-name=include'])
176
177 if not clang_dir:
178 self.lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
179
180 clang_dir = clang_dir.strip()
181 if sys.platform in ['win32'] and not self.use_lit_shell:
182 # Don't pass dosish path separator to msys bash.exe.
183 clang_dir = clang_dir.replace('\\', '/')
184 # Ensure the result is an ascii string, across Python2.5+ - Python3.
185 return clang_dir
186
187 def make_itanium_abi_triple(self, triple):
188 m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
189 if not m:
190 self.lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple)
191 if m.group(3).lower() != 'win32':
192 # All non-win32 triples use the Itanium ABI.
193 return triple
194 return m.group(1) + '-' + m.group(2) + '-mingw32'
195
196 def make_msabi_triple(self, triple):
197 m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
198 if not m:
199 self.lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple)
200 isa = m.group(1).lower()
201 vendor = m.group(2).lower()
202 os = m.group(3).lower()
203 if os == 'win32':
204 # If the OS is win32, we're done.
205 return triple
206 if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa):
207 # For x86 ISAs, adjust the OS.
208 return isa + '-' + vendor + '-win32'
209 # -win32 is not supported for non-x86 targets; use a default.
210 return 'i686-pc-win32'
211
212 def add_tool_substitutions(self, tools, search_dirs, warn_missing = True):
213 if lit.util.is_string(search_dirs):
214 search_dirs = [search_dirs]
215
216 search_dirs = os.pathsep.join(search_dirs)
217 for tool in tools:
218 # Extract the tool name from the pattern. This relies on the tool
219 # name being surrounded by \b word match operators. If the
220 # pattern starts with "| ", include it in the string to be
221 # substituted.
222 if lit.util.is_string(tool):
223 tool = lit.util.make_word_regex(tool)
224 else:
225 tool = str(tool)
226
227 tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_\.]+)\\b\W*$",
228 tool)
229 if not tool_match:
230 continue
231
232 tool_pipe = tool_match.group(2)
233 tool_name = tool_match.group(4)
234 tool_path = lit.util.which(tool_name, search_dirs)
235 if not tool_path:
236 if warn_missing:
237 # Warn, but still provide a substitution.
238 self.lit_config.note('Did not find ' + tool_name + ' in %s' % search_dirs)
239 tool_path = self.config.llvm_tools_dir + '/' + tool_name
240
241 if tool_name == 'llc' and os.environ.get('LLVM_ENABLE_MACHINE_VERIFIER') == '1':
242 tool_path += ' -verify-machineinstrs'
243 if tool_name == 'llvm-go':
244 exe = getattr(self.config, 'go_executable', None)
245 if exe:
246 tool_path += " go=" + exe
247
248 self.config.substitutions.append((tool, tool_pipe + tool_path))
3535 return False
3636 raise ValueError('"{}" is not a valid boolean'.format(value))
3737
38 def make_word_regex(word):
39 return r'\b' + word + r'\b'
4038
4139 def to_bytes(s):
4240 """Return the parameter as type 'bytes', possibly encoding it.