ProjectExplorer: filepathify gcc toolchain detection

Change-Id: I4114229033e2e9ba93d628d2014e224e3b1d5c1e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
David Schulz
2023-08-31 13:50:56 +02:00
parent 6f50addc1c
commit f2a93943f5

View File

@@ -1104,60 +1104,42 @@ static FilePaths findCompilerCandidates(const ToolchainDetector &detector,
}); });
FilePaths compilerPaths; FilePaths compilerPaths;
FilePaths searchPaths = detector.searchPaths;
if (device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) { if (device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
// FIXME: Merge with block below
FilePaths searchPaths = detector.searchPaths;
if (searchPaths.isEmpty()) if (searchPaths.isEmpty())
searchPaths = device->systemEnvironment().path(); searchPaths = device->systemEnvironment().path();
for (const FilePath &deviceDir : std::as_const(searchPaths)) { searchPaths = Utils::transform(searchPaths, [&](const FilePath &onDevice) {
static const QRegularExpression regexp(binaryRegexp); return device->filePath(onDevice.path());
const auto callBack = [&compilerPaths, compilerName](const FilePath &candidate) { });
if (candidate.fileName() == compilerName) } else if (searchPaths.isEmpty()) {
compilerPaths << candidate; searchPaths = Environment::systemEnvironment().path();
else if (regexp.match(candidate.path()).hasMatch()) searchPaths << gnuSearchPathsFromRegistry();
compilerPaths << candidate; searchPaths << atmelSearchPathsFromRegistry();
return IterationPolicy::Continue; searchPaths << renesasRl78SearchPathsFromRegistry();
}; if (HostOsInfo::isMacHost()) {
const FilePath globalDir = device->filePath(deviceDir.path()); searchPaths << "/opt/homebrew/opt/ccache/libexec" // homebrew arm
globalDir.iterateDirectory(callBack, {nameFilters, QDir::Files | QDir::Executable}); << "/usr/local/opt/ccache/libexec" // homebrew intel
<< "/opt/local/libexec/ccache"; // macports, no links are created automatically though
} }
} else { if (HostOsInfo::isAnyUnixHost()) {
// The normal, local host case. FilePath ccachePath = "/usr/lib/ccache/bin";
FilePaths searchPaths = detector.searchPaths; if (!ccachePath.exists())
if (searchPaths.isEmpty()) { ccachePath = "/usr/lib/ccache";
searchPaths = Environment::systemEnvironment().path(); if (ccachePath.exists() && !searchPaths.contains(ccachePath))
searchPaths << gnuSearchPathsFromRegistry(); searchPaths << ccachePath;
searchPaths << atmelSearchPathsFromRegistry();
searchPaths << renesasRl78SearchPathsFromRegistry();
if (HostOsInfo::isMacHost()) {
searchPaths << "/opt/homebrew/opt/ccache/libexec" // homebrew arm
<< "/usr/local/opt/ccache/libexec" // homebrew intel
<< "/opt/local/libexec/ccache"; // macports, no links are created automatically though
}
if (HostOsInfo::isAnyUnixHost()) {
FilePath ccachePath = "/usr/lib/ccache/bin";
if (!ccachePath.exists())
ccachePath = "/usr/lib/ccache";
if (ccachePath.exists() && !searchPaths.contains(ccachePath))
searchPaths << ccachePath;
}
}
for (const FilePath &dir : std::as_const(searchPaths)) {
static const QRegularExpression regexp(binaryRegexp);
QDir binDir(dir.toString());
const QStringList fileNames = binDir.entryList(nameFilters,
QDir::Files | QDir::Executable);
for (const QString &fileName : fileNames) {
if (fileName != compilerName &&
!regexp.match(QFileInfo(fileName).completeBaseName()).hasMatch()) {
continue;
}
compilerPaths << FilePath::fromString(binDir.filePath(fileName));
}
} }
} }
for (const FilePath &searchPath : std::as_const(searchPaths)) {
static const QRegularExpression regexp(binaryRegexp);
const auto callBack = [&compilerPaths, compilerName](const FilePath &candidate) {
if (candidate.fileName() == compilerName || regexp.match(candidate.path()).hasMatch())
compilerPaths << candidate;
return IterationPolicy::Continue;
};
searchPath.iterateDirectory(callBack, {nameFilters, QDir::Files | QDir::Executable});
}
return compilerPaths; return compilerPaths;
} }