Skip to content

Commit fe59122

Browse files
committed
[clang][Driver] Fix tool path priority test failures
Summary: Failure type 1: This test can fail when the path of the build includes the strings we're checking for. E.g "/gcc" is found in ".../gcc_7.3.0/..." To correct this look for '"' on the end of all matches. So that we only match the end of paths printed by clang -###. (which would be ".../gcc_7.3.0/.../gcc" for the example) Also look for other gcc names like gcc-x.y.z in the first check. This confirms that the copy of clang we made is isolated as expected. Failure type 2: If you use a triple like "powerpc64le-linux-gnu" clang actually reports "powerpc64le-unknown-linux-gnu". Then it searches for the former. That combined with Mac OS adding a version number to cmake's triple means we can't trust cmake or clang to give us the one default triple. To fix the test, write to both names. As they don't overlap with our fake triple, we're still showing that the lookup works. Reviewers: MaskRay, stevewan Reviewed By: stevewan Subscribers: miyuki, JDevlieghere, steven.zhang, stevewan, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D83055
1 parent 001c78d commit fe59122

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

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

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
/// so only name priority is accounted for, unless we fail to find
1414
/// anything at all in the prefix.
1515

16+
/// Note: All matches are expected to be at the end of file paths.
17+
/// So we match " on the end to account for build systems that
18+
/// put the name of the compiler in the build path.
19+
/// E.g. /build/gcc_X.Y.Z/0/...
20+
1621
/// Symlink clang to a new dir which will be its
1722
/// "program path" for these tests
1823
// RUN: rm -rf %t && mkdir -p %t
@@ -21,89 +26,108 @@
2126
/// No gccs at all, nothing is found
2227
// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
2328
// RUN: FileCheck --check-prefix=NO_NOTREAL_GCC %s
24-
// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc
25-
// NO_NOTREAL_GCC-NOT: /gcc
29+
// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc"
30+
/// Some systems will have "gcc-x.y.z" so for this first check
31+
/// make sure we don't find "gcc" or "gcc-x.y.z". If we do find either
32+
/// then there is no point continuing as this copy of clang is not
33+
/// isolated as we expected.
34+
// NO_NOTREAL_GCC-NOT: {{/gcc[^/]*"}}
2635

2736
/// <triple>-gcc in program path is found
2837
// RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
2938
// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
3039
// RUN: FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s
31-
// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc
40+
// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc"
3241

3342
/// <triple>-gcc on the PATH is found
3443
// RUN: mkdir -p %t/env
3544
// RUN: rm %t/notreal-none-elf-gcc
3645
// RUN: touch %t/env/notreal-none-elf-gcc && chmod +x %t/env/notreal-none-elf-gcc
3746
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
3847
// RUN: FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s
39-
// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc
48+
// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc"
4049

4150
/// <triple>-gcc in program path is preferred to one on the PATH
4251
// RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
4352
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
4453
// RUN: FileCheck --check-prefix=BOTH_NOTREAL_GCC %s
45-
// BOTH_NOTREAL_GCC: notreal-none-elf-gcc
46-
// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc
54+
// BOTH_NOTREAL_GCC: notreal-none-elf-gcc"
55+
// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc"
4756

4857
/// On program path, <triple>-gcc is preferred to plain gcc
4958
// RUN: touch %t/gcc && chmod +x %t/gcc
5059
// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
5160
// RUN: FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s
52-
// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc
53-
// NOTREAL_GCC_PREFERRED-NOT: /gcc
61+
// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc"
62+
// NOTREAL_GCC_PREFERRED-NOT: /gcc"
5463

5564
/// <triple>-gcc on the PATH is preferred to gcc in program path
5665
// RUN: rm %t/notreal-none-elf-gcc
5766
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
5867
// RUN: FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PROG %s
59-
// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc
60-
// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc
68+
// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc"
69+
// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc"
6170

6271
/// <triple>-gcc on the PATH is preferred to gcc on the PATH
6372
// RUN: rm %t/gcc
6473
// RUN: touch %t/env/gcc && chmod +x %t/env/gcc
6574
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
6675
// RUN: FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PATH %s
67-
// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc
68-
// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc
76+
// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc"
77+
// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc"
78+
79+
/// We cannot trust clang --version, or cmake's LLVM_DEFAULT_TARGET_TRIPLE
80+
/// to give us the one and only default triple.
81+
/// Can't trust cmake because on Darwin, triples have a verison appended to them.
82+
/// (and clang uses the versioned string to search)
83+
/// Can't trust --version because it will pad 3 item triples to 4 e.g.
84+
/// powerpc64le-linux-gnu -> powerpc64le-unknown-linux-gnu
85+
/// (and clang uses the former to search)
86+
/// So we write to both names which is a bit odd but still proves that the
87+
/// lookup is working.
6988

