From c12e48ea36bfc4308d7449ca4745324c852459eb Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 17 Jun 2021 16:56:14 +0200 Subject: [PATCH] ProjectExplorer: Allow gcc autodetection on docker devices This uses a separate branch for the remote detection and leaves the local development host path untouched. Ideally the code should be identical, but currently the environment handling on remote devices is not on par with the local cases, yet good enough to find normal gcc installations. Change-Id: I6762299d8ddfdf2aceb0d57cc77ab71fcc83788b Reviewed-by: Christian Kandeler --- src/plugins/projectexplorer/gcctoolchain.cpp | 77 +++++++++++++------- 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/src/plugins/projectexplorer/gcctoolchain.cpp b/src/plugins/projectexplorer/gcctoolchain.cpp index e882260f7d2..167db34f42b 100644 --- a/src/plugins/projectexplorer/gcctoolchain.cpp +++ b/src/plugins/projectexplorer/gcctoolchain.cpp @@ -1035,23 +1035,47 @@ QList GccToolChainFactory::detectForImport(const ToolChainDescripti return QList(); } -QList GccToolChainFactory::autoDetectToolchains( - const QString &compilerName, - DetectVariants detectVariants, - const Id language, - const Id requiredTypeId, - const QList &alreadyKnown, - const IDevice::Ptr &device, - const ToolchainChecker &checker) + +static FilePaths findCompilerCandidates(const IDevice::Ptr &device, + const QString &compilerName, + bool detectVariants) { - Q_UNUSED(device) + const QFileInfo fi(compilerName); + if (device.isNull() && fi.isAbsolute() && fi.isFile()) + return {FilePath::fromString(compilerName)}; + + QStringList nameFilters(compilerName); + if (detectVariants) { + nameFilters + << compilerName + "-[1-9]*" // "clang-8", "gcc-5" + << ("*-" + compilerName) // "avr-gcc", "avr32-gcc" + << ("*-" + compilerName + "-[1-9]*")// "avr-gcc-4.8.1", "avr32-gcc-4.4.7" + << ("*-*-*-" + compilerName) // "arm-none-eabi-gcc" + << ("*-*-*-" + compilerName + "-[1-9]*") // "arm-none-eabi-gcc-9.1.0" + << ("*-*-*-*-" + compilerName) // "x86_64-pc-linux-gnu-gcc" + << ("*-*-*-*-" + compilerName + + "-[1-9]*"); // "x86_64-pc-linux-gnu-gcc-7.4.1" + } FilePaths compilerPaths; - QFileInfo fi(compilerName); - if (fi.isAbsolute()) { - if (fi.isFile()) - compilerPaths << FilePath::fromString(compilerName); + + if (!device.isNull()) { + // FIXME: Merge with block below + FilePaths searchPaths = device->systemEnvironment().path(); + for (const FilePath &deviceDir : qAsConst(searchPaths)) { + static const QRegularExpression regexp(binaryRegexp); + const FilePath globalDir = device->mapToGlobalPath(deviceDir); + const FilePaths fileNames = device->directoryEntries(globalDir, nameFilters, + QDir::Files | QDir::Executable); + for (const FilePath &fileName : fileNames) { + if (fileName.fileName() == compilerName) + compilerPaths << fileName; + else if (regexp.match(fileName.path()).hasMatch()) + compilerPaths << fileName; + } + } } else { + // The normal, local host case. FilePaths searchPaths = Environment::systemEnvironment().path(); searchPaths << gnuSearchPathsFromRegistry(); searchPaths << atmelSearchPathsFromRegistry(); @@ -1066,18 +1090,6 @@ QList GccToolChainFactory::autoDetectToolchains( for (const FilePath &dir : qAsConst(searchPaths)) { static const QRegularExpression regexp(binaryRegexp); QDir binDir(dir.toString()); - QStringList nameFilters(compilerName); - if (detectVariants == DetectVariants::Yes) { - nameFilters - << compilerName + "-[1-9]*" // "clang-8", "gcc-5" - << ("*-" + compilerName) // "avr-gcc", "avr32-gcc" - << ("*-" + compilerName + "-[1-9]*")// "avr-gcc-4.8.1", "avr32-gcc-4.4.7" - << ("*-*-*-" + compilerName) // "arm-none-eabi-gcc" - << ("*-*-*-" + compilerName + "-[1-9]*") // "arm-none-eabi-gcc-9.1.0" - << ("*-*-*-*-" + compilerName) // "x86_64-pc-linux-gnu-gcc" - << ("*-*-*-*-" + compilerName - + "-[1-9]*"); // "x86_64-pc-linux-gnu-gcc-7.4.1" - } nameFilters = transform(nameFilters, [](const QString &baseName) { return HostOsInfo::withExecutableSuffix(baseName); }); @@ -1093,6 +1105,21 @@ QList GccToolChainFactory::autoDetectToolchains( } } + return compilerPaths; +} + +QList GccToolChainFactory::autoDetectToolchains( + const QString &compilerName, + DetectVariants detectVariants, + const Id language, + const Id requiredTypeId, + const QList &alreadyKnown, + const IDevice::Ptr &device, + const ToolchainChecker &checker) +{ + const FilePaths compilerPaths = + findCompilerCandidates(device, compilerName, detectVariants == DetectVariants::Yes); + QList existingCandidates = filtered(alreadyKnown, [requiredTypeId, language, &checker](const ToolChain *tc) { if (tc->typeId() != requiredTypeId)