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

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


10ne1 updated this revision to Diff 463189.
10ne1 added a comment.

Fixed some clang-format problems.


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.463189.patch
Type: text/x-patch
Size: 2079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220927/532a2d07/attachment.bin>


More information about the cfe-commits mailing list