r350027 - [Distro] Support detecting Gentoo

Michal Gorny via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 23 07:07:20 PST 2018


Author: mgorny
Date: Sun Dec 23 07:07:19 2018
New Revision: 350027

URL: http://llvm.org/viewvc/llvm-project?rev=350027&view=rev
Log:
[Distro] Support detecting Gentoo

Add support for distinguishing plain Gentoo distribution, and a unit
test for it.  This is going to be used to introduce distro-specific
customizations in the driver code; most notably, it is going to be used
to disable -faddrsig.

Differential Revision: https://reviews.llvm.org/D56024

Modified:
    cfe/trunk/include/clang/Driver/Distro.h
    cfe/trunk/lib/Driver/Distro.cpp
    cfe/trunk/unittests/Driver/DistroTest.cpp

Modified: cfe/trunk/include/clang/Driver/Distro.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Distro.h?rev=350027&r1=350026&r2=350027&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Distro.h (original)
+++ cfe/trunk/include/clang/Driver/Distro.h Sun Dec 23 07:07:19 2018
@@ -39,6 +39,7 @@ public:
     RHEL6,
     RHEL7,
     Fedora,
+    Gentoo,
     OpenSUSE,
     UbuntuHardy,
     UbuntuIntrepid,
@@ -123,6 +124,10 @@ public:
     return DistroVal == AlpineLinux;
   }
 
+  bool IsGentoo() const {
+    return DistroVal == Gentoo;
+  }
+
   /// @}
 };
 

Modified: cfe/trunk/lib/Driver/Distro.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Distro.cpp?rev=350027&r1=350026&r2=350027&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Distro.cpp (original)
+++ cfe/trunk/lib/Driver/Distro.cpp Sun Dec 23 07:07:19 2018
@@ -138,6 +138,9 @@ static Distro::DistroType DetectDistro(l
   if (VFS.exists("/etc/arch-release"))
     return Distro::ArchLinux;
 
+  if (VFS.exists("/etc/gentoo-release"))
+    return Distro::Gentoo;
+
   return Distro::UnknownDistro;
 }
 

