1 /// Don't create symlinks on Windows
2 // UNSUPPORTED: system-windows
3 
4 /// Check the priority used when searching for tools
5 /// Names and locations are usually in this order:
6 /// <triple>-tool, tool, <default triple>-tool
7 /// program path, PATH
8 /// (from highest to lowest priority)
9 /// A higher priority name found in a lower priority
10 /// location will win over a lower priority name in a
11 /// higher priority location.
12 /// Prefix dirs (added with -B) override the location,
13 /// so only name priority is accounted for, unless we fail to find
14 /// anything at all in the prefix.
15 
16 /// Symlink clang to a new dir which will be its
17 /// "program path" for these tests
18 // RUN: rm -rf %t && mkdir -p %t
19 // RUN: ln -s %clang %t/clang
20 
21 /// No gccs at all, nothing is found
22 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
23 // RUN:   FileCheck --check-prefix=NO_NOTREAL_GCC %s
24 // NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc
25 // NO_NOTREAL_GCC-NOT: /gcc
26 
27 /// <triple>-gcc in program path is found
28 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
29 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
30 // RUN:   FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s
31 // PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc
32 
33 /// <triple>-gcc on the PATH is found
34 // RUN: mkdir -p %t/env
35 // RUN: rm %t/notreal-none-elf-gcc
36 // RUN: touch %t/env/notreal-none-elf-gcc && chmod +x %t/env/notreal-none-elf-gcc
37 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
38 // RUN:   FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s
39 // ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc
40 
41 /// <triple>-gcc in program path is preferred to one on the PATH
42 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
43 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
44 // 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
47 
48 /// On program path, <triple>-gcc is preferred to plain gcc
49 // RUN: touch %t/gcc && chmod +x %t/gcc
50 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
51 // RUN:   FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s
52 // NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc
53 // NOTREAL_GCC_PREFERRED-NOT: /gcc
54 
55 /// <triple>-gcc on the PATH is preferred to gcc in program path
56 // RUN: rm %t/notreal-none-elf-gcc
57 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
58 // 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
61 
62 /// <triple>-gcc on the PATH is preferred to gcc on the PATH
63 // RUN: rm %t/gcc
64 // RUN: touch %t/env/gcc && chmod +x %t/env/gcc
65 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
66 // 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
69 
70 /// <default-triple>-gcc has lowest priority so <triple>-gcc
71 /// 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.
74 // RUN: DEFAULT_TRIPLE=`%t/clang --version | grep "Target:" | cut -d ' ' -f2`
75 // RUN: touch %t/$DEFAULT_TRIPLE-gcc && chmod +x %t/$DEFAULT_TRIPLE-gcc
76 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
77 // RUN:   FileCheck --check-prefix=DEFAULT_TRIPLE_GCC %s
78 // DEFAULT_TRIPLE_GCC: env/notreal-none-elf-gcc
79 
80 /// plain gcc on PATH beats default triple in program path
81 // RUN: rm %t/env/notreal-none-elf-gcc
82 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
83 // RUN:   FileCheck --check-prefix=DEFAULT_TRIPLE_NO_NOTREAL %s
84 // DEFAULT_TRIPLE_NO_NOTREAL: env/gcc
85 // DEFAULT_TRIPLE_NO_NOTREAL-NOT: -gcc
86 
87 /// default triple only chosen when no others are present
88 // RUN: rm %t/env/gcc
89 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
90 // 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
94 
95 /// -B paths are searched separately so default triple will win
96 /// if put in one of those even if other paths have higher priority names
97 // RUN: mkdir -p %t/prefix
98 // RUN: mv %t/$DEFAULT_TRIPLE-gcc %t/prefix
99 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
100 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s -B %t/prefix 2>&1 | \
101 // 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
104 
105 /// Only if there is nothing in the prefix will we search other paths
106 // RUN: rm %t/prefix/$DEFAULT_TRIPLE-gcc
107 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s -B %t/prefix 2>&1 | \
108 // RUN:   FileCheck --check-prefix=EMPTY_PREFIX_DIR %s
109 // EMPTY_PREFIX_DIR: notreal-none-elf-gcc
110