[PATCH] D134454: [Driver][Distro] Fix ArchLinux sysroot detection

Adrian Ratiu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 03:38:00 PDT 2022


10ne1 updated this revision to Diff 463177.
10ne1 retitled this revision from "[Driver][Distro] Fix ArchLinux triplet and sysroot detection" to "[Driver][Distro] Fix ArchLinux sysroot detection".
10ne1 edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134454/new/

https://reviews.llvm.org/D134454

Files:
  clang/include/clang/Driver/Distro.h
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -370,28 +370,30 @@
     return std::string();
   }
 
-  if (!GCCInstallation.isValid() || !getTriple().isMIPS())
+  if (!GCCInstallation.isValid())
     return std::string();
 
-  // Standalone MIPS toolchains use different names for sysroot folder
-  // and put it into different places. Here we try to check some known
-  // variants.
-
+  const Distro Distro(getDriver().getVFS(), getTriple());
   const StringRef InstallDir = GCCInstallation.getInstallPath();
   const StringRef TripleStr = GCCInstallation.getTriple().str();
   const Multilib &Multilib = GCCInstallation.getMultilib();
+  std::string BasePath = (InstallDir + "/../../../../"  + TripleStr).str();
 
-  std::string Path =
-      (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix())
-          .str();
-
-  if (getVFS().exists(Path))
-    return Path;
+  if (Distro.IsArchLinux() && getVFS().exists(BasePath))
+      return BasePath;
 
-  Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str();
+  // Standalone MIPS toolchains use different names for sysroot folder
+  // and put it into different places. Here we try to check some known
+  // variants.
+  if (getTriple().isMIPS()) {
+    std::string Path = BasePath + "/libc" + Multilib.osSuffix();
+    if (getVFS().exists(Path))
+      return Path;
 
-  if (getVFS().exists(Path))
-    return Path;
+    Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str();
+    if (getVFS().exists(Path))
+      return Path;
+  }
 
   return std::string();
 }
Index: clang/include/clang/Driver/Distro.h
===================================================================
--- clang/include/clang/Driver/Distro.h
+++ clang/include/clang/Driver/Distro.h
@@ -134,6 +134,8 @@
 
   bool IsGentoo() const { return DistroVal == Gentoo; }
 
+  bool IsArchLinux() const { return DistroVal == ArchLinux; }
+
   /// @}
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134454.463177.patch
Type: text/x-patch
Size: 2082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220927/bec58f6a/attachment-0001.bin>


More information about the cfe-commits mailing list