[clang] ba60dc0 - Revert "[Driver] Move detectLibcxxIncludePath to ToolChain"

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 3 11:23:26 PDT 2020


Author: Nico Weber
Date: 2020-10-03T14:22:53-04:00
New Revision: ba60dc0aa75e86165e260b2c08afafd1c394e95a

URL: https://github.com/llvm/llvm-project/commit/ba60dc0aa75e86165e260b2c08afafd1c394e95a
DIFF: https://github.com/llvm/llvm-project/commit/ba60dc0aa75e86165e260b2c08afafd1c394e95a.diff

LOG: Revert "[Driver] Move detectLibcxxIncludePath to ToolChain"

This reverts commit e25bf2592060e7751f8b14522c97081ce2047175.
Breaks tests on Windows, see comments on https://reviews.llvm.org/D88452

Added: 
    

Modified: 
    clang/include/clang/Driver/ToolChain.h
    clang/lib/Driver/ToolChain.cpp
    clang/lib/Driver/ToolChains/Fuchsia.cpp
    clang/lib/Driver/ToolChains/Gnu.cpp

Removed: 
    clang/test/Driver/Inputs/basic_fuchsia_tree/include/c++/v1/.keep


################################################################################
diff  --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index db4c4a730232..7495e08fe6e6 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -575,9 +575,6 @@ class ToolChain {
   // given compilation arguments.
   virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const;
 
-  // Detect the highest available version of libc++ in base path.
-  virtual std::string detectLibcxxIncludePath(StringRef Base) const;
-
   /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
   /// the include paths to use for the given C++ standard library type.
   virtual void

diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 8e98e3206880..8991216da676 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -924,29 +924,6 @@ void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
   }
 }
 
-std::string ToolChain::detectLibcxxIncludePath(StringRef Base) const {
-  std::error_code EC;
-  int MaxVersion = 0;
-  std::string MaxVersionString;
-  for (llvm::vfs::directory_iterator LI = getVFS().dir_begin(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 = std::string(VersionText);
-      }
-    }
-  }
-  if (!MaxVersion)
-    return "";
-  SmallString<128> P(Base);
-  llvm::sys::path::append(P, MaxVersionString);
-  return std::string(P.str());
-}
-
 void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
                                              ArgStringList &CC1Args) const {
   // Header search paths should be handled by each of the subclasses.

diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index e5f23ee38555..781179be39a3 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -319,8 +319,8 @@ void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {
     SmallString<128> P(getDriver().Dir);
-    llvm::sys::path::append(P, "..", "include", "c++");
-    addSystemInclude(DriverArgs, CC1Args, detectLibcxxIncludePath(P.str()));
+    llvm::sys::path::append(P, "..", "include", "c++", "v1");
+    addSystemInclude(DriverArgs, CC1Args, P.str());
     break;
   }
 

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 3778b6f297ed..f3843685a522 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2877,11 +2877,31 @@ void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
   }
 }
 
+static std::string DetectLibcxxIncludePath(llvm::vfs::FileSystem &vfs,
+                                           StringRef base) {
+  std::error_code EC;
+  int MaxVersion = 0;
+  std::string MaxVersionString;
+  for (llvm::vfs::directory_iterator LI = vfs.dir_begin(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 = std::string(VersionText);
+      }
+    }
+  }
+  return MaxVersion ? (base + "/" + MaxVersionString).str() : "";
+}
+
 void
 Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
                                    llvm::opt::ArgStringList &CC1Args) const {
   auto AddIncludePath = [&](std::string Path) {
-    std::string IncludePath = detectLibcxxIncludePath(Path);
+    std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path);
     if (IncludePath.empty() || !getVFS().exists(IncludePath))
       return false;
     addSystemInclude(DriverArgs, CC1Args, IncludePath);

diff  --git a/clang/test/Driver/Inputs/basic_fuchsia_tree/include/c++/v1/.keep b/clang/test/Driver/Inputs/basic_fuchsia_tree/include/c++/v1/.keep
deleted file mode 100644
index e69de29bb2d1..000000000000


        


More information about the cfe-commits mailing list