Skip to content

Commit 30c2af6

Browse files
[lit] Expand late substitutions before running builtins
This enables the use of readfile substitutions for populating environment variables. This is necessary in some compiler-rt tests. Pull Request: llvm#165140
1 parent 7387863 commit 30c2af6

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
825825
not_args = []
826826
not_count = 0
827827
not_crash = False
828+
829+
# Expand all late substitutions.
830+
args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
831+
828832
while True:
829833
if args[0] == "env":
830834
# Create a copy of the global environment and modify it for
@@ -874,9 +878,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
874878
# Ensure args[0] is hashable.
875879
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
876880

877-
# Expand all late substitutions.
878-
args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
879-
880881
inproc_builtin = inproc_builtins.get(args[0], None)
881882
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
882883
# env calling an in-process builtin is useless, so we take the safe
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Tests that readfile works with the env builtin.
2+
# RUN: echo -n "hello" > %t.1
3+
# RUN: env TEST=%{readfile:%t.1} python3 -c "import os; print(os.environ['TEST'])"
4+
5+
## Fail the test so we can assert on the output.
6+
# RUN: not echo return

llvm/utils/lit/tests/shtest-readfile-external.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# UNSUPPORTED: system-windows
77
# RUN: env LIT_USE_INTERNAL_SHELL=0 not %{lit} -a -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S/Inputs/shtest-readfile/Output %s
88

9-
# CHECK: -- Testing: 4 tests{{.*}}
9+
# CHECK: -- Testing: 5 tests{{.*}}
1010

1111
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}})
1212
# CHECK: echo $(cat [[TEMP_PATH]]/absolute-paths.txt.tmp) && test -e [[TEMP_PATH]]/absolute-paths.txt.tmp {{.*}}

llvm/utils/lit/tests/shtest-readfile.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
# RUN: env LIT_USE_INTERNAL_SHELL=1 not %{lit} -a -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S%{fs-sep}Inputs%{fs-sep}shtest-readfile%{fs-sep}Output %s
77

8-
# CHECK: -- Testing: 4 tests{{.*}}
8+
# CHECK: -- Testing: 5 tests{{.*}}
99

1010
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}})
1111
# CHECK: echo hello
1212
# CHECK: # executed command: echo '%{readfile:[[TEMP_PATH]]{{[\\\/]}}absolute-paths.txt.tmp}'
1313

14+
# CHECK-LABEL: FAIL: shtest-readfile :: env.txt ({{[^)]*}})
15+
# CHECK: env TEST=hello python3 -c "import os; print(os.environ['TEST'])"
16+
# CHECK: # | hello
17+
1418
# CHECK-LABEL: FAIL: shtest-readfile :: file-does-not-exist.txt ({{[^)]*}})
1519
# CHECK: # executed command: @echo 'echo %{readfile:/file/does/not/exist}'
1620
# CHECK: # | File specified in readfile substitution does not exist: {{.*}}/file/does/not/exist

0 commit comments

Comments
 (0)