[cfe-dev] Version agnostic path search for mingw
Nikola Smiljanic
popizdeh at gmail.com
Fri Mar 23 16:02:01 PDT 2012
On Thu, Mar 22, 2012 at 1:35 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
> I'd go back to the previous patch and
> submit the mingw fixes.
This should be it.
-------------- next part --------------
Index: lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- lib/Frontend/InitHeaderSearch.cpp (revision 153340)
+++ lib/Frontend/InitHeaderSearch.cpp (working copy)
@@ -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,55 @@
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 +340,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 +396,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-dev
mailing list