From abe2c906ad4c34d257e63b067fe8514050ea77ff Mon Sep 17 00:00:00 2001 From: James Henderson Date: Wed, 5 May 2021 11:56:46 +0100 Subject: [PATCH] [lit] Report tool path from use_llvm_tool if found via env variable Previously, if the search_env argument was specified, and the tool was found at that location, the path was not reported, unlike other situations when this function was called. Adding the reporting makes the function consistent. Reviewed by: thopre Differential Revision: https://reviews.llvm.org/D101896 --- llvm/utils/lit/lit/llvm/config.py | 8 ++++---- .../lit/tests/Inputs/use-tool-search-env/lit.cfg | 11 +++++++++++ .../lit/tests/Inputs/use-tool-search-env/test.tool | 0 .../lit/tests/Inputs/use-tool-search-env/true.txt | 1 + llvm/utils/lit/tests/use-tool-search-env.py | 7 +++++++ 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg create mode 100644 llvm/utils/lit/tests/Inputs/use-tool-search-env/test.tool create mode 100644 llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt create mode 100644 llvm/utils/lit/tests/use-tool-search-env.py diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py index 386e4ae90201..6ff3cba00f3e 100644 --- a/llvm/utils/lit/lit/llvm/config.py +++ b/llvm/utils/lit/lit/llvm/config.py @@ -407,13 +407,13 @@ class LLVMConfig(object): configuration's PATH.""" # If the override is specified in the environment, use it without # validation. + tool = None if search_env: tool = self.config.environment.get(search_env) - if tool: - return tool - # Otherwise look in the path. - tool = lit.util.which(name, self.config.environment['PATH']) + if not tool: + # Otherwise look in the path. + tool = lit.util.which(name, self.config.environment['PATH']) if required and not tool: message = "couldn't find '{}' program".format(name) diff --git a/llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg b/llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg new file mode 100644 index 000000000000..7e61bb32aafa --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg @@ -0,0 +1,11 @@ +import lit.formats +config.name = 'search-env' +config.suffixes = ['.txt'] +config.test_format = lit.formats.ShTest() +config.test_source_root = None +config.test_exec_root = None +import lit.llvm +lit.llvm.initialize(lit_config, config) +import os.path +lit.llvm.llvm_config.with_environment('TOOL_LOCATION', os.path.dirname(__file__) + '/test.tool') +lit.llvm.llvm_config.use_llvm_tool('test-tool', search_env='TOOL_LOCATION') diff --git a/llvm/utils/lit/tests/Inputs/use-tool-search-env/test.tool b/llvm/utils/lit/tests/Inputs/use-tool-search-env/test.tool new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt b/llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt new file mode 100644 index 000000000000..b80b60b7a279 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt @@ -0,0 +1 @@ +# RUN: true diff --git a/llvm/utils/lit/tests/use-tool-search-env.py b/llvm/utils/lit/tests/use-tool-search-env.py new file mode 100644 index 000000000000..6fe7d3c05828 --- /dev/null +++ b/llvm/utils/lit/tests/use-tool-search-env.py @@ -0,0 +1,7 @@ +## Show that lit reports the path to tools picked up via the use_llvm_tool +## function when the tool is found via an environment variable. + +# RUN: %{lit} %{inputs}/use-tool-search-env 2>&1 | \ +# RUN: FileCheck %s -DDIR=%p + +# CHECK: note: using test-tool: [[DIR]]{{[\\/]}}Inputs{{[\\/]}}use-tool-search-env{{[\\/]}}test.tool