Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 4d15ba8

Browse files
author
Zachary Turner
committed
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
1 parent 4d7a2de commit 4d15ba8

File tree

4 files changed

+111
-171
lines changed

4 files changed

+111
-171
lines changed

test/lit.cfg.py

Lines changed: 98 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import lit.util
1212
import lit.formats
1313
from lit.llvm import llvm_config
14-
from lit.llvm import ToolFilter
1514

1615
# name: The name of this test suite.
1716
config.name = 'LLVM'
@@ -135,39 +134,108 @@ def get_asan_rtlib():
135134
# The regex is a pre-assertion to avoid matching a preceding
136135
# dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns
137136
# also have a post-assertion to not match a trailing hyphen (foo-).
138-
JUNKCHARS = r".-^/<"
139-
140-
required_tools = [
141-
'lli', 'llvm-ar', 'llvm-as', 'llvm-bcanalyzer', 'llvm-config', 'llvm-cov',
142-
'llvm-cxxdump', 'llvm-cvtres', 'llvm-diff', 'llvm-dis', 'llvm-dsymutil',
143-
'llvm-dwarfdump', 'llvm-extract', 'llvm-isel-fuzzer', 'llvm-lib',
144-
'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mcmarkup',
145-
'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump',
146-
'llvm-pdbutil', 'llvm-profdata', 'llvm-ranlib', 'llvm-readobj',
147-
'llvm-rtdyld', 'llvm-size', 'llvm-split', 'llvm-strings', 'llvm-tblgen',
148-
'llvm-c-test', 'llvm-cxxfilt', 'llvm-xray', 'yaml2obj', 'obj2yaml',
149-
'FileCheck', 'yaml-bench', 'verify-uselistorder',
150-
ToolFilter('bugpoint', post='-'),
151-
ToolFilter('llc', pre=JUNKCHARS),
152-
ToolFilter('llvm-symbolizer', pre=JUNKCHARS),
153-
ToolFilter('opt', JUNKCHARS),
154-
ToolFilter('sancov', pre=JUNKCHARS),
155-
ToolFilter('sanstats', pre=JUNKCHARS),
156-
# Handle these specially as they are strings searched for during testing.
157-
ToolFilter(r'\| \bcount\b', verbatim=True),
158-
ToolFilter(r'\| \bnot\b', verbatim=True)]
159-
160-
llvm_config.add_tool_substitutions(required_tools, config.llvm_tools_dir)
137+
NOJUNK = r"(?<!\.|-|\^|/|<)"
138+
139+
140+
def find_tool_substitution(pattern):
141+
# Extract the tool name from the pattern. This relies on the tool
142+
# name being surrounded by \b word match operators. If the
143+
# pattern starts with "| ", include it in the string to be
144+
# substituted.
145+
tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
146+
pattern)
147+
tool_pipe = tool_match.group(2)
148+
tool_name = tool_match.group(4)
149+
# Did the user specify the tool path + arguments? This allows things like
150+
# llvm-lit "-Dllc=llc -enable-misched -verify-machineinstrs"
151+
tool_path = lit_config.params.get(tool_name)
152+
if tool_path is None:
153+
tool_path = lit.util.which(tool_name, config.llvm_tools_dir)
154+
if tool_path is None:
155+
return tool_name, tool_path, tool_pipe
156+
if (tool_name == "llc" and
157+
'LLVM_ENABLE_MACHINE_VERIFIER' in os.environ and
158+
os.environ['LLVM_ENABLE_MACHINE_VERIFIER'] == "1"):
159+
tool_path += " -verify-machineinstrs"
160+
if (tool_name == "llvm-go"):
161+
tool_path += " go=" + config.go_executable
162+
return tool_name, tool_path, tool_pipe
163+
164+
165+
for pattern in [r"\bbugpoint\b(?!-)",
166+
NOJUNK + r"\bllc\b",
167+
r"\blli\b",
168+
r"\bllvm-ar\b",
169+
r"\bllvm-as\b",
170+
r"\bllvm-bcanalyzer\b",
171+
r"\bllvm-config\b",
172+
r"\bllvm-cov\b",
173+
r"\bllvm-cxxdump\b",
174+
r"\bllvm-cvtres\b",
175+
r"\bllvm-diff\b",
176+
r"\bllvm-dis\b",
177+
r"\bllvm-dsymutil\b",
178+
r"\bllvm-dwarfdump\b",
179+
r"\bllvm-extract\b",
180+
r"\bllvm-isel-fuzzer\b",
181+
r"\bllvm-lib\b",
182+
r"\bllvm-link\b",
183+
r"\bllvm-lto\b",
184+
r"\bllvm-lto2\b",
185+
r"\bllvm-mc\b",
186+
r"\bllvm-mcmarkup\b",
187+
r"\bllvm-modextract\b",
188+
r"\bllvm-nm\b",
189+
r"\bllvm-objcopy\b",
190+
r"\bllvm-objdump\b",
191+
r"\bllvm-pdbutil\b",
192+
r"\bllvm-profdata\b",
193+
r"\bllvm-ranlib\b",
194+
r"\bllvm-readobj\b",
195+
r"\bllvm-rtdyld\b",
196+
r"\bllvm-size\b",
197+
r"\bllvm-split\b",
198+
r"\bllvm-strings\b",
199+
r"\bllvm-tblgen\b",
200+
r"\bllvm-c-test\b",
201+
r"\bllvm-cxxfilt\b",
202+
r"\bllvm-xray\b",
203+
NOJUNK + r"\bllvm-symbolizer\b",
204+
NOJUNK + r"\bopt\b",
205+
r"\bFileCheck\b",
206+
r"\bobj2yaml\b",
207+
NOJUNK + r"\bsancov\b",
208+
NOJUNK + r"\bsanstats\b",
209+
r"\byaml2obj\b",
210+
r"\byaml-bench\b",
211+
r"\bverify-uselistorder\b",
212+
# Handle these specially as they are strings searched
213+
# for during testing.
214+
r"\| \bcount\b",
215+
r"\| \bnot\b"]:
216+
tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
217+
if not tool_path:
218+
# Warn, but still provide a substitution.
219+
lit_config.note('Did not find ' + tool_name + ' in ' + config.llvm_tools_dir)
220+
tool_path = config.llvm_tools_dir + '/' + tool_name
221+
config.substitutions.append((pattern, tool_pipe + tool_path))
161222

