Skip to content

Commit b62870f

Browse files
rebase
Created using spr 1.3.6
2 parents 5bd8d4f + 9edf549 commit b62870f

File tree

13 files changed

+88
-19
lines changed

13 files changed

+88
-19
lines changed

clang/test/ClangScanDeps/pr61006.cppm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// RUN: mkdir -p %t
77
// RUN: split-file %s %t
88
//
9-
// RUN: EXPECTED_RESOURCE_DIR=`%clang -print-resource-dir` && \
9+
// RUN: %clang -print-resource-dir | tr -d '\n' > %t/resource-dir
10+
// RUN: env EXPECTED_RESOURCE_DIR=%{readfile:%t/resource-dir} && \
1011
// RUN: ln -s %clang++ %t/clang++ && \
1112
// RUN: sed "s|EXPECTED_RESOURCE_DIR|$EXPECTED_RESOURCE_DIR|g; s|DIR|%/t|g" %t/P1689.json.in > %t/P1689.json && \
1213
// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/a.cpp -DPREFIX=%/t && \

clang/test/ClangScanDeps/resource_directory.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// then verify `%clang-scan-deps` arrives at the same path by calling the
1313
// `Driver::GetResourcesPath` function.
1414
//
15-
// RUN: EXPECTED_RESOURCE_DIR=`%clang -print-resource-dir`
15+
// RUN: %clang -print-resource-dir | tr -d '\n' > %t/resource-dir
1616
// RUN: sed -e "s|CLANG|%clang|g" -e "s|DIR|%/t|g" \
1717
// RUN: %S/Inputs/resource_directory/cdb.json.template > %t/cdb_path.json
1818
//
1919
// RUN: clang-scan-deps -compilation-database %t/cdb_path.json --format experimental-full \
2020
// RUN: --resource-dir-recipe modify-compiler-path > %t/result_path.json
2121
// RUN: cat %t/result_path.json | sed 's:\\\\\?:/:g' \
22-
// RUN: | FileCheck %s --check-prefix=CHECK-PATH -DEXPECTED_RESOURCE_DIR="$EXPECTED_RESOURCE_DIR"
22+
// RUN: | FileCheck %s --check-prefix=CHECK-PATH -DEXPECTED_RESOURCE_DIR="%{readfile:%t/resource-dir}"
2323
// CHECK-PATH: "-resource-dir"
2424
// CHECK-PATH-NEXT: "[[EXPECTED_RESOURCE_DIR]]"
2525

@@ -31,16 +31,15 @@
3131
// Here we hard-code the expected path into `%t/compiler` and then verify
3232
// `%clang-scan-deps` arrives at the path by actually running the executable.
3333
//
34-
// RUN: EXPECTED_RESOURCE_DIR="/custom/compiler/resources"
3534
// RUN: echo "#!/bin/sh" > %t/compiler
36-
// RUN: echo "echo '$EXPECTED_RESOURCE_DIR'" >> %t/compiler
35+
// RUN: echo "echo '/custom/compiler/resources'" >> %t/compiler
3736
// RUN: chmod +x %t/compiler
3837
// RUN: sed -e "s|CLANG|%/t/compiler|g" -e "s|DIR|%/t|g" \
3938
// RUN: %S/Inputs/resource_directory/cdb.json.template > %t/cdb_invocation.json
4039
//
4140
// RUN: clang-scan-deps -compilation-database %t/cdb_invocation.json --format experimental-full \
4241
// RUN: --resource-dir-recipe invoke-compiler > %t/result_invocation.json
4342
// RUN: cat %t/result_invocation.json | sed 's:\\\\\?:/:g' \
44-
// RUN: | FileCheck %s --check-prefix=CHECK-PATH -DEXPECTED_RESOURCE_DIR="$EXPECTED_RESOURCE_DIR"
43+
// RUN: | FileCheck %s --check-prefix=CHECK-PATH -DEXPECTED_RESOURCE_DIR="/custom/compiler/resources"
4544
// CHECK-INVOCATION: "-resource-dir"
4645
// CHECK-INVOCATION-NEXT: "[[EXPECTED_RESOURCE_DIR]]"

