[lld] r313919 - [lit] Refactor out some more common lit configuration code.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 14:27:32 PDT 2017


Author: zturner
Date: Thu Sep 21 14:27:31 2017
New Revision: 313919

URL: http://llvm.org/viewvc/llvm-project?rev=313919&view=rev
Log:
[lit] Refactor out some more common lit configuration code.

debuginfo-tests has need to reuse a lot of common configuration
from clang and lld, and in general it seems like all of the
projects which are tightly coupled (e.g. lld, clang, llvm, lldb,
etc) can benefit from knowing about one other.  For example,
lldb needs to know various things about how to run clang in its
test suite.  Since there's a lot of common substitutions and
operations that need to be shared among projects, sinking this
up into LLVM makes sense.

In addition, this patch introduces a function add_tool_substitution
which handles all the dirty intricacies of matching tool names
which was previously copied around the various config files.  This
is now a simple straightforward interface which is hard to mess
up.

Differential Revision: https://reviews.llvm.org/D37944

Modified:
    lld/trunk/test/lit.cfg.py

Modified: lld/trunk/test/lit.cfg.py
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/lit.cfg.py?rev=313919&r1=313918&r2=313919&view=diff
==============================================================================
--- lld/trunk/test/lit.cfg.py (original)
+++ lld/trunk/test/lit.cfg.py Thu Sep 21 14:27:31 2017
@@ -10,6 +10,7 @@ import lit.formats
 import lit.util
 
 from lit.llvm import llvm_config
+from lit.llvm import ToolFilter
 
 # Configuration file for the 'lit' test runner.
 
@@ -36,58 +37,30 @@ config.test_source_root = os.path.dirnam
 config.test_exec_root = os.path.join(config.lld_obj_root, 'test')
 
 # Tweak the PATH to include the tools dir and the scripts dir.
-llvm_config.with_environment('PATH', [config.llvm_tools_dir, config.lld_tools_dir], append_path=True)
+llvm_config.with_environment('PATH',
+                             [config.llvm_tools_dir, config.lld_tools_dir], append_path=True)
 
-llvm_config.with_environment('LD_LIBRARY_PATH', [config.lld_libs_dir, config.llvm_libs_dir], append_path=True)
+llvm_config.with_environment('LD_LIBRARY_PATH',
+                             [config.lld_libs_dir, config.llvm_libs_dir], append_path=True)
 
-# For each occurrence of a lld tool name as its own word, replace it
-# with the full path to the build directory holding that tool.  This
-# ensures that we are testing the tools just built and not some random
+# For each occurrence of a clang tool name, replace it with the full path to
+# the build directory holding that tool.  We explicitly specify the directories
+# to search to ensure that we get the tools just built and not some random
 # tools that might happen to be in the user's PATH.
-
-# Regex assertions to reject neighbor hyphens/dots (seen in some tests).
-# For example, we want to prefix 'lld' and 'ld.lld' but not the 'lld' inside
-# of 'ld.lld'.
-NoPreJunk = r"(?<!(-|\.|/))"
-NoPostJunk = r"(?!(-|\.))"
+tool_dirs = [config.lld_tools_dir, config.llvm_tools_dir]
 
 config.substitutions.append( (r"\bld.lld\b", 'ld.lld --full-shutdown') )
 
-tool_patterns = [r"\bFileCheck\b",
-                 r"\bnot\b",
-                 NoPreJunk + r"\blld\b" + NoPostJunk,
-                 r"\bld.lld\b",
-                 r"\blld-link\b",
-                 r"\bllvm-as\b",
-                 r"\bllvm-mc\b",
-                 r"\bllvm-nm\b",
-                 r"\bllvm-objdump\b",
-                 r"\bllvm-pdbutil\b",
-                 r"\bllvm-readobj\b",
-                 r"\bobj2yaml\b",
-                 r"\byaml2obj\b"]
-
-for pattern in tool_patterns:
-    # 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.
-    tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_\.]+)\\b\W*$",
-                          pattern)
-    tool_pipe = tool_match.group(2)
-    tool_name = tool_match.group(4)
-    tool_path = lit.util.which(tool_name, config.environment['PATH'])
-    if not tool_path:
-        # Warn, but still provide a substitution.
-        lit_config.note('Did not find ' + tool_name + ' in ' + path)
-        tool_path = config.llvm_tools_dir + '/' + tool_name
-    config.substitutions.append((pattern, tool_pipe + tool_path))
+tool_patterns = [
+    'FileCheck', 'not', 'ld.lld', 'lld-link', 'llvm-as', 'llvm-mc', 'llvm-nm',
+    'llvm-objdump', 'llvm-pdbutil', 'llvm-readobj', 'obj2yaml', 'yaml2obj',
+    ToolFilter('lld', pre='-.', post='-.')]
+
+llvm_config.add_tool_substitutions(tool_patterns, tool_dirs)
 
 # Add site-specific substitutions.
 config.substitutions.append( ('%python', config.python_executable) )
 
-###
-
 # When running under valgrind, we mangle '-vg' onto the end of the triple so we
 # can check it with XFAIL and XTARGET.
 if lit_config.useValgrind:




More information about the llvm-commits mailing list