Extend -Bprefix functionality and make it closer to gcc. If the "prefix"

is not a directory, Driver::GetProgramPath() routine does not try to append
the program name as a "path component" to it. It just joins the "prefix" with
the program name and checks the resulting path existence.

The patch reviewed by Rafael Espindola.

llvm-svn: 167114
This commit is contained in:
Simon Atanasyan 2012-10-31 12:01:53 +00:00
parent c914ab6e3c
commit 86bdab7468
6 changed files with 35 additions and 6 deletions

View file

@ -1591,12 +1591,19 @@ std::string Driver::GetProgramPath(const char *Name,
// attempting to use this prefix when looking for program paths.
for (Driver::prefix_list::const_iterator it = PrefixDirs.begin(),
ie = PrefixDirs.end(); it != ie; ++it) {
llvm::sys::Path P(*it);
P.appendComponent(TargetSpecificExecutable);
if (P.canExecute()) return P.str();
P.eraseComponent();
P.appendComponent(Name);
if (P.canExecute()) return P.str();
bool IsDirectory;
if (!llvm::sys::fs::is_directory(*it, IsDirectory) && IsDirectory) {
llvm::sys::Path P(*it);
P.appendComponent(TargetSpecificExecutable);
if (P.canExecute()) return P.str();
P.eraseComponent();
P.appendComponent(Name);
if (P.canExecute()) return P.str();
}
else {
llvm::sys::Path P(*it + Name);
if (P.canExecute()) return P.str();
}
}
const ToolChain::path_list &List = TC.getProgramPaths();

22
clang/test/Driver/B-opt.c Normal file
View file

@ -0,0 +1,22 @@
// Check -B driver option.
//
// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
// RUN: -B %S/Inputs/B_opt_tree/dir1 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-B-OPT-TRIPLE %s
// CHECK-B-OPT-TRIPLE: "{{.*}}/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld"
//
// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
// RUN: -B %S/Inputs/B_opt_tree/dir2 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-B-OPT-DIR %s
// CHECK-B-OPT-DIR: "{{.*}}/Inputs/B_opt_tree/dir2/ld"
//
// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
// RUN: -B %S/Inputs/B_opt_tree/dir3/prefix- 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-B-OPT-PREFIX %s
// CHECK-B-OPT-PREFIX: "{{.*}}/Inputs/B_opt_tree/dir3/prefix-ld"
//
// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
// RUN: -B %S/Inputs/B_opt_tree/dir3/prefix- \
// RUN: -B %S/Inputs/B_opt_tree/dir2 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-B-OPT-MULT %s
// CHECK-B-OPT-MULT: "{{.*}}/Inputs/B_opt_tree/dir3/prefix-ld"

View file

View file