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 searchPaths = detector.searchPaths;
if (device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
// FIXME: Merge with block below
FilePaths searchPaths = detector.searchPaths;
if (searchPaths.isEmpty())
searchPaths = device->systemEnvironment().path();
for (const FilePath &deviceDir : std::as_const(searchPaths)) {
static const QRegularExpression regexp(binaryRegexp);
const auto callBack = [&compilerPaths, compilerName](const FilePath &candidate) {
if (candidate.fileName() == compilerName)
compilerPaths << candidate;
else if (regexp.match(candidate.path()).hasMatch())
compilerPaths << candidate;
return IterationPolicy::Continue;
};
const FilePath globalDir = device->filePath(deviceDir.path());
globalDir.iterateDirectory(callBack, {nameFilters, QDir::Files | QDir::Executable});
searchPaths = Utils::transform(searchPaths, [&](const FilePath &onDevice) {
return device->filePath(onDevice.path());
});
} else if (searchPaths.isEmpty()) {
searchPaths = Environment::systemEnvironment().path();
searchPaths << gnuSearchPathsFromRegistry();
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
}
} else {
// The normal, local host case.
FilePaths searchPaths = detector.searchPaths;
if (searchPaths.isEmpty()) {
searchPaths = Environment::systemEnvironment().path();
searchPaths << gnuSearchPathsFromRegistry();
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));
}
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 &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;
}