162223
# For tools that are optional depending on the config, we won't warn
163224
# if they're missing.
225+
for pattern in [r"\bllvm-go\b",
226+
r"\bllvm-mt\b",
227+
r"\bKaleidoscope-Ch3\b",
228+
r"\bKaleidoscope-Ch4\b",
229+
r"\bKaleidoscope-Ch5\b",
230+
r"\bKaleidoscope-Ch6\b",
231+
r"\bKaleidoscope-Ch7\b",
232+
r"\bKaleidoscope-Ch8\b"]:
233+
tool_name, tool_path, tool_pipe = find_tool_substitution(pattern)
234+
if not tool_path:
235+
# Provide a substitution anyway, for the sake of consistent errors.
236+
tool_path = config.llvm_tools_dir + '/' + tool_name
237+
config.substitutions.append((pattern, tool_pipe + tool_path))
164238

165-
optional_tools = [
166-
'llvm-go', 'llvm-mt', 'Kaleidoscope-Ch3', 'Kaleidoscope-Ch4',
167-
'Kaleidoscope-Ch5', 'Kaleidoscope-Ch6', 'Kaleidoscope-Ch7',
168-
'Kaleidoscope-Ch8']
169-
llvm_config.add_tool_substitutions(optional_tools, config.llvm_tools_dir,
170-
warn_missing=False)
171239

