Docker: Fix searching compilers in custom directories

Previously, detection (mostly) only used path.

Change-Id: If382205c2ff39cabfe21953e877e152dc952a84c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2022-03-14 16:37:57 +01:00
parent c865481068
commit a23c4ce014
8 changed files with 44 additions and 22 deletions

View File

@@ -725,7 +725,7 @@ Toolchains KitDetectorPrivate::autoDetectToolChains()
emit q->logOutput('\n' + tr("Searching toolchains..."));
for (ToolChainFactory *factory : factories) {
emit q->logOutput(tr("Searching toolchains of type %1").arg(factory->displayName()));
const ToolchainDetector detector(alreadyKnown, m_device);
const ToolchainDetector detector(alreadyKnown, m_device, m_searchPaths);
const Toolchains newToolChains = factory->autoDetect(detector);
for (ToolChain *toolChain : newToolChains) {
emit q->logOutput(tr("Found \"%1\"").arg(toolChain->compilerCommand().toUserOutput()));
@@ -1809,6 +1809,12 @@ QByteArray DockerDevicePrivate::outputForRunInShell(const CommandLine &cmd) cons
QTC_ASSERT(m_shell && m_shell->isRunning(), return {});
QMutexLocker l(&m_shellMutex);
m_shell->readAllStandardOutput(); // clean possible left-overs
const QByteArray oldError = m_shell->readAllStandardError(); // clean possible left-overs
if (!oldError.isEmpty()) {
LOG("Unexpected old stderr: " << oldError);
QTC_CHECK(false);
}
const QByteArray markerWithNewLine("___QC_DOCKER_" + randomHex() + "_OUTPUT_MARKER___\n");
m_shell->write(cmd.toUserOutput().toUtf8() + "\necho -n \"" + markerWithNewLine + "\"\n");
QByteArray output;
@@ -1820,6 +1826,11 @@ QByteArray DockerDevicePrivate::outputForRunInShell(const CommandLine &cmd) cons
LOG("Run command in shell:" << cmd.toUserOutput() << "output size:" << output.size());
if (QTC_GUARD(output.endsWith(markerWithNewLine)))
output.chop(markerWithNewLine.size());
const QByteArray currentError = m_shell->readAllStandardError();
if (!currentError.isEmpty()) {
LOG("Unexpected current stderr: " << currentError);
QTC_CHECK(false);
}
return output;
}

View File

@@ -354,7 +354,7 @@ static ToolChain *iarToolChain(const FilePath &path, Id language)
== BareMetal::Constants::IAREW_TOOLCHAIN_TYPEID;
});
if (iarFactory) {
Toolchains detected = iarFactory->autoDetect(ToolchainDetector({}, {}));
Toolchains detected = iarFactory->autoDetect(ToolchainDetector({}, {}, {}));
if (detected.isEmpty())
detected = iarFactory->detectForImport({path, language});
for (auto tc : detected) {

View File

@@ -1090,10 +1090,11 @@ Toolchains GccToolChainFactory::detectForImport(const ToolChainDescription &tcd)
return {};
}
static FilePaths findCompilerCandidates(const IDevice::ConstPtr &device,
static FilePaths findCompilerCandidates(const ToolchainDetector &detector,
const QString &compilerName,
bool detectVariants)
{
const IDevice::ConstPtr device = detector.device;
const QFileInfo fi(compilerName);
if (device.isNull() && fi.isAbsolute() && fi.isFile())
return {FilePath::fromString(compilerName)};
@@ -1119,7 +1120,9 @@ static FilePaths findCompilerCandidates(const IDevice::ConstPtr &device,
if (!device.isNull()) {
// FIXME: Merge with block below
FilePaths searchPaths = device->systemEnvironment().path();
FilePaths searchPaths = detector.searchPaths;
if (searchPaths.isEmpty())
searchPaths = device->systemEnvironment().path();
for (const FilePath &deviceDir : qAsConst(searchPaths)) {
static const QRegularExpression regexp(binaryRegexp);
const auto callBack = [&compilerPaths, compilerName](const FilePath &candidate) {
@@ -1135,16 +1138,19 @@ static FilePaths findCompilerCandidates(const IDevice::ConstPtr &device,
}
} else {
// The normal, local host case.
FilePaths searchPaths = Environment::systemEnvironment().path();
searchPaths << gnuSearchPathsFromRegistry();
searchPaths << atmelSearchPathsFromRegistry();
searchPaths << renesasRl78SearchPathsFromRegistry();
if (HostOsInfo::isAnyUnixHost()) {
FilePath ccachePath = "/usr/lib/ccache/bin";
if (!ccachePath.exists())
ccachePath = "/usr/lib/ccache";
if (ccachePath.exists() && !searchPaths.contains(ccachePath))
searchPaths << ccachePath;
FilePaths searchPaths = detector.searchPaths;
if (searchPaths.isEmpty()) {
searchPaths = Environment::systemEnvironment().path();
searchPaths << gnuSearchPathsFromRegistry();
searchPaths << atmelSearchPathsFromRegistry();
searchPaths << renesasRl78SearchPathsFromRegistry();
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 : qAsConst(searchPaths)) {
static const QRegularExpression regexp(binaryRegexp);
@@ -1173,7 +1179,7 @@ Toolchains GccToolChainFactory::autoDetectToolchains(
const ToolchainChecker &checker) const
{
const FilePaths compilerPaths =
findCompilerCandidates(detector.device, compilerName, detectVariants == DetectVariants::Yes);
findCompilerCandidates(detector, compilerName, detectVariants == DetectVariants::Yes);
Toolchains existingCandidates = filtered(detector.alreadyKnown,
[language](const ToolChain *tc) { return tc->language() == language; });
Toolchains result;
@@ -1742,7 +1748,7 @@ Toolchains ClangToolChainFactory::autoDetect(const ToolchainDetector &detector)
const FilePath clang = compilerPath.parentDir().pathAppended("clang").withExecutableSuffix();
tcs.append(autoDetectToolchains(clang.toString(), DetectVariants::No,
Constants::C_LANGUAGE_ID, Constants::CLANG_TOOLCHAIN_TYPEID,
ToolchainDetector(known, detector.device)));
ToolchainDetector(known, detector.device, detector.searchPaths)));
}
return tcs;

View File

@@ -673,8 +673,10 @@ void ToolChainFactory::setUserCreatable(bool userCreatable)
m_userCreatable = userCreatable;
}
ToolchainDetector::ToolchainDetector(const Toolchains &alreadyKnown, const IDevice::ConstPtr &device)
: alreadyKnown(alreadyKnown), device(device)
ToolchainDetector::ToolchainDetector(const Toolchains &alreadyKnown,
const IDevice::ConstPtr &device,
const FilePaths &searchPaths)
: alreadyKnown(alreadyKnown), device(device), searchPaths(searchPaths)
{}
BadToolchain::BadToolchain(const Utils::FilePath &filePath)

View File

@@ -250,13 +250,16 @@ public:
class PROJECTEXPLORER_EXPORT ToolchainDetector
{
public:
ToolchainDetector(const Toolchains &alreadyKnown, const IDevice::ConstPtr &device);
ToolchainDetector(const Toolchains &alreadyKnown,
const IDevice::ConstPtr &device,
const Utils::FilePaths &searchPaths);
bool isBadToolchain(const Utils::FilePath &toolchain) const;
void addBadToolchain(const Utils::FilePath &toolchain) const;
const Toolchains alreadyKnown;
const IDevice::ConstPtr device;
const Utils::FilePaths searchPaths; // If empty use device path and/or magic.
};
class PROJECTEXPLORER_EXPORT ToolChainFactory

View File

@@ -412,7 +412,7 @@ void ToolChainOptionsWidget::redetectToolchains()
QSet<ToolChain *> toDelete;
ToolChainManager::resetBadToolchains();
for (ToolChainFactory *f : ToolChainFactory::allToolChainFactories()) {
const ToolchainDetector detector(knownTcs, {}); // FIXME: Pass device.
const ToolchainDetector detector(knownTcs, {}, {}); // FIXME: Pass device and search paths
for (ToolChain * const tc : f->autoDetect(detector)) {
if (knownTcs.contains(tc) || toDelete.contains(tc))
continue;

View File

@@ -205,7 +205,7 @@ Toolchains ToolChainSettingsAccessor::restoreToolChains(QWidget *parent) const
= Utils::filtered(userFileTcs, &ToolChain::isAutoDetected);
// FIXME: Use real device?
const Toolchains autodetectedTcs =
autoDetectToolChains(ToolchainDetector(autodetectedUserFileTcs, {}));
autoDetectToolChains(ToolchainDetector(autodetectedUserFileTcs, {}, {}));
// merge tool chains and register those that we need to keep:
const ToolChainOperations ops = mergeToolChainLists(systemFileTcs, userFileTcs, autodetectedTcs);

View File

@@ -126,7 +126,7 @@ void WebAssemblyToolChain::registerToolChains()
return f->supportedToolChainType() == Constants::WEBASSEMBLY_TOOLCHAIN_TYPEID;
});
QTC_ASSERT(factory, return);
for (auto toolChain : factory->autoDetect(ToolchainDetector({}, {})))
for (auto toolChain : factory->autoDetect(ToolchainDetector({}, {}, {})))
ToolChainManager::registerToolChain(toolChain);
// Let kits pick up the new toolchains