[cfe-commits] r86334 - /cfe/trunk/tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Fri Nov 6 20:19:57 PST 2009


Author: ddunbar
Date: Fri Nov  6 22:19:57 2009
New Revision: 86334

URL: http://llvm.org/viewvc/llvm-project?rev=86334&view=rev
Log:
Lift compiler builtin include path logic higher.

Modified:
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86334&r1=86333&r2=86334&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Fri Nov  6 22:19:57 2009
@@ -1052,26 +1052,23 @@
 // 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
+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/<version>/include
+    P.appendComponent("lib");
+    P.appendComponent("clang");
+    P.appendComponent(CLANG_VERSION_STRING);
+    P.appendComponent("include");
+  }
 
-  // Get foo/lib/clang/<version>/include
-  MainExecutablePath.appendComponent("lib");
-  MainExecutablePath.appendComponent("clang");
-  MainExecutablePath.appendComponent(CLANG_VERSION_STRING);
-  MainExecutablePath.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 @@
 
   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);





More information about the cfe-commits mailing list