172240
### Targets
173241

utils/lit/lit/llvm/__init__.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,9 @@
1+
12
from lit.llvm import config
2-
import lit.util
3-
import re
43

54
llvm_config = None
65

7-
class ToolFilter(object):
8-
"""
9-
String-like class used to build regex substitution patterns for
10-
llvm tools. Handles things like adding word-boundary patterns,
11-
and filtering characters from the beginning an end of a tool name
12-
"""
13-
14-
def __init__(self, name, pre=None, post=None, verbatim=False):
15-
"""
16-
Construct a ToolFilter.
17-
18-
name: the literal name of the substitution to look for.
19-
20-
pre: If specified, the substitution will not find matches where
21-
the character immediately preceding the word-boundary that begins
22-
`name` is any of the characters in the string `pre`.
23-
24-
post: If specified, the substitution will not find matches where
25-
the character immediately after the word-boundary that ends `name`
26-
is any of the characters specified in the string `post`.
27-
28-
verbatim: If True, `name` is an exact regex that is passed to the
29-
underlying substitution
30-
"""
31-
if verbatim:
32-
self.regex = name
33-
return
34-
35-
def not_in(chars, where=''):
36-
if not chars:
37-
return ''
38-
pattern_str = '|'.join(re.escape(x) for x in chars)
39-
return r'(?{}!({}))'.format(where, pattern_str)
40-
41-
self.regex = not_in(pre, '<') + r'\b' + name + r'\b' + not_in(post)
42-
43-
def __str__(self):
44-
return self.regex
45-
46-
476
def initialize(lit_config, test_config):
487
global llvm_config
49-
508
llvm_config = config.LLVMConfig(lit_config, test_config)
519

utils/lit/lit/llvm/config.py

Lines changed: 12 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,22 @@ def clear_environment(self, variables):
136136
if name in self.config.environment:
137137
del self.config.environment[name]
138138

139-
def get_process_output(self, command):
140-
try:
141-
cmd = subprocess.Popen(
142-
command, stdout=subprocess.PIPE,
143-
stderr=subprocess.PIPE, env=self.config.environment)
144-
stdout, stderr = cmd.communicate()
145-
return (stdout, stderr)
146-
except OSError:
147-
self.lit_config.fatal("Could not run process %s" % command)
148-
149-
def feature_config(self, features):
139+
def feature_config(self, features, encoding = 'ascii'):
150140
# Ask llvm-config about the specified feature.
151141
arguments = [x for (x, _) in features]
152-
config_path = os.path.join(self.config.llvm_tools_dir, 'llvm-config')
142+
try:
143+
config_path = os.path.join(self.config.llvm_tools_dir, 'llvm-config')
153144

154-
output, _ = self.get_process_output([config_path] + arguments)
155-
lines = output.split('\n')
145+
llvm_config_cmd = subprocess.Popen(
146+
[config_path] + arguments,
147+
stdout = subprocess.PIPE,
148+
env=self.config.environment)
149+
except OSError:
150+
self.lit_config.fatal("Could not find llvm-config in " + self.config.llvm_tools_dir)
156151