clang/test/Driver/env.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Some assertions in this test use Linux style (/) file paths.
22
// UNSUPPORTED: system-windows
3+
// RUN: bash -c env | grep LD_LIBRARY_PATH | tr -d '\n' > /tmp/ld_library_path
34
// The PATH variable is heavily used when trying to find a linker.
4-
// RUN: env -i LC_ALL=C LD_LIBRARY_PATH="$LD_LIBRARY_PATH" CLANG_NO_DEFAULT_CONFIG=1 \
5+
// RUN: env -i LC_ALL=C LD_LIBRARY_PATH="%{readfile:/tmp/ld_library_path}" CLANG_NO_DEFAULT_CONFIG=1 \
56
// RUN: %clang %s -### -o %t.o --target=i386-unknown-linux \
67
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
78
// RUN: --rtlib=platform --unwindlib=platform -no-pie \
89
// RUN: 2>&1 | FileCheck --check-prefix=CHECK-LD-32 %s
910
//
10-
// RUN: env -i LC_ALL=C PATH="" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" CLANG_NO_DEFAULT_CONFIG=1 \
11+
// RUN: env -i LC_ALL=C PATH="" LD_LIBRARY_PATH="%{readfile:/tmp/ld_library_path}" CLANG_NO_DEFAULT_CONFIG=1 \
1112
// RUN: %clang %s -### -o %t.o --target=i386-unknown-linux \
1213
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
1314
// RUN: --rtlib=platform --unwindlib=platform -no-pie \

clang/test/Driver/program-path-priority.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787

8888
/// <default-triple>-gcc has lowest priority so <triple>-gcc
8989
/// on PATH beats default triple in program path
90-
// RUN: DEFAULT_TRIPLE=`%t/clang --version | grep "Target:" | cut -d ' ' -f2`
91-
// RUN: touch %t/$DEFAULT_TRIPLE-gcc && chmod +x %t/$DEFAULT_TRIPLE-gcc
90+
// RUN: %t/clang --version | grep "Target:" | cut -d ' ' -f2 > %t.default_triple
91+
// RUN: touch %t/%{readfile:%t.default_triple}-gcc && chmod +x %t/%{readfile:%t.default_triple}-gcc
9292
// RUN: touch %t/%target_triple-gcc && chmod +x %t/%target_triple-gcc
9393
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
9494
// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_GCC %s
@@ -101,7 +101,7 @@
101101
// DEFAULT_TRIPLE_NO_NOTREAL: env/gcc"
102102
// DEFAULT_TRIPLE_NO_NOTREAL-NOT: -gcc"
103103

104-
/// Pick "gcc" as a fallback. Don't pick $DEFAULT_TRIPLE-gcc.
104+
/// Pick "gcc" as a fallback. Don't pick DEFAULT_TRIPLE-gcc.
105105
// RUN: rm %t/env/gcc
106106
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
107107
// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_NO_OTHERS %s
@@ -110,9 +110,9 @@
110110
/// -B paths are searched separately so default triple will win
111111
/// if put in one of those even if other paths have higher priority names
112112
// RUN: mkdir -p %t/prefix
113-
/// One of these will fail when $DEFAULT_TRIPLE == %target_triple
114-
// RUN: test -f %t/$DEFAULT_TRIPLE-gcc && \
115-
// RUN: mv %t/$DEFAULT_TRIPLE-gcc %t/prefix || true
113+
/// One of these will fail when %{readfile:%t.default_triple} == %target_triple
114+
// RUN: test -f %t/%{readfile:%t.default_triple}-gcc && \
115+
// RUN: mv %t/%{readfile:%t.default_triple}-gcc %t/prefix || true
116116
// RUN: test -f %t/%target_triple-gcc && \
117117
// RUN: mv %t/%target_triple-gcc %t/prefix || true
118118
// RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
@@ -123,8 +123,8 @@
123123
// DEFAULT_TRIPLE_IN_PREFIX-NOT: notreal-none-elf-gcc"
124124