7089
/// <default-triple>-gcc has lowest priority so <triple>-gcc
7190
/// on PATH beats default triple in program path
72-
/// Darwin triples have a version appended to them, even if set via
73-
/// LLVM_DEFAULT_TARGET_TRIPLE. So the only way to know for sure is to ask clang.
7491
// RUN: DEFAULT_TRIPLE=`%t/clang --version | grep "Target:" | cut -d ' ' -f2`
7592
// RUN: touch %t/$DEFAULT_TRIPLE-gcc && chmod +x %t/$DEFAULT_TRIPLE-gcc
93+
// RUN: touch %t/%target_triple-gcc && chmod +x %t/%target_triple-gcc
7694
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
7795
// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_GCC %s
78-
// DEFAULT_TRIPLE_GCC: env/notreal-none-elf-gcc
96+
// DEFAULT_TRIPLE_GCC: env/notreal-none-elf-gcc"
7997

8098
/// plain gcc on PATH beats default triple in program path
8199
// RUN: rm %t/env/notreal-none-elf-gcc
82100
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
83101
// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_NO_NOTREAL %s
84-
// DEFAULT_TRIPLE_NO_NOTREAL: env/gcc
85-
// DEFAULT_TRIPLE_NO_NOTREAL-NOT: -gcc
102+
// DEFAULT_TRIPLE_NO_NOTREAL: env/gcc"
103+
// DEFAULT_TRIPLE_NO_NOTREAL-NOT: -gcc"
86104

87105
/// default triple only chosen when no others are present
88106
// RUN: rm %t/env/gcc
89107
// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
90108
// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_NO_OTHERS %s
91-
// DEFAULT_TRIPLE_NO_OTHERS: -gcc
92-
// DEFAULT_TRIPLE_NO_OTHERS-NOT: notreal-none-elf-gcc
93-
// DEFAULT_TRIPLE_NO_OTHERS-NOT: /gcc
109+
// DEFAULT_TRIPLE_NO_OTHERS: -gcc"
110+
// DEFAULT_TRIPLE_NO_OTHERS-NOT: notreal-none-elf-gcc"
111+
// DEFAULT_TRIPLE_NO_OTHERS-NOT: /gcc"
94112

95113
/// -B paths are searched separately so default triple will win
96114
/// if put in one of those even if other paths have higher priority names
97115
// RUN: mkdir -p %t/prefix
98-
// RUN: mv %t/$DEFAULT_TRIPLE-gcc %t/prefix
116+
/// One of these will fail when $DEFAULT_TRIPLE == %target_triple
117+
// RUN: test -f %t/$DEFAULT_TRIPLE-gcc && \
118+
// RUN: mv %t/$DEFAULT_TRIPLE-gcc %t/prefix || true
119+
// RUN: test -f %t/%target_triple-gcc && \
120+
// RUN: mv %t/%target_triple-gcc %t/prefix || true
99121
// RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
100122
// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s -B %t/prefix 2>&1 | \
101123
// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_IN_PREFIX %s
102-
// DEFAULT_TRIPLE_IN_PREFIX: prefix/{{.*}}-gcc
103-
// DEFAULT_TRIPLE_IN_PREFIX-NOT: notreal-none-elf-gcc
124+
// DEFAULT_TRIPLE_IN_PREFIX: prefix/{{.*}}-gcc"
125+
// DEFAULT_TRIPLE_IN_PREFIX-NOT: notreal-none-elf-gcc"
104126

105127
/// Only if there is nothing in the prefix will we search other paths
106-
// RUN: rm %t/prefix/$DEFAULT_TRIPLE-gcc
128+
/// -f in case $DEFAULT_TRIPLE == %target_triple
129+
// RUN: rm -f %t/prefix/$DEFAULT_TRIPLE-gcc
130+
// RUN: rm -f %t/prefix/%target_triple-gcc
107131
// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s -B %t/prefix 2>&1 | \
108132
// RUN: FileCheck --check-prefix=EMPTY_PREFIX_DIR %s
109-
// EMPTY_PREFIX_DIR: notreal-none-elf-gcc
133+
// EMPTY_PREFIX_DIR: notreal-none-elf-gcc"

clang/test/lit.cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
config.substitutions.append(
4747
('%src_include_dir', config.clang_src_dir + '/include'))
4848

49+
config.substitutions.append(
50+
('%target_triple', config.target_triple))
4951

5052
# Propagate path to symbolizer for ASan/MSan.
5153
llvm_config.with_system_environment(

0 commit comments

Comments
 (0)