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

llvm-svn: 176894
This commit is contained in:
Jim Grosbach 2013-03-12 20:17:58 +00:00
parent 5ce24ffca2
commit 061dabf7df
2 changed files with 21 additions and 9 deletions

View 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);

View File

@ -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) {}