Modified: cfe/trunk/unittests/Driver/DistroTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Driver/DistroTest.cpp?rev=350027&r1=350026&r2=350027&view=diff
==============================================================================
--- cfe/trunk/unittests/Driver/DistroTest.cpp (original)
+++ cfe/trunk/unittests/Driver/DistroTest.cpp Sun Dec 23 07:07:19 2018
@@ -51,6 +51,7 @@ TEST(DistroTest, DetectUbuntu) {
   ASSERT_FALSE(UbuntuTrusty.IsRedhat());
   ASSERT_FALSE(UbuntuTrusty.IsOpenSUSE());
   ASSERT_FALSE(UbuntuTrusty.IsDebian());
+  ASSERT_FALSE(UbuntuTrusty.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem UbuntuYakketyFileSystem;
   UbuntuYakketyFileSystem.addFile("/etc/debian_version", 0,
@@ -80,6 +81,7 @@ TEST(DistroTest, DetectUbuntu) {
   ASSERT_FALSE(UbuntuYakkety.IsRedhat());
   ASSERT_FALSE(UbuntuYakkety.IsOpenSUSE());
   ASSERT_FALSE(UbuntuYakkety.IsDebian());
+  ASSERT_FALSE(UbuntuYakkety.IsGentoo());
 }
 
 TEST(DistroTest, DetectRedhat) {
@@ -114,6 +116,7 @@ TEST(DistroTest, DetectRedhat) {
   ASSERT_TRUE(Fedora25.IsRedhat());
   ASSERT_FALSE(Fedora25.IsOpenSUSE());
   ASSERT_FALSE(Fedora25.IsDebian());
+  ASSERT_FALSE(Fedora25.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem CentOS7FileSystem;
   CentOS7FileSystem.addFile("/etc/system-release-cpe", 0,
@@ -150,6 +153,7 @@ TEST(DistroTest, DetectRedhat) {
   ASSERT_TRUE(CentOS7.IsRedhat());
   ASSERT_FALSE(CentOS7.IsOpenSUSE());
   ASSERT_FALSE(CentOS7.IsDebian());
+  ASSERT_FALSE(CentOS7.IsGentoo());
 }
 
 TEST(DistroTest, DetectOpenSUSE) {
@@ -177,6 +181,7 @@ TEST(DistroTest, DetectOpenSUSE) {
   ASSERT_FALSE(OpenSUSELeap421.IsRedhat());
   ASSERT_TRUE(OpenSUSELeap421.IsOpenSUSE());
   ASSERT_FALSE(OpenSUSELeap421.IsDebian());
+  ASSERT_FALSE(OpenSUSELeap421.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem OpenSUSE132FileSystem;
   OpenSUSE132FileSystem.addFile("/etc/SuSE-release", 0,
@@ -202,6 +207,7 @@ TEST(DistroTest, DetectOpenSUSE) {
   ASSERT_FALSE(OpenSUSE132.IsRedhat());
   ASSERT_TRUE(OpenSUSE132.IsOpenSUSE());
   ASSERT_FALSE(OpenSUSE132.IsDebian());
+  ASSERT_FALSE(OpenSUSE132.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem SLES10FileSystem;
   SLES10FileSystem.addFile("/etc/SuSE-release", 0,
@@ -218,6 +224,7 @@ TEST(DistroTest, DetectOpenSUSE) {
   ASSERT_FALSE(SLES10.IsRedhat());
   ASSERT_FALSE(SLES10.IsOpenSUSE());
   ASSERT_FALSE(SLES10.IsDebian());
+  ASSERT_FALSE(SLES10.IsGentoo());
 }
 
 TEST(DistroTest, DetectDebian) {
@@ -240,6 +247,7 @@ TEST(DistroTest, DetectDebian) {
   ASSERT_FALSE(DebianJessie.IsRedhat());
   ASSERT_FALSE(DebianJessie.IsOpenSUSE());
   ASSERT_TRUE(DebianJessie.IsDebian());
+  ASSERT_FALSE(DebianJessie.IsGentoo());
 
   llvm::vfs::InMemoryFileSystem DebianStretchSidFileSystem;
   DebianStretchSidFileSystem.addFile("/etc/debian_version", 0,
@@ -258,6 +266,7 @@ TEST(DistroTest, DetectDebian) {
   ASSERT_FALSE(DebianStretchSid.IsRedhat());
   ASSERT_FALSE(DebianStretchSid.IsOpenSUSE());
   ASSERT_TRUE(DebianStretchSid.IsDebian());
+  ASSERT_FALSE(DebianStretchSid.IsGentoo());
 }
 
 TEST(DistroTest, DetectExherbo) {
@@ -279,6 +288,7 @@ TEST(DistroTest, DetectExherbo) {
   ASSERT_FALSE(Exherbo.IsRedhat());
   ASSERT_FALSE(Exherbo.IsOpenSUSE());
   ASSERT_FALSE(Exherbo.IsDebian());
+  ASSERT_FALSE(Exherbo.IsGentoo());
 }
 
 TEST(DistroTest, DetectArchLinux) {
@@ -300,6 +310,32 @@ TEST(DistroTest, DetectArchLinux) {
   ASSERT_FALSE(ArchLinux.IsRedhat());
   ASSERT_FALSE(ArchLinux.IsOpenSUSE());
   ASSERT_FALSE(ArchLinux.IsDebian());
+  ASSERT_FALSE(ArchLinux.IsGentoo());
+}
+
+TEST(DistroTest, DetectGentoo) {
+  llvm::vfs::InMemoryFileSystem GentooFileSystem;
+  GentooFileSystem.addFile(
+      "/etc/gentoo-release", 0,
+      llvm::MemoryBuffer::getMemBuffer("Gentoo Base System release 2.6"));
+  GentooFileSystem.addFile(
+      "/etc/os-release", 0,
+      llvm::MemoryBuffer::getMemBuffer(
+          "NAME=Gentoo\n"
+          "ID=gentoo\n"
+          "PRETTY_NAME=\"Gentoo/Linux\"\n"
+          "ANSI_COLOR=\"1;32\"\n"
+          "HOME_URL=\"https://www.gentoo.org/\"\n"
+          "SUPPORT_URL=\"https://www.gentoo.org/support/\"\n"
+          "BUG_REPORT_URL=\"https://bugs.gentoo.org/\"\n"));
+
+  Distro Gentoo{GentooFileSystem};
+  ASSERT_EQ(Distro(Distro::Gentoo), Gentoo);
+  ASSERT_FALSE(Gentoo.IsUbuntu());
+  ASSERT_FALSE(Gentoo.IsRedhat());
+  ASSERT_FALSE(Gentoo.IsOpenSUSE());
+  ASSERT_FALSE(Gentoo.IsDebian());
+  ASSERT_TRUE(Gentoo.IsGentoo());
 }
 
 } // end anonymous namespace




More information about the cfe-commits mailing list