1d6efc981SDavid Spickett /// Don't create symlinks on Windows 2d6efc981SDavid Spickett // UNSUPPORTED: system-windows 3d6efc981SDavid Spickett 4d6efc981SDavid Spickett /// Check the priority used when searching for tools 5d6efc981SDavid Spickett /// Names and locations are usually in this order: 6*8ac5e440SFangrui Song /// <triple>-tool, tool, program path, PATH 7d6efc981SDavid Spickett /// (from highest to lowest priority) 8d6efc981SDavid Spickett /// A higher priority name found in a lower priority 9d6efc981SDavid Spickett /// location will win over a lower priority name in a 10d6efc981SDavid Spickett /// higher priority location. 11d6efc981SDavid Spickett /// Prefix dirs (added with -B) override the location, 12d6efc981SDavid Spickett /// so only name priority is accounted for, unless we fail to find 13d6efc981SDavid Spickett /// anything at all in the prefix. 14d6efc981SDavid Spickett 15fe591224SDavid Spickett /// Note: All matches are expected to be at the end of file paths. 16fe591224SDavid Spickett /// So we match " on the end to account for build systems that 17fe591224SDavid Spickett /// put the name of the compiler in the build path. 18fe591224SDavid Spickett /// E.g. /build/gcc_X.Y.Z/0/... 19fe591224SDavid Spickett 20d6efc981SDavid Spickett /// Symlink clang to a new dir which will be its 21d6efc981SDavid Spickett /// "program path" for these tests 22d6efc981SDavid Spickett // RUN: rm -rf %t && mkdir -p %t 23d6efc981SDavid Spickett // RUN: ln -s %clang %t/clang 24d6efc981SDavid Spickett 25d6efc981SDavid Spickett /// No gccs at all, nothing is found 26d6efc981SDavid Spickett // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 27d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=NO_NOTREAL_GCC %s 28fe591224SDavid Spickett // NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc" 29fe591224SDavid Spickett /// Some systems will have "gcc-x.y.z" so for this first check 30fe591224SDavid Spickett /// make sure we don't find "gcc" or "gcc-x.y.z". If we do find either 31fe591224SDavid Spickett /// then there is no point continuing as this copy of clang is not 32fe591224SDavid Spickett /// isolated as we expected. 33fe591224SDavid Spickett // NO_NOTREAL_GCC-NOT: {{/gcc[^/]*"}} 34d6efc981SDavid Spickett 35d6efc981SDavid Spickett /// <triple>-gcc in program path is found 36d6efc981SDavid Spickett // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc 37d6efc981SDavid Spickett // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 38d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s 39fe591224SDavid Spickett // PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc" 40d6efc981SDavid Spickett 41d6efc981SDavid Spickett /// <triple>-gcc on the PATH is found 42d6efc981SDavid Spickett // RUN: mkdir -p %t/env 43d6efc981SDavid Spickett // RUN: rm %t/notreal-none-elf-gcc 44d6efc981SDavid Spickett // RUN: touch %t/env/notreal-none-elf-gcc && chmod +x %t/env/notreal-none-elf-gcc 45d6efc981SDavid Spickett // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 46d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s 47fe591224SDavid Spickett // ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc" 48d6efc981SDavid Spickett 49d6efc981SDavid Spickett /// <triple>-gcc in program path is preferred to one on the PATH 50d6efc981SDavid Spickett // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc 51d6efc981SDavid Spickett // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 52d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=BOTH_NOTREAL_GCC %s 53fe591224SDavid Spickett // BOTH_NOTREAL_GCC: notreal-none-elf-gcc" 54fe591224SDavid Spickett // BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc" 55d6efc981SDavid Spickett 56d6efc981SDavid Spickett /// On program path, <triple>-gcc is preferred to plain gcc 57d6efc981SDavid Spickett // RUN: touch %t/gcc && chmod +x %t/gcc 58d6efc981SDavid Spickett // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 59d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s 60fe591224SDavid Spickett // NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc" 61fe591224SDavid Spickett // NOTREAL_GCC_PREFERRED-NOT: /gcc" 62d6efc981SDavid Spickett 63d6efc981SDavid Spickett /// <triple>-gcc on the PATH is preferred to gcc in program path 64d6efc981SDavid Spickett // RUN: rm %t/notreal-none-elf-gcc 65d6efc981SDavid Spickett // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 66d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PROG %s 67fe591224SDavid Spickett // NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc" 68fe591224SDavid Spickett // NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc" 69d6efc981SDavid Spickett 70d6efc981SDavid Spickett /// <triple>-gcc on the PATH is preferred to gcc on the PATH 71d6efc981SDavid Spickett // RUN: rm %t/gcc 72d6efc981SDavid Spickett // RUN: touch %t/env/gcc && chmod +x %t/env/gcc 73d6efc981SDavid Spickett // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 74d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PATH %s 75fe591224SDavid Spickett // NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc" 76fe591224SDavid Spickett // NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc" 77fe591224SDavid Spickett 78fe591224SDavid Spickett /// We cannot trust clang --version, or cmake's LLVM_DEFAULT_TARGET_TRIPLE 79fe591224SDavid Spickett /// to give us the one and only default triple. 80fe591224SDavid Spickett /// Can't trust cmake because on Darwin, triples have a verison appended to them. 81fe591224SDavid Spickett /// (and clang uses the versioned string to search) 82fe591224SDavid Spickett /// Can't trust --version because it will pad 3 item triples to 4 e.g. 83fe591224SDavid Spickett /// powerpc64le-linux-gnu -> powerpc64le-unknown-linux-gnu 84fe591224SDavid Spickett /// (and clang uses the former to search) 85fe591224SDavid Spickett /// So we write to both names which is a bit odd but still proves that the 86fe591224SDavid Spickett /// lookup is working. 87d6efc981SDavid Spickett 88d6efc981SDavid Spickett /// <default-triple>-gcc has lowest priority so <triple>-gcc 89d6efc981SDavid Spickett /// on PATH beats default triple in program path 90d6efc981SDavid Spickett // RUN: DEFAULT_TRIPLE=`%t/clang --version | grep "Target:" | cut -d ' ' -f2` 91d6efc981SDavid Spickett // RUN: touch %t/$DEFAULT_TRIPLE-gcc && chmod +x %t/$DEFAULT_TRIPLE-gcc 92fe591224SDavid Spickett // RUN: touch %t/%target_triple-gcc && chmod +x %t/%target_triple-gcc 93d6efc981SDavid Spickett // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 94d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_GCC %s 95fe591224SDavid Spickett // DEFAULT_TRIPLE_GCC: env/notreal-none-elf-gcc" 96d6efc981SDavid Spickett 97d6efc981SDavid Spickett /// plain gcc on PATH beats default triple in program path 98d6efc981SDavid Spickett // RUN: rm %t/env/notreal-none-elf-gcc 99d6efc981SDavid Spickett // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 100d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_NO_NOTREAL %s 101fe591224SDavid Spickett // DEFAULT_TRIPLE_NO_NOTREAL: env/gcc" 102fe591224SDavid Spickett // DEFAULT_TRIPLE_NO_NOTREAL-NOT: -gcc" 103d6efc981SDavid Spickett 104*8ac5e440SFangrui Song /// Pick "gcc" as a fallback. Don't pick $DEFAULT_TRIPLE-gcc. 105d6efc981SDavid Spickett // RUN: rm %t/env/gcc 106d6efc981SDavid Spickett // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \ 107d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_NO_OTHERS %s 108*8ac5e440SFangrui Song // DEFAULT_TRIPLE_NO_OTHERS: "gcc" 109d6efc981SDavid Spickett 110d6efc981SDavid Spickett /// -B paths are searched separately so default triple will win 111d6efc981SDavid Spickett /// if put in one of those even if other paths have higher priority names 112d6efc981SDavid Spickett // RUN: mkdir -p %t/prefix 113fe591224SDavid Spickett /// One of these will fail when $DEFAULT_TRIPLE == %target_triple 114fe591224SDavid Spickett // RUN: test -f %t/$DEFAULT_TRIPLE-gcc && \ 115fe591224SDavid Spickett // RUN: mv %t/$DEFAULT_TRIPLE-gcc %t/prefix || true 116fe591224SDavid Spickett // RUN: test -f %t/%target_triple-gcc && \ 117fe591224SDavid Spickett // RUN: mv %t/%target_triple-gcc %t/prefix || true 118d6efc981SDavid Spickett // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc 1193452a0d8SFangrui Song // RUN: touch %t/prefix/gcc && chmod +x %t/prefix/gcc 120d6efc981SDavid Spickett // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s -B %t/prefix 2>&1 | \ 121d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_IN_PREFIX %s 1223452a0d8SFangrui Song // DEFAULT_TRIPLE_IN_PREFIX: prefix/gcc" 123fe591224SDavid Spickett // DEFAULT_TRIPLE_IN_PREFIX-NOT: notreal-none-elf-gcc" 124d6efc981SDavid Spickett 125d6efc981SDavid Spickett /// Only if there is nothing in the prefix will we search other paths 126fe591224SDavid Spickett /// -f in case $DEFAULT_TRIPLE == %target_triple 1273452a0d8SFangrui Song // RUN: rm -f %t/prefix/$DEFAULT_TRIPLE-gcc %t/prefix/%target_triple-gcc %t/prefix/gcc 128d6efc981SDavid Spickett // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s -B %t/prefix 2>&1 | \ 129d6efc981SDavid Spickett // RUN: FileCheck --check-prefix=EMPTY_PREFIX_DIR %s 130fe591224SDavid Spickett // EMPTY_PREFIX_DIR: notreal-none-elf-gcc" 131