r176894 - Driver: -ccc-install-dir should affect cc1 -resource-dir

Jim Grosbach grosbach at apple.com
Tue Mar 12 13:17:58 PDT 2013


Author: grosbach
Date: Tue Mar 12 15:17:58 2013
New Revision: 176894

URL: http://llvm.org/viewvc/llvm-project?rev=176894&view=rev
Log:
Driver: -ccc-install-dir should affect cc1 -resource-dir

-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

Added:
    cfe/trunk/test/Driver/resource-dir.cpp
Modified:
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=176894&r1=176893&r2=176894&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Mar 12 15:17:58 2013
@@ -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(Ar
   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);
 

Added: cfe/trunk/test/Driver/resource-dir.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/resource-dir.cpp?rev=176894&view=auto
==============================================================================
--- cfe/trunk/test/Driver/resource-dir.cpp (added)
+++ cfe/trunk/test/Driver/resource-dir.cpp Tue Mar 12 15:17:58 2013
@@ -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) {}





More information about the cfe-commits mailing list