[cfe-commits] r153413 - /cfe/trunk/lib/Frontend/InitHeaderSearch.cpp

NAKAMURA Takumi geek4civic at gmail.com
Sun Mar 25 14:38:25 PDT 2012


Nikola,

It broke cygwin. Consider the case that distro contains multiple
version of g++ headers, esp, "known as bad" version.

/usr/lib/gcc/i686-pc-cygwin/3.4.4
/usr/lib/gcc/i686-pc-cygwin/4.5.3

...Takumi

2012/3/26 Aaron Ballman <aaron at aaronballman.com>:
> Author: aaronballman
> Date: Sun Mar 25 10:47:41 2012
> New Revision: 153413
>
> URL: http://llvm.org/viewvc/llvm-project?rev=153413&view=rev
> Log:
> No longer hard coding paths to the MinGW include directories; using a regular expression instead.
>
> Patch thanks to Nikola Smiljanic
>
> Modified:
>    cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
>
> Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=153413&r1=153412&r2=153413&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
> +++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Sun Mar 25 10:47:41 2012
> @@ -24,7 +24,9 @@
>  #include "llvm/ADT/Twine.h"
>  #include "llvm/Support/raw_ostream.h"
>  #include "llvm/Support/ErrorHandling.h"
> +#include "llvm/Support/FileSystem.h"
>  #include "llvm/Support/Path.h"
> +#include "llvm/Support/Regex.h"
>
>  #include "clang/Config/config.h" // C_INCLUDE_DIRS
>
> @@ -64,17 +66,17 @@
>                                    StringRef Dir32,
>                                    StringRef Dir64,
>                                    const llvm::Triple &triple);
> +
> +  /// AddMinGWCIncludePaths - Add MinGW paths that should always be searched
> +  void AddMinGWCIncludePaths(StringRef Base);
>
>   /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
>   ///  libstdc++.
> -  void AddMinGWCPlusPlusIncludePaths(StringRef Base,
> -                                     StringRef Arch,
> -                                     StringRef Version);
> +  void AddMinGWCPlusPlusIncludePaths(StringRef Base, StringRef Arch);
>
>   /// AddMinGW64CXXPaths - Add the necessary paths to support
>   /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
> -  void AddMinGW64CXXPaths(StringRef Base,
> -                          StringRef Version);
> +  void AddMinGW64CXXPaths(StringRef Base);
>
>   // AddDefaultCIncludePaths - Add paths that should always be searched.
>   void AddDefaultCIncludePaths(const llvm::Triple &triple,
> @@ -178,28 +180,54 @@
>   AddPath(Base + "/backward", CXXSystem, true, false, false);
>  }
>
> +void InitHeaderSearch::AddMinGWCIncludePaths(StringRef Base) {
> +  // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits
> +  llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");
> +  llvm::error_code EC;
> +  for (llvm::sys::fs::directory_iterator I(Base + "/lib/gcc/mingw32", EC), E;
> +       I != E && !EC; I.increment(EC)) {
> +    llvm::sys::fs::file_status status;
> +    if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {
> +      AddPath(I->path() + "/include", System, true, false, false);
> +      AddPath(Base + "/" + "include", System, true, false, false);
> +      AddPath(I->path() + "/include-fixed", System, true, false, false);
> +    }
> +  }
> +}
> +
>  void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
> -                                                     StringRef Arch,
> -                                                     StringRef Version) {
> -  AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
> -          CXXSystem, true, false, false);
> -  AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
> -          CXXSystem, true, false, false);
> -  AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",
> -          CXXSystem, true, false, false);
> +                                                     StringRef Arch) {
> +  // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits
> +  llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");
> +  llvm::error_code EC;
> +  for (llvm::sys::fs::directory_iterator I(Base + "/" + Arch, EC), E;
> +       I != E && !EC; I.increment(EC)) {
> +    llvm::sys::fs::file_status status;
> +    if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {
> +      const std::string &P = I->path();
> +      AddPath(P + "/include/c++", CXXSystem, true, false, false);
> +      AddPath(P + "/include/c++/" + Arch, CXXSystem, true, false, false);
> +      AddPath(P + "/include/c++/backward", CXXSystem, true, false, false);
> +    }
> +  }
>  }
>
> -void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
> -                                          StringRef Version) {
> +void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base) {
> +  // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits
> +  llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");
> +  llvm::error_code EC;
>   // Assumes Base is HeaderSearchOpts' ResourceDir
> -  AddPath(Base + "/../../../include/c++/" + Version,
> -          CXXSystem, true, false, false);
> -  AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
> -          CXXSystem, true, false, false);
> -  AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
> -          CXXSystem, true, false, false);
> -  AddPath(Base + "/../../../include/c++/" + Version + "/backward",
> -          CXXSystem, true, false, false);
> +  llvm::Twine Path = Base + "/../../../include/c++/";
> +  for (llvm::sys::fs::directory_iterator I(Path, EC), E;
> +       I != E && !EC; I.increment(EC)) {
> +    llvm::sys::fs::file_status status;
> +    if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {
> +      AddPath(I->path(), CXXSystem, true, false, false);
> +      AddPath(I->path() + "/x86_64-w64-mingw32", CXXSystem, true, false, false);
> +      AddPath(I->path() + "/i686-w64-mingw32", CXXSystem, true, false, false);
> +      AddPath(I->path() + "/backward", CXXSystem, true, false, false);
> +    }
> +  }
>  }
>
>  void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
> @@ -311,7 +339,7 @@
>       P.appendComponent("../../../include"); // <sysroot>/include
>       AddPath(P.str(), System, true, false, false);
>       AddPath("/mingw/include", System, true, false, false);
> -      AddPath("c:/mingw/include", System, true, false, false);
> +      AddMinGWCIncludePaths("c:/mingw");
>     }
>     break;
>
> @@ -367,32 +395,14 @@
>     llvm_unreachable("Include management is handled in the driver.");
>
>   case llvm::Triple::Cygwin:
> -    // Cygwin-1.7
> -    AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");
> -    AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");
> -    // g++-4 / Cygwin-1.5
> -    AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");
> +    AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin");
>     break;
>   case llvm::Triple::MinGW32:
>     // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
> -    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
> +    AddMinGW64CXXPaths(HSOpts.ResourceDir);
>     // mingw.org C++ include paths
> -    AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
> -    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
> -    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
> -    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
> -    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
> -    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
> -    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
> +    AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32"); //MSYS
> +    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32");
>     break;
>   case llvm::Triple::DragonFly:
>     AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);




More information about the cfe-commits mailing list