]> granicus.if.org Git - clang/commitdiff
Driver: -ccc-install-dir should affect cc1 -resource-dir
authorJim Grosbach <grosbach@apple.com>
Tue, 12 Mar 2013 20:17:58 +0000 (20:17 +0000)
committerJim Grosbach <grosbach@apple.com>
Tue, 12 Mar 2013 20:17:58 +0000 (20:17 +0000)
-ccc-install-dir is supposed to cause the compiler to behave as-if it
were installed in the indicated location. It almost does, but misses
anything that's relying on the resource directory (libc++ header search,
in particular). The resource dir is resolved too early, before command
line args are handled.

The fix is simply to move handling of the resource dir until after we
know if a -ccc-install-dir is present.

rdar://13402696

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

lib/Driver/Driver.cpp
test/Driver/resource-dir.cpp [new file with mode: 0644]

index 652046fce490a47ffb98a0cb6525768eeac8640c..140c8799f192849dd926ebf9c0cd082c15b852c8 100644 (file)
@@ -59,15 +59,6 @@ Driver::Driver(StringRef ClangExecutable,
 
   Name = llvm::sys::path::stem(ClangExecutable);
   Dir  = llvm::sys::path::parent_path(ClangExecutable);
-
-  // Compute the path to the resource directory.
-  StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
-  SmallString<128> P(Dir);
-  if (ClangResourceDir != "")
-    llvm::sys::path::append(P, ClangResourceDir);
-  else
-    llvm::sys::path::append(P, "..", "lib", "clang", CLANG_VERSION_STRING);
-  ResourceDir = P.str();
 }
 
 Driver::~Driver() {
@@ -291,6 +282,17 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
   if (Args->hasArg(options::OPT_nostdlib))
     UseStdLib = false;
 
+  // Compute the path to the resource directory. We used to do this in
+  // Driver::Driver(), but that's not right, as command line args (such as
+  // ccc-install-dir) can change 'Dir'.
+  StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
+  SmallString<128> P(Dir);
+  if (!ClangResourceDir.empty())
+    llvm::sys::path::append(P, ClangResourceDir);
+  else
+    llvm::sys::path::append(P, "..", "lib", "clang", CLANG_VERSION_STRING);
+  ResourceDir = P.str();
+
   // Perform the default argument translations.
   DerivedArgList *TranslatedArgs = TranslateInputArgs(*Args);
 
diff --git a/test/Driver/resource-dir.cpp b/test/Driver/resource-dir.cpp
new file mode 100644 (file)
index 0000000..484d7f5
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: %clang %s -fsyntax-only -### 2> %t.log
+// RUN: FileCheck %s --check-prefix=CHECK-DEFAULT < %t.log
+
+// CHECK-DEFAULT: "-resource-dir" "{{.+}}/../lib/clang/{{.+}}"
+
+// RUN: %clang %s -fsyntax-only -ccc-install-dir /my/install/dir -### 2> %t.log
+// RUN: FileCheck %s --check-prefix=CHECK-INSTALL-DIR < %t.log
+// CHECK-INSTALL-DIR: "-resource-dir" "/my/install/dir/../lib/clang
+
+void foo(void) {}