Skip to content

Commit a38794f

Browse files
[Clang] Rewrite tests using subshells to set env variables
Now that we have the %readfile substitution, we can rewrite these tests that were using env variable subshells to write the output of the command into a file and then load it where it is needed using readfile. This does involve one invocation of bash so that we are using the system env binary, which does support redirection into a tool like grep. We already do this in one LLVM test. I'm not happy about needing that, but the more principled way to solve it involves reworking how in-process builtins work within lit. That is something we want to do eventually, but not something that I think should block this patch. Reviewers: cmtice, petrhosek, ilovepi Reviewed By: cmtice, ilovepi Pull Request: #158446
1 parent 9542d0a commit a38794f

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-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: export 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 \

0 commit comments

Comments
 (0)