From: Daniel Dunbar Date: Sat, 7 Nov 2009 04:19:57 +0000 (+0000) Subject: Lift compiler builtin include path logic higher. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=750156aec27f66ddd53bf05bde34f147e73e7769;p=clang Lift compiler builtin include path logic higher. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86334 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index cfef4bf72c..9b6475a46d 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -1052,26 +1052,23 @@ isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"), // Finally, implement the code that groks the options above. // Add the clang headers, which are relative to the clang binary. -void AddClangIncludePaths(const char *Argv0, InitHeaderSearch *Init) { - llvm::sys::Path MainExecutablePath = - llvm::sys::Path::GetMainExecutable(Argv0, - (void*)(intptr_t)AddClangIncludePaths); - if (MainExecutablePath.isEmpty()) - return; - - MainExecutablePath.eraseComponent(); // Remove /clang from foo/bin/clang - MainExecutablePath.eraseComponent(); // Remove /bin from foo/bin - - // Get foo/lib/clang//include - MainExecutablePath.appendComponent("lib"); - MainExecutablePath.appendComponent("clang"); - MainExecutablePath.appendComponent(CLANG_VERSION_STRING); - MainExecutablePath.appendComponent("include"); +std::string GetBuiltinIncludePath(const char *Argv0) { + llvm::sys::Path P = + llvm::sys::Path::GetMainExecutable(Argv0, + (void*)(intptr_t) GetBuiltinIncludePath); + + if (!P.isEmpty()) { + P.eraseComponent(); // Remove /clang from foo/bin/clang + P.eraseComponent(); // Remove /bin from foo/bin + + // Get foo/lib/clang//include + P.appendComponent("lib"); + P.appendComponent("clang"); + P.appendComponent(CLANG_VERSION_STRING); + P.appendComponent("include"); + } - // We pass true to ignore sysroot so that we *always* look for clang headers - // relative to our executable, never relative to -isysroot. - Init->AddPath(MainExecutablePath.c_str(), InitHeaderSearch::System, - false, false, false, true /*ignore sysroot*/); + return P.str(); } /// InitializeIncludePaths - Process the -I options and set them in the @@ -1154,8 +1151,16 @@ void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers, Init.AddDefaultEnvVarPaths(Lang); - if (!nobuiltininc) - AddClangIncludePaths(Argv0, &Init); + if (!nobuiltininc) { + std::string P = GetBuiltinIncludePath(Argv0); + + if (!P.empty()) { + // We pass true to ignore sysroot so that we *always* look for clang + // headers relative to our executable, never relative to -isysroot. + Init.AddPath(P, InitHeaderSearch::System, + false, false, false, true /*ignore sysroot*/); + } + } if (!nostdinc) Init.AddDefaultSystemIncludePaths(Lang, triple);