]> granicus.if.org Git - clang/commitdiff
Teach the Linux toolchain about more modern Gentoo installations of GCC
authorChandler Carruth <chandlerc@gmail.com>
Mon, 26 Aug 2013 08:59:53 +0000 (08:59 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 26 Aug 2013 08:59:53 +0000 (08:59 +0000)
which add another wrinkle to the installation of the libstdc++ headers.

Add at least some basic testing of the weirdnesses of Gentoo's layout.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189212 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains.cpp
lib/Driver/ToolChains.h
test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/crtbegin.o [new file with mode: 0644]
test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/.keep [new file with mode: 0644]
test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/x86_64-pc-linux-gnu/lib/.keep [new file with mode: 0644]
test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/crtbegin.o [new file with mode: 0644]
test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/.keep [new file with mode: 0644]
test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/x86_64-pc-linux-gnu/lib/.keep [new file with mode: 0644]
test/Driver/linux-header-search.cpp

index aabcad3c8b547aacdba993b183a37c5d019a3dd3..58847c8aac4e883c2cd183e2ef2c211944d222ef 100644 (file)
@@ -907,17 +907,19 @@ Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args,
 /// This is the primary means of forming GCCVersion objects.
 /*static*/
 Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) {
-  const GCCVersion BadVersion = { VersionText.str(), -1, -1, -1, "" };
+  const GCCVersion BadVersion = { VersionText.str(), -1, -1, -1, "", "", "" };
   std::pair<StringRef, StringRef> First = VersionText.split('.');
   std::pair<StringRef, StringRef> Second = First.second.split('.');
 
-  GCCVersion GoodVersion = { VersionText.str(), -1, -1, -1, "" };
+  GCCVersion GoodVersion = { VersionText.str(), -1, -1, -1, "", "", "" };
   if (First.first.getAsInteger(10, GoodVersion.Major) ||
       GoodVersion.Major < 0)
     return BadVersion;
+  GoodVersion.MajorStr = First.first.str();
   if (Second.first.getAsInteger(10, GoodVersion.Minor) ||
       GoodVersion.Minor < 0)
     return BadVersion;
+  GoodVersion.MinorStr = Second.first.str();
 
   // First look for a number prefix and parse that if present. Otherwise just
   // stash the entire patch string in the suffix, and leave the number
@@ -935,7 +937,7 @@ Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) {
       if (PatchText.slice(0, EndNumber).getAsInteger(10, GoodVersion.Patch) ||
           GoodVersion.Patch < 0)
         return BadVersion;
-      GoodVersion.PatchSuffix = PatchText.substr(EndNumber).str();
+      GoodVersion.PatchSuffix = PatchText.substr(EndNumber);
     }
   }
 
@@ -2578,20 +2580,22 @@ void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
   // equivalent to '/usr/include/c++/X.Y' in almost all cases.
   StringRef LibDir = GCCInstallation.getParentLibPath();
   StringRef InstallDir = GCCInstallation.getInstallPath();
-  StringRef Version = GCCInstallation.getVersion().Text;
   StringRef TripleStr = GCCInstallation.getTriple().str();
+  const GCCVersion &Version = GCCInstallation.getVersion();
 
   if (addLibStdCXXIncludePaths(
-          LibDir.str() + "/../include", "/c++/" + Version.str(), TripleStr,
+          LibDir.str() + "/../include", "/c++/" + Version.Text, TripleStr,
           GCCInstallation.getBiarchSuffix(), DriverArgs, CC1Args))
     return;
 
   const std::string IncludePathCandidates[] = {
     // Gentoo is weird and places its headers inside the GCC install, so if the
-    // first attempt to find the headers fails, try this pattern.
-    InstallDir.str() + "/include/g++-v4",
+    // first attempt to find the headers fails, try these patterns.
+    InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." +
+        Version.MinorStr,
+    InstallDir.str() + "/include/g++-v" + Version.MajorStr,
     // Android standalone toolchain has C++ headers in yet another place.
-    LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.str(),
+    LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,
     // Freescale SDK C++ headers are directly in <sysroot>/usr/include/c++,
     // without a subdirectory corresponding to the gcc version.
     LibDir.str() + "/../include/c++",
index a37cf472ff744debc7edca3267df625b8ff67441..acfcfdf3b85ad031a7cf84d5a72c864f54c2faad 100644 (file)
@@ -50,6 +50,9 @@ protected:
     /// \brief The parsed major, minor, and patch numbers.
     int Major, Minor, Patch;
 
+    /// \brief The text of the parsed major, and major+minor versions.
+    std::string MajorStr, MinorStr;
+
     /// \brief Any textual suffix on the patch number.
     std::string PatchSuffix;
 
diff --git a/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/crtbegin.o b/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/crtbegin.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/.keep b/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/x86_64-pc-linux-gnu/lib/.keep b/test/Driver/Inputs/gentoo_linux_gcc_4.6.2_tree/usr/x86_64-pc-linux-gnu/lib/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/crtbegin.o b/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/crtbegin.o
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/.keep b/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/x86_64-pc-linux-gnu/lib/.keep b/test/Driver/Inputs/gentoo_linux_gcc_4.6.4_tree/usr/x86_64-pc-linux-gnu/lib/.keep
new file mode 100644 (file)
index 0000000..e69de29
index 788694fcbaa104c73aefcf011a9ecad56fbb96a9..8955ed71d3c2c266fab99ff46d5ec2c802391efb 100644 (file)
 // CHECK-DEBIAN-PPC64: "-internal-externc-isystem" "[[SYSROOT]]/usr/include/powerpc64-linux-gnu"
 // CHECK-DEBIAN-PPC64: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-DEBIAN-PPC64: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+//
+// Test Gentoo's weirdness both before and after they changed it in their GCC
+// 4.6.4 release.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-unknown-linux-gnu \
+// RUN:     --sysroot=%S/Inputs/gentoo_linux_gcc_4.6.2_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-6-2 %s
+// CHECK-GENTOO-4-6-2: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-6-2: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/x86_64-pc-linux-gnu"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.2/include/g++-v4/backward"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-6-2: "-internal-isystem" "{{.*}}{{/|\\\\}}lib{{(64|32)?}}{{/|\\\\}}clang{{/|\\\\}}{{[0-9]\.[0-9]}}{{/|\\\\}}include"
+// CHECK-GENTOO-4-6-2: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-6-2: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-unknown-linux-gnu \
+// RUN:     --sysroot=%S/Inputs/gentoo_linux_gcc_4.6.4_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-6-4 %s
+// CHECK-GENTOO-4-6-4: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-6-4: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/x86_64-pc-linux-gnu"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.4/include/g++-v4.6/backward"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-6-4: "-internal-isystem" "{{.*}}{{/|\\\\}}lib{{(64|32)?}}{{/|\\\\}}clang{{/|\\\\}}{{[0-9]\.[0-9]}}{{/|\\\\}}include"
+// CHECK-GENTOO-4-6-4: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-6-4: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"