From e358c169a279dee47f70fafd86235ee6ef4fe794 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Tue, 9 Jul 2019 19:09:45 +0300 Subject: [PATCH] ProjectExplorer: Auto-detect installed GNU tools for ARM on Windows This patch implements the auto-detection for the installed GCC embedded toolchains provided by "ARM Holdings": https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads The detection algorithm does search a toolchain path in a Windows registry; this will work only if a toolchain was installed using the installer. Change-Id: Ide71fa57e5fa060372439923c8422c33ab81a8a0 Reviewed-by: Christian Kandeler --- src/plugins/projectexplorer/gcctoolchain.cpp | 35 +++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/plugins/projectexplorer/gcctoolchain.cpp b/src/plugins/projectexplorer/gcctoolchain.cpp index 097597b69ef..97a2645ec61 100644 --- a/src/plugins/projectexplorer/gcctoolchain.cpp +++ b/src/plugins/projectexplorer/gcctoolchain.cpp @@ -855,6 +855,38 @@ QString GccToolChain::detectVersion() const // GccToolChainFactory // -------------------------------------------------------------------------- +static Utils::FilePathList searchPathsFromRegistry() +{ + if (!HostOsInfo::isWindowsHost()) + return {}; + + // Registry token for the "GNU Tools for ARM Embedded Processors". + static const char kRegistryToken[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" \ + "Windows\\CurrentVersion\\Uninstall\\"; + + Utils::FilePathList searchPaths; + + QSettings registry(kRegistryToken, QSettings::NativeFormat); + const auto productGroups = registry.childGroups(); + for (const QString &productKey : productGroups) { + if (!productKey.startsWith("GNU Tools for ARM Embedded Processors")) + continue; + registry.beginGroup(productKey); + QString uninstallFilePath = registry.value("UninstallString").toString(); + if (uninstallFilePath.startsWith(QLatin1Char('"'))) + uninstallFilePath.remove(0, 1); + if (uninstallFilePath.endsWith(QLatin1Char('"'))) + uninstallFilePath.remove(uninstallFilePath.size() - 1, 1); + registry.endGroup(); + + const QString toolkitRootPath = QFileInfo(uninstallFilePath).path(); + const QString toolchainPath = toolkitRootPath + QLatin1String("/bin"); + searchPaths.push_back(FilePath::fromString(toolchainPath)); + } + + return searchPaths; +} + GccToolChainFactory::GccToolChainFactory() { setDisplayName(tr("GCC")); @@ -904,7 +936,8 @@ QList GccToolChainFactory::autoDetectToolchains( if (fi.isFile()) compilerPaths << FilePath::fromString(compilerName); } else { - const FilePathList searchPaths = Environment::systemEnvironment().path(); + FilePathList searchPaths = Environment::systemEnvironment().path(); + searchPaths << searchPathsFromRegistry(); for (const FilePath &dir : searchPaths) { static const QRegularExpression regexp(binaryRegexp); QDir binDir(dir.toString());