[cfe-commits] r141134 - /cfe/trunk/lib/Driver/ToolChains.cpp
Chandler Carruth
chandlerc at gmail.com
Tue Oct 4 16:17:12 PDT 2011
Author: chandlerc
Date: Tue Oct 4 18:17:12 2011
New Revision: 141134
URL: http://llvm.org/viewvc/llvm-project?rev=141134&view=rev
Log:
Hoist the other messy part out of an inner loop and into a helper
function, cleaning up along the way.
Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=141134&r1=141133&r2=141134&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Tue Oct 4 18:17:12 2011
@@ -1590,7 +1590,6 @@
// Loop over the various components which exist and select the best GCC
// installation available. GCC installs are ranked by version number.
- static const GCCVersion MinVersion = { 4, 1, 1 };
GCCVersion BestVersion = {};
for (unsigned i = 0, ie = Prefixes.size(); i < ie; ++i) {
if (!PathExists(Prefixes[i]))
@@ -1599,48 +1598,8 @@
const std::string LibDir = Prefixes[i] + CandidateLibDirs[j].str();
if (!PathExists(LibDir))
continue;
- for (unsigned k = 0, ke = CandidateTriples.size(); k < ke; ++k) {
- StringRef CandidateTriple = CandidateTriples[k];
- const std::string TripleDir = LibDir + "/" + CandidateTriple.str();
- if (!PathExists(TripleDir))
- continue;
-
- // There are various different suffixes on the triple directory we
- // check for. We also record what is necessary to walk from each back
- // up to the lib directory.
- const std::string Suffixes[] = { "", "/gcc/" + CandidateTriple.str(),
- "/gcc/i686-linux-gnu" };
- const std::string InstallSuffixes[] = { "/../../..", "/../../../..",
- "/../../../.." };
- const unsigned NumSuffixes = (llvm::array_lengthof(Suffixes) -
- (CandidateTriple != "i386-linux-gnu"));
- for (unsigned l = 0; l < NumSuffixes; ++l) {
- StringRef Suffix = Suffixes[l];
- llvm::error_code EC;
- for (llvm::sys::fs::directory_iterator LI(TripleDir + Suffix, EC),
- LE;
- !EC && LI != LE; LI = LI.increment(EC)) {
- StringRef VersionText = llvm::sys::path::filename(LI->path());
- GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
- if (CandidateVersion < MinVersion)
- continue;
- if (CandidateVersion <= BestVersion)
- continue;
- if (!PathExists(LI->path() + "/crtbegin.o"))
- continue;
-
- BestVersion = CandidateVersion;
- GccTriple = CandidateTriple.str();
- // FIXME: We hack together the directory name here instead of
- // using LI to ensure stable path separators across Windows and
- // Linux.
- GccInstallPath = (TripleDir + Suffixes[l] + "/" +
- VersionText.str());
- GccParentLibPath = GccInstallPath + InstallSuffixes[l];
- IsValid = true;
- }
- }
- }
+ for (unsigned k = 0, ke = CandidateTriples.size(); k < ke; ++k)
+ ScanLibDirForGCCTriple(LibDir, CandidateTriples[k], BestVersion);
}
}
}
@@ -1723,6 +1682,49 @@
PPC64Triples + llvm::array_lengthof(PPC64Triples));
}
}
+
+ void ScanLibDirForGCCTriple(const std::string &LibDir,
+ StringRef CandidateTriple,
+ GCCVersion &BestVersion) {
+ const std::string TripleDir = LibDir + "/" + CandidateTriple.str();
+ if (!PathExists(TripleDir))
+ return;
+
+ // There are various different suffixes on the triple directory we
+ // check for. We also record what is necessary to walk from each back
+ // up to the lib directory.
+ const std::string Suffixes[] = { "", "/gcc/" + CandidateTriple.str(),
+ "/gcc/i686-linux-gnu" };
+ const std::string InstallSuffixes[] = { "/../../..", "/../../../..",
+ "/../../../.." };
+ const unsigned NumSuffixes = (llvm::array_lengthof(Suffixes) -
+ (CandidateTriple != "i386-linux-gnu"));
+ for (unsigned i = 0; i < NumSuffixes; ++i) {
+ StringRef Suffix = Suffixes[i];
+ llvm::error_code EC;
+ for (llvm::sys::fs::directory_iterator LI(TripleDir + Suffix, EC), LE;
+ !EC && LI != LE; LI = LI.increment(EC)) {
+ StringRef VersionText = llvm::sys::path::filename(LI->path());
+ GCCVersion CandidateVersion = GCCVersion::Parse(VersionText);
+ static const GCCVersion MinVersion = { 4, 1, 1 };
+ if (CandidateVersion < MinVersion)
+ continue;
+ if (CandidateVersion <= BestVersion)
+ continue;
+ if (!PathExists(LI->path() + "/crtbegin.o"))
+ continue;
+
+ BestVersion = CandidateVersion;
+ GccTriple = CandidateTriple.str();
+ // FIXME: We hack together the directory name here instead of
+ // using LI to ensure stable path separators across Windows and
+ // Linux.
+ GccInstallPath = TripleDir + Suffixes[i] + "/" + VersionText.str();
+ GccParentLibPath = GccInstallPath + InstallSuffixes[i];
+ IsValid = true;
+ }
+ }
+ }
};
}
More information about the cfe-commits
mailing list