Add the resource directory to the search path for Driver::GetFilePath,

as well as the search path printed by -print-search-dirs.

The main purpose of this change is to cause -print-file-name=include
to print the path to the include directory under Clang's resource
directory, instead of the system compiler's include directory, whose
header files Clang may not be able to parse.  Some build scripts will
do something like:
  $(CC) -nostdinc -I`$(CC) -print-file-name=include`
to exclude all header paths except the compiler's.

llvm-svn: 139127
This commit is contained in:
Peter Collingbourne 2011-09-06 02:08:31 +00:00
parent c4c43fbb07
commit fa9771ffec
1 changed files with 8 additions and 3 deletions

View File

@ -585,7 +585,7 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
llvm::outs() << *it;
}
llvm::outs() << "\n";
llvm::outs() << "libraries: =";
llvm::outs() << "libraries: =" << ResourceDir;
std::string sysroot;
if (Arg *A = C.getArgs().getLastArg(options::OPT__sysroot_EQ))
@ -593,8 +593,7 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
for (ToolChain::path_list::const_iterator it = TC.getFilePaths().begin(),
ie = TC.getFilePaths().end(); it != ie; ++it) {
if (it != TC.getFilePaths().begin())
llvm::outs() << ':';
llvm::outs() << ':';
const char *path = it->c_str();
if (path[0] == '=')
llvm::outs() << sysroot << path + 1;
@ -1428,6 +1427,12 @@ std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const {
return P.str();
}
llvm::sys::Path P(ResourceDir);
P.appendComponent(Name);
bool Exists;
if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
return P.str();
const ToolChain::path_list &List = TC.getFilePaths();
for (ToolChain::path_list::const_iterator
it = List.begin(), ie = List.end(); it != ie; ++it) {