summaryrefslogtreecommitdiff
path: root/utils/lit/lit/llvm/config.py
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-10-06 17:54:46 +0000
committerZachary Turner <zturner@google.com>2017-10-06 17:54:46 +0000
commit19ac6f8ea49ce239065d44c6f8f06a8f24859941 (patch)
tree23768f730b0ee5a4f388a7780bcb3c042bd39fc7 /utils/lit/lit/llvm/config.py
parente959bd0e6085525c807b74693251ab474594c352 (diff)
[lit] Improve tool substitution in lit.
This addresses two sources of inconsistency in test configuration files. 1. Substitution boundaries. Previously you would specify a substitution, such as 'lli', and then additionally a set of characters that should fail to match before and after the tool. This was used, for example, so that matches that are parts of full paths would not be replaced. But not all tools did this, and those that did would often re-invent the set of characters themselves, leading to inconsistency. Now, every tool substitution defaults to using a sane set of reasonable defaults and you have to explicitly opt out of it. This actually fixed a few latent bugs that were never being surfaced, but only on accident. 2. There was no standard way for the system to decide how to locate a tool. Sometimes you have an explicit path, sometimes we would search for it and build up a path ourselves, and sometimes we would build up a full command line. Furthermore, there was no standardized way to handle missing tools. Do we warn, fail, ignore, etc? All of this is now encapsulated in the ToolSubst class. You either specify an exact command to run, or an instance of FindTool('<tool-name>') and everything else just works. Furthermore, you can specify an action to take if the tool cannot be resolved. Differential Revision: https://reviews.llvm.org/D38565 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315085 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/lit/lit/llvm/config.py')
-rw-r--r--utils/lit/lit/llvm/config.py68
1 files changed, 38 insertions, 30 deletions
diff --git a/utils/lit/lit/llvm/config.py b/utils/lit/lit/llvm/config.py
index 292b77d3da8..87851b3cb1a 100644
--- a/utils/lit/lit/llvm/config.py
+++ b/utils/lit/lit/llvm/config.py
@@ -5,6 +5,8 @@ import subprocess
import sys
import lit.util
+from lit.llvm.subst import FindTool
+from lit.llvm.subst import ToolSubst
def binary_feature(on, feature, off_prefix):
@@ -225,41 +227,47 @@ class LLVMConfig(object):
# -win32 is not supported for non-x86 targets; use a default.
return 'i686-pc-win32'
- def add_tool_substitutions(self, tools, search_dirs, warn_missing=True):
+ def add_tool_substitutions(self, tools, search_dirs=None):
+ if not search_dirs:
+ search_dirs = [self.config.llvm_tools_dir]
+
if lit.util.is_string(search_dirs):
search_dirs = [search_dirs]
+ tools = [x if isinstance(x, ToolSubst) else ToolSubst(x)
+ for x in tools]
+
search_dirs = os.pathsep.join(search_dirs)
+ substitutions = []
+
for tool in tools:
- # Extract the tool name from the pattern. This relies on the tool
- # name being surrounded by \b word match operators. If the
- # pattern starts with "| ", include it in the string to be
- # substituted.
- if lit.util.is_string(tool):
- tool = lit.util.make_word_regex(tool)
- else:
- tool = str(tool)
+ match = tool.resolve(self, search_dirs)
- tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_\.]+)\\b\W*$",
- tool)
- if not tool_match:
+ # Either no match occurred, or there was an unresolved match that
+ # is ignored.
+ if not match:
continue
- tool_pipe = tool_match.group(2)
- tool_name = tool_match.group(4)
- tool_path = lit.util.which(tool_name, search_dirs)
- if not tool_path:
- if warn_missing:
- # Warn, but still provide a substitution.
- self.lit_config.note(
- 'Did not find ' + tool_name + ' in %s' % search_dirs)
- tool_path = self.config.llvm_tools_dir + '/' + tool_name
-
- if tool_name == 'llc' and os.environ.get('LLVM_ENABLE_MACHINE_VERIFIER') == '1':
- tool_path += ' -verify-machineinstrs'
- if tool_name == 'llvm-go':
- exe = getattr(self.config, 'go_executable', None)
- if exe:
- tool_path += ' go=' + exe
-
- self.config.substitutions.append((tool, tool_pipe + tool_path))
+ subst_key, tool_pipe, command = match
+
+ # An unresolved match occurred that can't be ignored. Fail without
+ # adding any of the previously-discovered substitutions.
+ if not command:
+ return False
+
+ substitutions.append((subst_key, tool_pipe + command))
+
+ self.config.substitutions.extend(substitutions)
+ return True
+
+ def use_default_substitutions(self):
+ tool_patterns = [
+ ToolSubst('FileCheck', unresolved='fatal'),
+ # Handle these specially as they are strings searched for during testing.
+ ToolSubst(r'\| \bcount\b', command=FindTool(
+ 'count'), verbatim=True, unresolved='fatal'),
+ ToolSubst(r'\| \bnot\b', command=FindTool('not'), verbatim=True, unresolved='fatal')]
+
+ self.config.substitutions.append(('%python', sys.executable))
+ self.add_tool_substitutions(
+ tool_patterns, [self.config.llvm_tools_dir])