[PATCH] D42019: [Driver] Set default sysroot for Fuchsia if none is specified

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 12 16:18:06 PST 2018


phosek created this revision.
phosek added a reviewer: mcgrathr.
Herald added a subscriber: cfe-commits.

When sysroot isn't explicitly set, try to use the default location which is <driver path>/../<triple>


Repository:
  rC Clang

https://reviews.llvm.org/D42019

Files:
  lib/Driver/ToolChains/Fuchsia.cpp


Index: lib/Driver/ToolChains/Fuchsia.cpp
===================================================================
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -146,6 +146,12 @@
   return P.str();
 }
 
+static std::string getSysRoot(const Driver &D, llvm::Triple Triple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  llvm::sys::path::append(P, normalizeTriple(Triple));
+  return P.str();
+}
+
 Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
                  const ArgList &Args)
     : ToolChain(D, Triple, Args) {
@@ -157,11 +163,10 @@
   llvm::sys::path::append(P, "lib");
   getFilePaths().push_back(P.str());
 
-  if (!D.SysRoot.empty()) {
-    SmallString<128> P(D.SysRoot);
-    llvm::sys::path::append(P, "lib");
-    getFilePaths().push_back(P.str());
-  }
+  SmallString<128> S(!D.SysRoot.empty() ? D.SysRoot
+                                        : getSysRoot(D, getTriple()));
+  llvm::sys::path::append(S, "lib");
+  getFilePaths().push_back(S.str());
 }
 
 std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList &Args,
@@ -236,11 +241,10 @@
     return;
   }
 
-  if (!D.SysRoot.empty()) {
-    SmallString<128> P(D.SysRoot);
-    llvm::sys::path::append(P, "include");
-    addExternCSystemInclude(DriverArgs, CC1Args, P.str());
-  }
+  SmallString<128> S(!D.SysRoot.empty() ? D.SysRoot
+                                        : getSysRoot(D, getTriple()));
+  llvm::sys::path::append(S, "include");
+  addExternCSystemInclude(DriverArgs, CC1Args, S.str());
 }
 
 void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42019.129727.patch
Type: text/x-patch
Size: 1623 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180113/7054827d/attachment-0001.bin>


More information about the cfe-commits mailing list