[llvm] 3d2c906 - [lit] Fix testing of standalone clang and lld builds

Thomas Preud'homme via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 3 05:57:31 PDT 2021


Author: James Henderson
Date: 2021-06-03T13:57:50+01:00
New Revision: 3d2c9069dcafd0cbb641841aa3dd6e851fb7d760

URL: https://github.com/llvm/llvm-project/commit/3d2c9069dcafd0cbb641841aa3dd6e851fb7d760
DIFF: https://github.com/llvm/llvm-project/commit/3d2c9069dcafd0cbb641841aa3dd6e851fb7d760.diff

LOG: [lit] Fix testing of standalone clang and lld builds

In such cases, the executables are not in the llvm_tools_dir directory, so we need to look in the other search locations. Previously, they were found via the PATH, but this was disabled by default in commit rGa1e6565.

Depends on D103154.

Reviewed By: thopre

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

Added: 
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case10
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case10.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case9
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case9.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case10
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case10.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/search1/empty
    llvm/utils/lit/tests/Inputs/use-llvm-tool/search2/case9
    llvm/utils/lit/tests/Inputs/use-llvm-tool/search2/case9.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/search3/case9
    llvm/utils/lit/tests/Inputs/use-llvm-tool/search3/case9.exe

Modified: 
    llvm/utils/lit/lit/llvm/config.py
    llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg
    llvm/utils/lit/tests/use-llvm-tool.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py
index bb4d57c75aaa..7bc4b445b75e 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -402,7 +402,7 @@ def use_default_substitutions(self):
         self.add_err_msg_substitutions()
 
     def use_llvm_tool(self, name, search_env=None, required=False, quiet=False,
-                      use_installed=False):
+                      search_paths=None, use_installed=False):
         """Find the executable program 'name', optionally using the specified
         environment variable as an override before searching the build directory
         and then optionally the configuration's PATH."""
