[PATCH] D101896: [lit] Report tool path from use_llvm_tool if found via env variable

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 5 05:42:17 PDT 2021


jhenderson updated this revision to Diff 343015.
jhenderson marked an inline comment as done.
jhenderson added a comment.

Address review comment and attempt to fix pre-merge check.

There was something odd going on with the slash direction in the `%{inputs}` on the pre-merge bot: despite being a Windows machine, it was using `/` as the path separator in the substitution. This isn't what happens for me locally on my Windows machine. Either way, the new approach uses `%p` which should work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101896/new/

https://reviews.llvm.org/D101896

Files:
  llvm/utils/lit/lit/llvm/config.py
  llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg
  llvm/utils/lit/tests/Inputs/use-tool-search-env/test.tool
  llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt
  llvm/utils/lit/tests/use-tool-search-env.py


Index: llvm/utils/lit/tests/use-tool-search-env.py
===================================================================
--- /dev/null
+++ 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
Index: llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt
@@ -0,0 +1 @@
+# RUN: true
Index: llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg
===================================================================
--- /dev/null
+++ 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')
Index: llvm/utils/lit/lit/llvm/config.py
===================================================================
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -407,13 +407,13 @@
         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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101896.343015.patch
Type: text/x-patch
Size: 2263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210505/3c564da0/attachment.bin>


More information about the llvm-commits mailing list