152+
output, _ = llvm_config_cmd.communicate()
153+
output = output.decode(encoding)
154+
lines = output.split('\n')
157155
for (feature_line, (_, patterns)) in zip(lines, features):
158156
# We should have either a callable or a dictionary. If it's a
159157
# dictionary, grep each key against the output and use the value if
@@ -165,85 +163,3 @@ def feature_config(self, features):
165163
for (re_pattern, feature) in patterns.items():
166164
if re.search(re_pattern, feature_line):
167165
self.config.available_features.add(feature)
168-
169-
170-
# Note that when substituting %clang_cc1 also fill in the include directory of
171-
# the builtin headers. Those are part of even a freestanding environment, but
172-
# Clang relies on the driver to locate them.
173-
def get_clang_builtin_include_dir(self, clang):
174-
# FIXME: Rather than just getting the version, we should have clang print
175-
# out its resource dir here in an easy to scrape form.
176-
clang_dir, _ = self.get_process_output([clang, '-print-file-name=include'])
177-
178-
if not clang_dir:
179-
self.lit_config.fatal("Couldn't find the include dir for Clang ('%s')" % clang)
180-
181-
clang_dir = clang_dir.strip()
182-
if sys.platform in ['win32'] and not self.use_lit_shell:
183-
# Don't pass dosish path separator to msys bash.exe.
184-
clang_dir = clang_dir.replace('\\', '/')
185-
# Ensure the result is an ascii string, across Python2.5+ - Python3.
186-
return clang_dir
187-
188-
def make_itanium_abi_triple(self, triple):
189-
m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
190-
if not m:
191-
self.lit_config.fatal("Could not turn '%s' into Itanium ABI triple" % triple)
192-
if m.group(3).lower() != 'win32':
193-
# All non-win32 triples use the Itanium ABI.
194-
return triple
195-
return m.group(1) + '-' + m.group(2) + '-mingw32'
196-
197-
def make_msabi_triple(self, triple):
198-
m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
199-
if not m:
200-
self.lit_config.fatal("Could not turn '%s' into MS ABI triple" % triple)
201-
isa = m.group(1).lower()
202-
vendor = m.group(2).lower()
203-
os = m.group(3).lower()
204-
if os == 'win32':
205-
# If the OS is win32, we're done.
206-
return triple
207-
if isa.startswith('x86') or isa == 'amd64' or re.match(r'i\d86', isa):
208-
# For x86 ISAs, adjust the OS.
209-
return isa + '-' + vendor + '-win32'
210-
# -win32 is not supported for non-x86 targets; use a default.
211-
return 'i686-pc-win32'
212-
213-
def add_tool_substitutions(self, tools, search_dirs, warn_missing = True):
214-
if lit.util.is_string(search_dirs):
215-
search_dirs = [search_dirs]
216-
217-
search_dirs = os.pathsep.join(search_dirs)
218-
for tool in tools:
219-
# Extract the tool name from the pattern. This relies on the tool
220-
# name being surrounded by \b word match operators. If the
221-
# pattern starts with "| ", include it in the string to be
222-
# substituted.
223-
if lit.util.is_string(tool):
224-
tool = lit.util.make_word_regex(tool)
225-
else:
226-
tool = str(tool)
227-
228-
tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_\.]+)\\b\W*$",
229-
tool)
230-
if not tool_match:
231-
continue
232-
233-
tool_pipe = tool_match.group(2)
234-
tool_name = tool_match.group(4)
235-
tool_path = lit.util.which(tool_name, search_dirs)
236-
if not tool_path:
237-
if warn_missing:
238-
# Warn, but still provide a substitution.
239-
self.lit_config.note('Did not find ' + tool_name + ' in %s' % search_dirs)
240-
tool_path = self.config.llvm_tools_dir + '/' + tool_name
241-
242-
if tool_name == 'llc' and os.environ.get('LLVM_ENABLE_MACHINE_VERIFIER') == '1':
243-
tool_path += ' -verify-machineinstrs'
244-
if tool_name == 'llvm-go':
245-
exe = getattr(self.config, 'go_executable', None)
246-
if exe:
247-
tool_path += " go=" + exe
248-
249-
self.config.substitutions.append((tool, tool_pipe + tool_path))

utils/lit/lit/util.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ def pythonize_bool(value):
3636
return False
3737
raise ValueError('"{}" is not a valid boolean'.format(value))
3838

39-
def make_word_regex(word):
40-
return r'\b' + word + r'\b'
4139

4240
def to_bytes(s):
4341
"""Return the parameter as type 'bytes', possibly encoding it.

0 commit comments

Comments
 (0)