]> granicus.if.org Git - clang/commitdiff
Extend -Bprefix functionality and make it closer to gcc. If the "prefix"
authorSimon Atanasyan <satanasyan@mips.com>
Wed, 31 Oct 2012 12:01:53 +0000 (12:01 +0000)
committerSimon Atanasyan <satanasyan@mips.com>
Wed, 31 Oct 2012 12:01:53 +0000 (12:01 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167114 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Driver.cpp
test/Driver/B-opt.c [new file with mode: 0644]
test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld [new file with mode: 0755]
test/Driver/Inputs/B_opt_tree/dir1/ld [new file with mode: 0755]
test/Driver/Inputs/B_opt_tree/dir2/ld [new file with mode: 0755]
test/Driver/Inputs/B_opt_tree/dir3/prefix-ld [new file with mode: 0755]

index eeb59e854dadf0d26005ca55aa455c62034e8029..d71e731f39ce580c9ce375e20e87ffb845cca77c 100644 (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();
diff --git a/test/Driver/B-opt.c b/test/Driver/B-opt.c
new file mode 100644 (file)
index 0000000..a0b9a11
--- /dev/null
@@ -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"
diff --git a/test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld b/test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld
new file mode 100755 (executable)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/B_opt_tree/dir1/ld b/test/Driver/Inputs/B_opt_tree/dir1/ld
new file mode 100755 (executable)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/B_opt_tree/dir2/ld b/test/Driver/Inputs/B_opt_tree/dir2/ld
new file mode 100755 (executable)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/B_opt_tree/dir3/prefix-ld b/test/Driver/Inputs/B_opt_tree/dir3/prefix-ld
new file mode 100755 (executable)
index 0000000..e69de29