Skip to content

Commit 3d2c906

Browse files
jh7370Thomas Preud'homme
authored andcommitted
[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
1 parent c698505 commit 3d2c906

File tree

14 files changed

+24
-10
lines changed

14 files changed

+24
-10
lines changed

llvm/utils/lit/lit/llvm/config.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def use_default_substitutions(self):
402402
self.add_err_msg_substitutions()
403403

404404
def use_llvm_tool(self, name, search_env=None, required=False, quiet=False,
405-
use_installed=False):
405+
search_paths=None, use_installed=False):
406406
"""Find the executable program 'name', optionally using the specified
407407
environment variable as an override before searching the build directory
408408
and then optionally the configuration's PATH."""
@@ -413,8 +413,11 @@ def use_llvm_tool(self, name, search_env=None, required=False, quiet=False,
413413
tool = self.config.environment.get(search_env)
414414

415415
if not tool:
416-
# Use the build directory version.
417-
tool = lit.util.which(name, self.config.llvm_tools_dir)
416+
if search_paths is None:
417+
search_paths = [self.config.llvm_tools_dir]
418+
# Use the specified search paths.
419+
path = os.pathsep.join(search_paths)
420+
tool = lit.util.which(name, path)
418421

419422
if not tool and use_installed:
420423
# Otherwise look in the path, if enabled.
@@ -488,10 +491,10 @@ def use_clang(self, additional_tool_dirs=[], additional_flags=[],
488491
'llvm_shlib_dir',
489492
'llvm_libs_dir',
490493
]
491-
paths = [getattr(self.config, pp) for pp in lib_dir_props
492-
if getattr(self.config, pp, None)]
494+
lib_paths = [getattr(self.config, pp) for pp in lib_dir_props
495+
if getattr(self.config, pp, None)]
493496

494-
self.with_environment('LD_LIBRARY_PATH', paths, append_path=True)
497+
self.with_environment('LD_LIBRARY_PATH', lib_paths, append_path=True)
495498

496499
shl = getattr(self.config, 'llvm_shlib_dir', None)
497500
pext = getattr(self.config, 'llvm_plugin_ext', None)
@@ -503,7 +506,7 @@ def use_clang(self, additional_tool_dirs=[], additional_flags=[],
503506
# Discover the 'clang' and 'clangcc' to use.
504507
self.config.clang = self.use_llvm_tool(
505508
'clang', search_env='CLANG', required=required,
506-
use_installed=use_installed)
509+
search_paths=paths, use_installed=use_installed)
507510
if self.config.clang:
508511
self.config.available_features.add('clang')
509512
builtin_include_dir = self.get_clang_builtin_include_dir(
@@ -595,20 +598,24 @@ def use_lld(self, additional_tool_dirs=[], required=True,
595598

596599
lib_dir_props = [self.config.name.lower() + '_libs_dir',
597600
'lld_libs_dir', 'llvm_libs_dir']
598-
paths = [getattr(self.config, pp) for pp in lib_dir_props
599-
if getattr(self.config, pp, None)]
601+
lib_paths = [getattr(self.config, pp) for pp in lib_dir_props
602+
if getattr(self.config, pp, None)]
600603

601-
self.with_environment('LD_LIBRARY_PATH', paths, append_path=True)
604+
self.with_environment('LD_LIBRARY_PATH', lib_paths, append_path=True)
602605

603606
# Discover the LLD executables to use.
604607

605608
ld_lld = self.use_llvm_tool('ld.lld', required=required,
609+
search_paths=paths,
606610
use_installed=use_installed)
607611
lld_link = self.use_llvm_tool('lld-link', required=required,
612+
search_paths=paths,
608613
use_installed=use_installed)
609614
ld64_lld = self.use_llvm_tool('ld64.lld', required=required,
615+
search_paths=paths,
610616
use_installed=use_installed)
611617
wasm_ld = self.use_llvm_tool('wasm-ld', required=required,
618+
search_paths=paths,
612619
use_installed=use_installed)
613620

614621
was_found = ld_lld and lld_link and ld64_lld and wasm_ld

llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case10

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case10.exe

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case9

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case9.exe

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ lit.llvm.llvm_config.use_llvm_tool('case5')
2020
lit.llvm.llvm_config.use_llvm_tool('case6', search_env='CASE6', use_installed=True)
2121
lit.llvm.llvm_config.use_llvm_tool('case7', use_installed=True)
2222
lit.llvm.llvm_config.use_llvm_tool('case8', use_installed=True)
23+
paths = [os.path.join(this_dir, 'search1'), os.path.join(this_dir, 'search2'), os.path.join(this_dir, 'search3')]
24+
lit.llvm.llvm_config.use_llvm_tool('case9', search_paths=paths)
25+
lit.llvm.llvm_config.use_llvm_tool('case10', search_paths=paths, use_installed=True)

llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case10

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case10.exe

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/search1/empty

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/search2/case9

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/search2/case9.exe

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/search3/case9

Whitespace-only changes.

llvm/utils/lit/tests/Inputs/use-llvm-tool/search3/case9.exe

Whitespace-only changes.

llvm/utils/lit/tests/use-llvm-tool.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
## 6 | / | / | / | <- Env is preferred over build, PATH
1818
## 7 | N/S | / | / | <- Build dir is preferred over PATH
1919
## 8 | X | X | X | <- Say nothing if cannot be found if not required
20+
## 9 | N/S | override | N/S | <- Use specified search directory, instead of default directory
21+
## 10 | N/S | override | / | <- Use PATH if not in search directory
2022

2123
## Check the exact path reported for the first case, but don't bother for the
2224
## others.
@@ -28,6 +30,8 @@
2830
# CHECK-NEXT: note: using case6: {{.*}}env-case6
2931
# CHECK-NEXT: note: using case7: {{.*}}build{{[\\/]}}case7
3032
# CHECK-NOT: case8
33+
# CHECK-NEXT: note: using case9: {{.*}}search2{{[\\/]}}case9
34+
# CHECK-NEXT: note: using case10: {{.*}}path{{[\\/]}}case10
3135

3236
## Test that if required is True, lit errors if the tool is not found.
3337
# RUN: not %{lit} %{inputs}/use-llvm-tool-required 2>&1 | \

0 commit comments

Comments
 (0)