thiagomacieira updated this revision to Diff 169152.

https://reviews.llvm.org/D53125

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

Index: unittests/Driver/DistroTest.cpp
===================================================================
--- unittests/Driver/DistroTest.cpp
+++ unittests/Driver/DistroTest.cpp
@@ -302,4 +302,27 @@
   ASSERT_FALSE(ArchLinux.IsDebian());
 }
 
+TEST(DistroTest, DetectClearLinux) {
+  vfs::InMemoryFileSystem ClearLinuxFileSystem;
+  ClearLinuxFileSystem.addFile("/usr/lib/os-release", 0,
+      llvm::MemoryBuffer::getMemBuffer("NAME=\"Clear Linux OS\"\n"
+                                       "VERSION=1\n"
+                                       "ID=clear-linux-os\n"
+                                       "VERSION_ID=25530\n"
+                                       "PRETTY_NAME=\"Clear Linux OS\"\n"
+                                       "ANSI_COLOR=\"1;35\"\n"
+                                       "HOME_URL=\"https://clearlinux.org\"\n";
+                                       "SUPPORT_URL=\"https://clearlinux.org\"\n";
+                                       "BUG_REPORT_URL=\"mailto:d...@lists.clearlinux.org\"\n"
+                                       "PRIVACY_POLICY_URL=\"http://www.intel.com/privacy\"\n";));
+
+  Distro ClearLinux{ClearLinuxFileSystem};
+  ASSERT_EQ(Distro(Distro::ClearLinux), ClearLinux);
+  ASSERT_TRUE(ClearLinux.IsClearLinux());
+  ASSERT_FALSE(ClearLinux.IsUbuntu());
+  ASSERT_FALSE(ClearLinux.IsRedhat());
+  ASSERT_FALSE(ClearLinux.IsOpenSUSE());
+  ASSERT_FALSE(ClearLinux.IsDebian());
+}
+
 } // end anonymous namespace
Index: lib/Driver/ToolChains/Linux.cpp
===================================================================
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -229,16 +229,19 @@
 
   Distro Distro(D.getVFS());
 
-  if (Distro.IsAlpineLinux()) {
+  if (Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
     ExtraOpts.push_back("-z");
     ExtraOpts.push_back("now");
   }
 
-  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux()) {
+  if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() || Distro.IsClearLinux()) {
     ExtraOpts.push_back("-z");
     ExtraOpts.push_back("relro");
   }
 
+  if (Distro.IsClearLinux())
+    ExtraOpts.push_back("--copy-dt-needed-entries");
+
   if (GCCInstallation.getParentLibPath().find("opt/rh/devtoolset") !=
       StringRef::npos)
     // With devtoolset on RHEL, we want to add a bin directory that is relative
@@ -283,7 +286,7 @@
   ExtraOpts.push_back("--build-id");
 #endif
 
-  if (IsAndroid || Distro.IsOpenSUSE())
+  if (IsAndroid || Distro.IsOpenSUSE() || Distro.IsClearLinux())
     ExtraOpts.push_back("--enable-new-dtags");
 
   // The selection of paths to try here is designed to match the patterns which
Index: lib/Driver/Distro.cpp
===================================================================
--- lib/Driver/Distro.cpp
+++ lib/Driver/Distro.cpp
@@ -136,6 +136,19 @@
   if (VFS.exists("/etc/arch-release"))
     return Distro::ArchLinux;
 
+  File = VFS.getBufferForFile("/usr/lib/os-release");
+  if (File) {
+    StringRef Data = File.get()->getBuffer();
+    SmallVector<StringRef, 16> Lines;
+    Data.split(Lines, "\n");
+    Distro::DistroType Version = Distro::UnknownDistro;
+    for (StringRef Line : Lines)
+      if (Version == Distro::UnknownDistro && Line.startswith("ID="))
+        Version = llvm::StringSwitch<Distro::DistroType>(Line.substr(3))
+                      .Case("clear-linux-os", Distro::ClearLinux);
+    return Version;
+  }
+
   return Distro::UnknownDistro;
 }
 
Index: include/clang/Driver/Distro.h
===================================================================
--- include/clang/Driver/Distro.h
+++ include/clang/Driver/Distro.h
@@ -28,6 +28,7 @@
     // the first and last known member in the family, e.g. IsRedHat().
     AlpineLinux,
     ArchLinux,
+    ClearLinux,
     DebianLenny,
     DebianSqueeze,
     DebianWheezy,
@@ -122,6 +123,10 @@
     return DistroVal == AlpineLinux;
   }
 
+  bool IsClearLinux() const {
+    return DistroVal == ClearLinux;
+  }
+
   /// @}
 };
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to