<br><br><div class="gmail_quote">Le 25 mars 2012 17:47, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>></span> a écrit :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: aaronballman<br>
Date: Sun Mar 25 10:47:41 2012<br>
New Revision: 153413<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=153413&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=153413&view=rev</a><br>
Log:<br>
No longer hard coding paths to the MinGW include directories; using a regular expression instead.<br>
<br>
Patch thanks to Nikola Smiljanic<br>
<br>
Modified:<br>
cfe/trunk/lib/Frontend/InitHeaderSearch.cpp<br>
<br>
Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=153413&r1=153412&r2=153413&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=153413&r1=153412&r2=153413&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Sun Mar 25 10:47:41 2012<br>
@@ -24,7 +24,9 @@<br>
#include "llvm/ADT/Twine.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
#include "llvm/Support/ErrorHandling.h"<br>
+#include "llvm/Support/FileSystem.h"<br>
#include "llvm/Support/Path.h"<br>
+#include "llvm/Support/Regex.h"<br>
<br>
#include "clang/Config/config.h" // C_INCLUDE_DIRS<br>
<br>
@@ -64,17 +66,17 @@<br>
StringRef Dir32,<br>
StringRef Dir64,<br>
const llvm::Triple &triple);<br>
+<br>
+ /// AddMinGWCIncludePaths - Add MinGW paths that should always be searched<br>
+ void AddMinGWCIncludePaths(StringRef Base);<br>
<br>
/// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW<br>
/// libstdc++.<br>
- void AddMinGWCPlusPlusIncludePaths(StringRef Base,<br>
- StringRef Arch,<br>
- StringRef Version);<br>
+ void AddMinGWCPlusPlusIncludePaths(StringRef Base, StringRef Arch);<br>
<br>
/// AddMinGW64CXXPaths - Add the necessary paths to support<br>
/// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.<br>
- void AddMinGW64CXXPaths(StringRef Base,<br>
- StringRef Version);<br>
+ void AddMinGW64CXXPaths(StringRef Base);<br>
<br>
// AddDefaultCIncludePaths - Add paths that should always be searched.<br>
void AddDefaultCIncludePaths(const llvm::Triple &triple,<br>
@@ -178,28 +180,54 @@<br>
AddPath(Base + "/backward", CXXSystem, true, false, false);<br>
}<br>
<br>
+void InitHeaderSearch::AddMinGWCIncludePaths(StringRef Base) {<br>
+ // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits<br>
+ llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");<br>
+ llvm::error_code EC;<br>
+ for (llvm::sys::fs::directory_iterator I(Base + "/lib/gcc/mingw32", EC), E;<br>
+ I != E && !EC; I.increment(EC)) {<br>
+ llvm::sys::fs::file_status status;<br>
+ if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {<br>
+ AddPath(I->path() + "/include", System, true, false, false);<br>
+ AddPath(Base + "/" + "include", System, true, false, false);<br>
+ AddPath(I->path() + "/include-fixed", System, true, false, false);<br>
+ }<br>
+ }<br>
+}<br>
+<br>
void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,<br>
- StringRef Arch,<br>
- StringRef Version) {<br>
- AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",<br>
- CXXSystem, true, false, false);<br>
- AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,<br>
- CXXSystem, true, false, false);<br>
- AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward",<br>
- CXXSystem, true, false, false);<br>
+ StringRef Arch) {<br>
+ // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits<br>
+ llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");<br>
+ llvm::error_code EC;<br>
+ for (llvm::sys::fs::directory_iterator I(Base + "/" + Arch, EC), E;<br>
+ I != E && !EC; I.increment(EC)) {<br>
+ llvm::sys::fs::file_status status;<br>
+ if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {<br>
+ const std::string &P = I->path();<br>
+ AddPath(P + "/include/c++", CXXSystem, true, false, false);<br>
+ AddPath(P + "/include/c++/" + Arch, CXXSystem, true, false, false);<br>
+ AddPath(P + "/include/c++/backward", CXXSystem, true, false, false);<br>
+ }<br>
+ }<br>
}<br>
<br>
-void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,<br>
- StringRef Version) {<br>
+void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base) {<br>
+ // match directories of the forms x.x and x.x.x where x can be 1 or 2 digits<br>
+ llvm::Regex Regex("[0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?$");<br>
+ llvm::error_code EC;<br>
// Assumes Base is HeaderSearchOpts' ResourceDir<br>
- AddPath(Base + "/../../../include/c++/" + Version,<br>
- CXXSystem, true, false, false);<br>
- AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",<br>
- CXXSystem, true, false, false);<br>
- AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",<br>
- CXXSystem, true, false, false);<br>
- AddPath(Base + "/../../../include/c++/" + Version + "/backward",<br>
- CXXSystem, true, false, false);<br>
+ llvm::Twine Path = Base + "/../../../include/c++/";<br>
+ for (llvm::sys::fs::directory_iterator I(Path, EC), E;<br>
+ I != E && !EC; I.increment(EC)) {<br>
+ llvm::sys::fs::file_status status;<br>
+ if (!I->status(status) && is_directory(status) && Regex.match(I->path())) {<br>
+ AddPath(I->path(), CXXSystem, true, false, false);<br>
+ AddPath(I->path() + "/x86_64-w64-mingw32", CXXSystem, true, false, false);<br>
+ AddPath(I->path() + "/i686-w64-mingw32", CXXSystem, true, false, false);<br>
+ AddPath(I->path() + "/backward", CXXSystem, true, false, false);<br>
+ }<br>
+ }<br>
}<br>
<br>
void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,<br>
@@ -311,7 +339,7 @@<br>
P.appendComponent("../../../include"); // <sysroot>/include<br>
AddPath(P.str(), System, true, false, false);<br>
AddPath("/mingw/include", System, true, false, false);<br>
- AddPath("c:/mingw/include", System, true, false, false);<br>
+ AddMinGWCIncludePaths("c:/mingw");<br>
}<br>
break;<br>
<br>
@@ -367,32 +395,14 @@<br>
llvm_unreachable("Include management is handled in the driver.");<br>
<br>
case llvm::Triple::Cygwin:<br>
- // Cygwin-1.7<br>
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.5.3");<br>
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4");<br>
- // g++-4 / Cygwin-1.5<br>
- AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2");<br>
+ AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin");<br>
break;<br>
case llvm::Triple::MinGW32:<br>
// mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");<br>
- AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");<br>
+ AddMinGW64CXXPaths(HSOpts.ResourceDir);<br>
// <a href="http://mingw.org" target="_blank">mingw.org</a> C++ include paths<br>
- AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS<br>
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");<br>
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");<br>
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");<br>
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");<br>
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");<br>
- AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");<br>
+ AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32"); //MSYS<br>
+ AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32");<br>
break;<br>
case llvm::Triple::DragonFly:<br>
AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false);<br><br></blockquote><div>In the case of Mingw64 the base path is taken from options (it seems), while in the case of mingw32 it is hard-coded to the C:/ directory. Do you think it would be possible to supply this parameter at runtime too ? It would avoid the necessity to edit this file when one has not installed mingw on C:/<br>
<br>(Note: the option could perfectly default to C:/mingw)<br><br>-- Matthieu <br></div></div>