134 lines · c
1/// Don't create symlinks on Windows2// UNSUPPORTED: system-windows, system-cygwin3 4/// Check the priority used when searching for tools5/// Names and locations are usually in this order:6/// <triple>-tool, tool, program path, PATH7/// (from highest to lowest priority)8/// A higher priority name found in a lower priority9/// location will win over a lower priority name in a10/// higher priority location.11/// Prefix dirs (added with -B) override the location,12/// so only name priority is accounted for, unless we fail to find13/// anything at all in the prefix.14 15/// Note: All matches are expected to be at the end of file paths.16/// So we match " on the end to account for build systems that17/// put the name of the compiler in the build path.18/// E.g. /build/gcc_X.Y.Z/0/...19 20/// Symlink clang to a new dir which will be its21/// "program path" for these tests22// RUN: rm -rf %t && mkdir -p %t23// RUN: ln -s %clang %t/clang24 25/// No gccs at all, nothing is found26// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \27// RUN: FileCheck --check-prefix=NO_NOTREAL_GCC %s28// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc"29/// Some systems will have "gcc-x.y.z" so for this first check30/// make sure we don't find "gcc" or "gcc-x.y.z". If we do find either31/// then there is no point continuing as this copy of clang is not32/// isolated as we expected.33// NO_NOTREAL_GCC-NOT: {{/gcc[^/]*"}}34 35/// <triple>-gcc in program path is found36// RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc37// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \38// RUN: FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s39// PROG_PATH_NOTREAL_GCC: notreal-none-unknown-elf40 41/// <triple>-gcc on the PATH is found42// RUN: mkdir -p %t/env43// RUN: rm %t/notreal-none-elf-gcc44// RUN: touch %t/env/notreal-none-elf-gcc && chmod +x %t/env/notreal-none-elf-gcc45// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \46// RUN: FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s47// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc"48 49/// <triple>-gcc in program path is preferred to one on the PATH50// RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc51// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \52// RUN: FileCheck --check-prefix=BOTH_NOTREAL_GCC %s53// BOTH_NOTREAL_GCC: notreal-none-elf-gcc"54// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc"55 56/// On program path, <triple>-gcc is preferred to plain gcc57// RUN: touch %t/gcc && chmod +x %t/gcc58// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \59// RUN: FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s60// NOTREAL_GCC_PREFERRED: notreal-none-unknown-elf"61// NOTREAL_GCC_PREFERRED-NOT: /gcc"62 63/// <triple>-gcc on the PATH is preferred to gcc in program path64// RUN: rm %t/notreal-none-elf-gcc65// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \66// RUN: FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PROG %s67// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc"68// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc"69 70/// <triple>-gcc on the PATH is preferred to gcc on the PATH71// RUN: rm %t/gcc72// RUN: touch %t/env/gcc && chmod +x %t/env/gcc73// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \74// RUN: FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PATH %s75// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc"76// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc"77 78/// We cannot trust clang --version, or cmake's LLVM_DEFAULT_TARGET_TRIPLE79/// to give us the one and only default triple.80/// Can't trust cmake because on Darwin, triples have a verison appended to them.81/// (and clang uses the versioned string to search)82/// Can't trust --version because it will pad 3 item triples to 4 e.g.83/// powerpc64le-linux-gnu -> powerpc64le-unknown-linux-gnu84/// (and clang uses the former to search)85/// So we write to both names which is a bit odd but still proves that the86/// lookup is working.87 88/// <default-triple>-gcc has lowest priority so <triple>-gcc89/// on PATH beats default triple in program path90// RUN: %t/clang --version | grep "Target:" | cut -d ' ' -f2 > %t.default_triple91// RUN: touch %t/%{readfile:%t.default_triple}-gcc && chmod +x %t/%{readfile:%t.default_triple}-gcc92// RUN: touch %t/%target_triple-gcc && chmod +x %t/%target_triple-gcc93// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \94// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_GCC %s95// DEFAULT_TRIPLE_GCC: env/notreal-none-elf-gcc"96 97/// plain gcc on PATH beats default triple in program path98// RUN: rm %t/env/notreal-none-elf-gcc99// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \100// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_NO_NOTREAL %s101// DEFAULT_TRIPLE_NO_NOTREAL: env/gcc"102// DEFAULT_TRIPLE_NO_NOTREAL-NOT: -gcc"103 104/// Pick "gcc" as a fallback. Don't pick DEFAULT_TRIPLE-gcc.105// RUN: rm %t/env/gcc106// RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \107// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_NO_OTHERS %s108// DEFAULT_TRIPLE_NO_OTHERS: "gcc"109 110/// -B paths are searched separately so default triple will win111/// if put in one of those even if other paths have higher priority names112// RUN: mkdir -p %t/prefix113/// One of these will fail when %{readfile:%t.default_triple} == %target_triple114// RUN: test -f %t/%{readfile:%t.default_triple}-gcc && \115// RUN: mv %t/%{readfile:%t.default_triple}-gcc %t/prefix || true116// RUN: test -f %t/%target_triple-gcc && \117// RUN: mv %t/%target_triple-gcc %t/prefix || true118// RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc119// RUN: touch %t/prefix/gcc && chmod +x %t/prefix/gcc120// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s -B %t/prefix 2>&1 | \121// RUN: FileCheck --check-prefix=DEFAULT_TRIPLE_IN_PREFIX %s122// DEFAULT_TRIPLE_IN_PREFIX: prefix/gcc"123// DEFAULT_TRIPLE_IN_PREFIX-NOT: notreal-none-elf-gcc"124 125/// Only if there is nothing in the prefix will we search other paths126/// -f in case %{readfile:%t.default_triple} == %target_triple127// RUN: rm -f %t/prefix/%{readfile:%t.default_triple}-gcc %t/prefix/%target_triple-gcc %t/prefix/gcc128// RUN: env "PATH=" %t/clang -### -canonical-prefixes --target=notreal-none-elf %s -B %t/prefix 2>&1 | \129// RUN: FileCheck --check-prefix=EMPTY_PREFIX_DIR1 %s130// EMPTY_PREFIX_DIR1: gcc"131// RUN: env "PATH=" %t/clang -### -no-canonical-prefixes --target=notreal-none-elf %s -B %t/prefix 2>&1 | \132// RUN: FileCheck --check-prefix=EMPTY_PREFIX_DIR2 %s133// EMPTY_PREFIX_DIR2: notreal-none-elf-gcc"134