Skip to content

Commit 28e98b8

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. Reviewers: pawosm-arm Reviewed By: pawosm-arm Pull Request: llvm#165140
1 parent 6a10d1d commit 28e98b8

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

llvm/utils/lit/lit/TestRunner.py

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

878-
# Expand all late substitutions.
879-
args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
880-
881882
inproc_builtin = inproc_builtins.get(args[0], None)
882883
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
883884
# 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} %{python} -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/Inputs/shtest-readfile/lit.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
1010
config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell)
1111
config.test_source_root = None
1212
config.test_exec_root = None
13+
config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))
1314

1415
# If we are testing with the external shell, remove the fake-externals from
1516
# PATH so that we use mkdir in the tests.

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 {{.*}} -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)