125125
/// Only if there is nothing in the prefix will we search other paths
126-
/// -f in case $DEFAULT_TRIPLE == %target_triple
127-
// RUN: rm -f %t/prefix/$DEFAULT_TRIPLE-gcc %t/prefix/%target_triple-gcc %t/prefix/gcc
126+
/// -f in case %{readfile:%t.default_triple} == %target_triple
127+
// RUN: rm -f %t/prefix/%{readfile:%t.default_triple}-gcc %t/prefix/%target_triple-gcc %t/prefix/gcc
128128
// RUN: env "PATH=" %t/clang -### -canonical-prefixes --target=notreal-none-elf %s -B %t/prefix 2>&1 | \
129129
// RUN: FileCheck --check-prefix=EMPTY_PREFIX_DIR1 %s
130130
// EMPTY_PREFIX_DIR1: gcc"

clang/test/Modules/relative-resource-dir.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
2-
// REQUIRES: shell
32

4-
// RUN: EXPECTED_RESOURCE_DIR=`%clang -print-resource-dir` && \
3+
// RUN: %clang -print-resource-dir | tr -d '\n' > %t.resource_dir
4+
// RUN: env EXPECTED_RESOURCE_DIR="%{readfile:%t.resource_dir}" && \
55
// RUN: mkdir -p %t && rm -rf %t/resource-dir && \
6-
// RUN: cp -R $EXPECTED_RESOURCE_DIR %t/resource-dir
6+
// RUN: cp -R %{readfile:%t.resource_dir} %t/resource-dir
77
// RUN: cd %t && %clang -cc1 -x objective-c -fmodules -fmodule-format=obj \
88
// RUN: -fimplicit-module-maps -fmodules-cache-path=%t.mcp \
99
// RUN: -fbuiltin-headers-in-system-modules \

llvm/docs/CommandGuide/lit.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ TestRunner.py:
664664
Otherwise, %t but with a single leading ``/`` removed.
665665
%:T On Windows, %/T but a ``:`` is removed if its the second character.
666666
Otherwise, %T but with a single leading ``/`` removed.
667+
%{readfile:<filename>} Reads the file specified.
667668
======================= ==============
668669

669670
Other substitutions are provided that are variations on this base set and

llvm/test/tools/llvm-cgdata/empty.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ RUN: printf '\000\000\000\000' >> %t_header.cgdata
3535
RUN: printf '\040\000\000\000\000\000\000\000' >> %t_header.cgdata
3636
RUN: printf '\040\000\000\000\000\000\000\000' >> %t_header.cgdata
3737
RUN: diff %t_header.cgdata %t_emptyheader.cgdata
38+
RUN: echo %{readfile:/tmp/test} > /tmp/test

llvm/utils/lit/lit/TestRunner.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,23 @@ def processRedirects(cmd, stdin_source, cmd_shenv, opened_files):
720720
return std_fds
721721

722722

723+
def _expandLateSubstitutions(arguments, cwd):
724+
for i, arg in enumerate(arguments):
725+
if not isinstance(arg, str):
726+
continue
727+
728+
def _replaceReadFile(match):
729+
filePath = match.group(1)
730+
if not os.path.isabs(filePath):
731+
filePath = os.path.join(cwd, filePath)
732+
with open(filePath) as fileHandle:
733+
return fileHandle.read()
734+
735+
arguments[i] = re.sub(r"%{readfile:([^}]*)}", _replaceReadFile, arg)
736+
737+
return arguments
738+
739+
723740
def _executeShCmd(cmd, shenv, results, timeoutHelper):
724741
if timeoutHelper.timeoutReached():
725742
# Prevent further recursion if the timeout has been hit
@@ -834,6 +851,9 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
834851
# Ensure args[0] is hashable.
835852
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
836853

854+
# Expand all late substitutions
855+
args = _expandLateSubstitutions(args, cmd_shenv.cwd)
856+
837857
inproc_builtin = inproc_builtins.get(args[0], None)
838858
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
839859
# 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 absolute paths
2+
# RUN: echo -n "hello" > %t
3+
# RUN: echo %{readfile:%t}
4+
5+
## Fail the test so we can assert on the output.
6+
# RUN: not echo return
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import lit.formats
2+
3+
config.name = "shtest-readfile"
4+
config.suffixes = [".txt"]
5+
config.test_format = lit.formats.ShTest(execute_external=False)
6+
config.test_source_root = None
7+
config.test_exec_root = None
8+
config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))

0 commit comments

Comments
 (0)