r252514 - Extend linux header search to find libc++ headers in c++/vN for any N.

Evgeniy Stepanov via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 13:10:55 PST 2015


Author: eugenis
Date: Mon Nov  9 15:10:54 2015
New Revision: 252514

URL: http://llvm.org/viewvc/llvm-project?rev=252514&view=rev
Log:
Extend linux header search to find libc++ headers in c++/vN for any N.

Added:
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/bin/
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/bin/.keep
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/v1/
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/v1/.keep
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/v2/
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/v2/.keep
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/lib/
    cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/lib/.keep
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/bin/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/bin/.keep
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/4.8/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/4.8/backward/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/4.8/backward/.keep   (with props)
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/v1/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/v1/.keep
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/v2/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/v2/.keep
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/lib/
    cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/lib/.keep
Modified:
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/test/Driver/linux-header-search.cpp

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=252514&r1=252513&r2=252514&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Nov  9 15:10:54 2015
@@ -3849,6 +3849,25 @@ void Linux::AddClangSystemIncludeArgs(co
 }
 
 
+static std::string DetectLibcxxIncludePath(StringRef base) {
+  std::error_code EC;
+  int MaxVersion = 0;
+  std::string MaxVersionString = "";
+  for (llvm::sys::fs::directory_iterator LI(base, EC), LE; !EC && LI != LE;
+       LI = LI.increment(EC)) {
+    StringRef VersionText = llvm::sys::path::filename(LI->path());
+    int Version;
+    if (VersionText[0] == 'v' &&
+        !VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
+      if (Version > MaxVersion) {
+        MaxVersion = Version;
+        MaxVersionString = VersionText;
+      }
+    }
+  }
+  return MaxVersion ? (base + "/" + MaxVersionString).str() : "";
+}
+
 void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
                                          ArgStringList &CC1Args) const {
   if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
@@ -3858,17 +3877,14 @@ void Linux::AddClangCXXStdlibIncludeArgs
   // Check if libc++ has been enabled and provide its include paths if so.
   if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) {
     const std::string LibCXXIncludePathCandidates[] = {
-        // The primary location is within the Clang installation.
-        // FIXME: We shouldn't hard code 'v1' here to make Clang future proof to
-        // newer ABI versions.
-        getDriver().Dir + "/../include/c++/v1",
+        DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"),
 
         // We also check the system as for a long time this is the only place
         // Clang looked.
         // FIXME: We should really remove this. It doesn't make any sense.
-        getDriver().SysRoot + "/usr/include/c++/v1"};
+        DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++")};
     for (const auto &IncludePath : LibCXXIncludePathCandidates) {
-      if (!getVFS().exists(IncludePath))
+      if (IncludePath.empty() || !getVFS().exists(IncludePath))
         continue;
       // Add the first candidate that exists.
       addSystemInclude(DriverArgs, CC1Args, IncludePath);

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/bin/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/bin/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/v1/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c%2B%2B/v1/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c++/v2/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/c%2B%2B/v2/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/lib/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/lib/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/bin/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/bin/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/4.8/backward/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c%2B%2B/4.8/backward/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Propchange: cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/4.8/backward/.keep
------------------------------------------------------------------------------
    svn:executable = *

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/v1/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c%2B%2B/v1/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c++/v2/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/c%2B%2B/v2/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/lib/.keep
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/lib/.keep?rev=252514&view=auto
==============================================================================
    (empty)

Modified: cfe/trunk/test/Driver/linux-header-search.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-header-search.cpp?rev=252514&r1=252513&r2=252514&view=diff
==============================================================================
--- cfe/trunk/test/Driver/linux-header-search.cpp (original)
+++ cfe/trunk/test/Driver/linux-header-search.cpp Mon Nov  9 15:10:54 2015
@@ -26,6 +26,42 @@
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1"
 // CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
 //
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-unknown-linux-gnu \
+// RUN:     -stdlib=libc++ \
+// RUN:     -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN:     --sysroot=%S/Inputs/basic_linux_libcxxv2_tree \
+// RUN:     --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXXV2-SYSROOT %s
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v2"
+// CHECK-BASIC-LIBCXXV2-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-unknown-linux-gnu \
+// RUN:     -stdlib=libc++ \
+// RUN:     -ccc-install-dir %S/Inputs/basic_linux_libcxxv2_tree/usr/bin \
+// RUN:     --sysroot=%S/Inputs/basic_linux_libcxxv2_tree \
+// RUN:     --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXXV2-INSTALL %s
+// CHECK-BASIC-LIBCXXV2-INSTALL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v2"
+// CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+//
+// Test Linux with both libc++ and libstdc++ installed.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN:     -target x86_64-unknown-linux-gnu \
+// RUN:     -stdlib=libc++ \
+// RUN:     -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN:     --sysroot=%S/Inputs/basic_linux_libstdcxx_libcxxv2_tree \
+// RUN:     --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-LIBCXXV2-SYSROOT %s
+// CHECK-BASIC-LIBSTDCXX-LIBCXXV2-SYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-BASIC-LIBSTDCXX-LIBCXXV2-SYSROOT: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBSTDCXX-LIBCXXV2-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v2"
+// CHECK-BASIC-LIBSTDCXX-LIBCXXV2-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+//
 // Test a very broken version of multiarch that shipped in Ubuntu 11.04.
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN:     -target i386-unknown-linux \




More information about the cfe-commits mailing list