-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lit] Fix to make "RUN: env PATH=..." work as intended #165308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a bug in llvm-lit related to setting PATH using env in the internal shell. The new PATH wasn't used when looking up the command to be executed. So when doing things like this in a test case RUN: mkdir %t RUN: env PATH=%t program ... the internal shell would search for "program" using the orignal PATH and not the PATH set by env when preceeding the command. It seems like this was a simple mistake in commit 57782ef, since the logic to pick a PATH from the cmd_shenv instead of shenv actually was added in that patch, but the resulting path wasn't used.
|
@llvm/pr-subscribers-testing-tools Author: Björn Pettersson (bjope) ChangesThere was a bug in llvm-lit related to setting PATH using env in the internal shell. The new PATH wasn't used when looking up the command to be executed. So when doing things like this in a test case It seems like this was a simple mistake in commit 57782ef, since the logic to pick a PATH from the cmd_shenv instead of shenv actually was added in that patch, but the resulting path wasn't used. Full diff: https://github.com/llvm/llvm-project/pull/165308.diff 1 Files Affected:
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index f88314547bb3f..9fba96a1471a0 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -945,7 +945,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
path = (
cmd_shenv.env["PATH"] if "PATH" in cmd_shenv.env else shenv.env["PATH"]
)
- executable = lit.util.which(args[0], shenv.env["PATH"])
+ executable = lit.util.which(args[0], path)
if not executable:
raise InternalShellError(j, "%r: command not found" % args[0])
|
|
I spent some time trying to figure out how to make a nice regression test for this. But I'm not quite sure how to. |
boomanaiden154
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(or find ways to limit it to Linux or something).
I would try to see if it "just works", at least on premerge CI. If something breaks, you can split it out into a separate test file (see the shtest-ulimit-nondarwin.py/shtest-ulimit.py for an example of the split).
| # Use the path from cmd_shenv by default, but if the environment variable | ||
| # is unset (like if the user is using env -i), use the standard path. | ||
| path = ( | ||
| cmd_shenv.env["PATH"] if "PATH" in cmd_shenv.env else shenv.env["PATH"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure using the parent env is correct, if PATH is not set it looks like bash and zsh use a default value.
env -i bash -c 'echo $PATH; printenv'
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.
PWD=/usr/local/google/home/alexrichardson
SHLVL=0
_=/usr/bin/printenv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I also thought that it looked a bit weird to use the parent env in case of env -i.
The goal with this patch is to fix the case when PATH actually is set to something, and then use the correct env when looking up the executable. So I haven't really considered the scenario when PATH is unset in cmd_shenv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree that handling the PATH is unset case in the same way as a "real" shell shouldn't matter too much - I was just curious to see what happens if you do that. Using the parent env instead of some shell-dependent hardcoded value seems fine to me (or we just use the bash value of /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.).
|
|
||
| # The test is using /bin/sh. Limit to system known to have /bin/sh. | ||
| # REQUIRED: system-linux | ||
| # REQUIRES: system-linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have quite a few tests that have this requires even though they should also work on other systems such as freebsd. Should it be the following instead?
| # REQUIRES: system-linux | |
| # UNSUPPORTED: system-windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt a bit uncomfortable with using UNSUPPORTED as I do not know how many different systems there are. So I enabled it for the only system I can test on myself and made sure the pre-commit tests would pass.
I could of course enable it speculatively and then someone need to update this when buildbots starts failing, although I won't really be able to do that for the rest of this week since I'll be out-of-office for some days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is perhaps REQUIRES: shell more appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is perhaps
REQUIRES: shellmore appropriate?
Sorry. That is about using the lit internal shell or not. So that wouldn't fit for checking if /bin/sh exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this is not about the behaviour of PATH but rather because the script needs a shell interpreter. I think we could make this work on windows too by using test.py instead of test.sh
arichardson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to run this test on all platforms but otherwise all looks good
| @@ -0,0 +1,4 @@ | |||
| #!/bin/sh | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would making this a python script allow it to work on windows and avoid the /bin/sh dependency? This should be testable in pre-commit ci so you wouldn't need a windows system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about using python, but couldn't find a good way to make it work. The only executable that is in PATH is test.py itself, so python isn't in the PATH. That is why I though /bin/sh could be assumed to always exist in supported linux installations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about using python, but couldn't find a good way to make it work. The only executable that is in PATH is test.py itself, so python isn't in the PATH. That is why I though /bin/sh could be assumed to always exist in supported linux installations.
Ah yes that is awkward, we'd have to generate a script with #!{sys.executable} but that might not work on windows. So probably best to keep as-is
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/29879 Here is the relevant piece of the build log for the reference |
There was a bug in llvm-lit related to setting PATH using env in the internal shell. The new PATH wasn't used when looking up the command to be executed. So when doing things like this in a test case RUN: mkdir %t RUN: env PATH=%t program ... the internal shell would search for "program" using the orignal PATH and not the PATH set by env when preceeding the command. It seems like this was a simple mistake in commit 57782ef, since the logic to pick a PATH from the cmd_shenv instead of shenv actually was added in that patch, but the resulting path wasn't used.
There was a bug in llvm-lit related to setting PATH using env in the internal shell. The new PATH wasn't used when looking up the command to be executed. So when doing things like this in a test case RUN: mkdir %t RUN: env PATH=%t program ... the internal shell would search for "program" using the orignal PATH and not the PATH set by env when preceeding the command. It seems like this was a simple mistake in commit 57782ef, since the logic to pick a PATH from the cmd_shenv instead of shenv actually was added in that patch, but the resulting path wasn't used.
There was a bug in llvm-lit related to setting PATH using env in the internal shell. The new PATH wasn't used when looking up the command to be executed. So when doing things like this in a test case RUN: mkdir %t RUN: env PATH=%t program ... the internal shell would search for "program" using the orignal PATH and not the PATH set by env when preceeding the command. It seems like this was a simple mistake in commit 57782ef, since the logic to pick a PATH from the cmd_shenv instead of shenv actually was added in that patch, but the resulting path wasn't used.
There was a bug in llvm-lit related to setting PATH using env in the internal shell.
The new PATH wasn't used when looking up the command to be executed. So when doing things like this in a test case
RUN: mkdir %t
RUN: env PATH=%t program ...
the internal shell would search for "program" using the orignal PATH and not the PATH set by env when preceeding the command.
It seems like this was a simple mistake in commit 57782ef, since the logic to pick a PATH from the cmd_shenv instead of shenv actually was added in that patch, but the resulting path wasn't used.