@@ -413,8 +413,11 @@ def use_llvm_tool(self, name, search_env=None, required=False, quiet=False,
             tool = self.config.environment.get(search_env)
 
         if not tool:
-            # Use the build directory version.
-            tool = lit.util.which(name, self.config.llvm_tools_dir)
+            if search_paths is None:
+                search_paths = [self.config.llvm_tools_dir]
+            # Use the specified search paths.
+            path = os.pathsep.join(search_paths)
+            tool = lit.util.which(name, path)
 
         if not tool and use_installed:
             # Otherwise look in the path, if enabled.
@@ -488,10 +491,10 @@ def use_clang(self, additional_tool_dirs=[], additional_flags=[],
             'llvm_shlib_dir',
             'llvm_libs_dir',
             ]
-        paths = [getattr(self.config, pp) for pp in lib_dir_props
-                 if getattr(self.config, pp, None)]
+        lib_paths = [getattr(self.config, pp) for pp in lib_dir_props
+                     if getattr(self.config, pp, None)]
 
-        self.with_environment('LD_LIBRARY_PATH', paths, append_path=True)
+        self.with_environment('LD_LIBRARY_PATH', lib_paths, append_path=True)
 
         shl = getattr(self.config, 'llvm_shlib_dir', None)
         pext = getattr(self.config, 'llvm_plugin_ext', None)
@@ -503,7 +506,7 @@ def use_clang(self, additional_tool_dirs=[], additional_flags=[],
         # Discover the 'clang' and 'clangcc' to use.
         self.config.clang = self.use_llvm_tool(
             'clang', search_env='CLANG', required=required,
-            use_installed=use_installed)
+            search_paths=paths, use_installed=use_installed)
         if self.config.clang:
           self.config.available_features.add('clang')
           builtin_include_dir = self.get_clang_builtin_include_dir(
@@ -595,20 +598,24 @@ def use_lld(self, additional_tool_dirs=[], required=True,
 
         lib_dir_props = [self.config.name.lower() + '_libs_dir',
                          'lld_libs_dir', 'llvm_libs_dir']
-        paths = [getattr(self.config, pp) for pp in lib_dir_props
-                 if getattr(self.config, pp, None)]
+        lib_paths = [getattr(self.config, pp) for pp in lib_dir_props
+                     if getattr(self.config, pp, None)]
 
-        self.with_environment('LD_LIBRARY_PATH', paths, append_path=True)
+        self.with_environment('LD_LIBRARY_PATH', lib_paths, append_path=True)
 
         # Discover the LLD executables to use.
 
         ld_lld = self.use_llvm_tool('ld.lld', required=required,
+                                    search_paths=paths,
                                     use_installed=use_installed)
         lld_link = self.use_llvm_tool('lld-link', required=required,
+                                      search_paths=paths,
                                       use_installed=use_installed)
         ld64_lld = self.use_llvm_tool('ld64.lld', required=required,
+                                      search_paths=paths,
                                       use_installed=use_installed)
         wasm_ld = self.use_llvm_tool('wasm-ld', required=required,
+                                     search_paths=paths,
                                      use_installed=use_installed)
 
         was_found = ld_lld and lld_link and ld64_lld and wasm_ld

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case10 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case10
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case10.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case10.exe
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case9 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case9
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case9.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case9.exe
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg b/llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg
index 7c2263c68cd5..2bd401aacde3 100644
--- a/llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg
+++ b/llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg
@@ -20,3 +20,6 @@ lit.llvm.llvm_config.use_llvm_tool('case5')
 lit.llvm.llvm_config.use_llvm_tool('case6', search_env='CASE6', use_installed=True)
 lit.llvm.llvm_config.use_llvm_tool('case7', use_installed=True)
 lit.llvm.llvm_config.use_llvm_tool('case8', use_installed=True)
+paths = [os.path.join(this_dir, 'search1'), os.path.join(this_dir, 'search2'), os.path.join(this_dir, 'search3')]
+lit.llvm.llvm_config.use_llvm_tool('case9', search_paths=paths)
+lit.llvm.llvm_config.use_llvm_tool('case10', search_paths=paths, use_installed=True)

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case10 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case10
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case10.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case10.exe
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/search1/empty b/llvm/utils/lit/tests/Inputs/use-llvm-tool/search1/empty
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/search2/case9 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/search2/case9
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/search2/case9.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/search2/case9.exe
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/search3/case9 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/search3/case9
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/search3/case9.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/search3/case9.exe
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/llvm/utils/lit/tests/use-llvm-tool.py b/llvm/utils/lit/tests/use-llvm-tool.py
index c1eb496254fc..3e190a3e40f7 100644
--- a/llvm/utils/lit/tests/use-llvm-tool.py
+++ b/llvm/utils/lit/tests/use-llvm-tool.py
@@ -17,6 +17,8 @@
 ##   6  |  /  |     /     |   /  | <- Env is preferred over build, PATH
 ##   7  | N/S |     /     |   /  | <- Build dir is preferred over PATH
 ##   8  |  X  |     X     |   X  | <- Say nothing if cannot be found if not required
+##   9  | N/S |  override |  N/S | <- Use specified search directory, instead of default directory
+##  10  | N/S |  override |   /  | <- Use PATH if not in search directory
 
 ## Check the exact path reported for the first case, but don't bother for the
 ## others.
@@ -28,6 +30,8 @@
 # CHECK-NEXT: note: using case6: {{.*}}env-case6
 # CHECK-NEXT: note: using case7: {{.*}}build{{[\\/]}}case7
 # CHECK-NOT:  case8
+# CHECK-NEXT: note: using case9: {{.*}}search2{{[\\/]}}case9
+# CHECK-NEXT: note: using case10: {{.*}}path{{[\\/]}}case10
 
 ## Test that if required is True, lit errors if the tool is not found.
 # RUN: not %{lit} %{inputs}/use-llvm-tool-required 2>&1 | \


        


More information about the llvm-commits mailing list