From 4a50a582e79c14ee6df5b6ed34ffa50bd384ad9c Mon Sep 17 00:00:00 2001 From: Christiaan Janssen Date: Tue, 23 Nov 2021 16:20:52 +0100 Subject: [PATCH] McuSupport: default paths for 3rd party dependencies left empty If QtCreator is installed via the Qt Installer, sensible defaults are provided at installation time. For not provided software, $HOME is not a useful default. Leaving the field empty signals the user that they need to provide one manually, more clearly than providing an invalid path. Task-number: UL-4939 Change-Id: I8ef79e563366ebdbea53df8183a1eca82bd7be4a Reviewed-by: Alessandro Portale Reviewed-by: --- src/plugins/mcusupport/mcusupportsdk.cpp | 42 +++++++++--------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/plugins/mcusupport/mcusupportsdk.cpp b/src/plugins/mcusupport/mcusupportsdk.cpp index 1823d634513..90fc1bb1467 100644 --- a/src/plugins/mcusupport/mcusupportsdk.cpp +++ b/src/plugins/mcusupport/mcusupportsdk.cpp @@ -104,8 +104,6 @@ static McuToolChainPackage *createArmGccPackage() defaultPath = subDirs.first(); } } - if (defaultPath.isEmpty()) - defaultPath = FileUtils::homePath(); const QString detectionPath = Utils::HostOsInfo::withExecutableSuffix("bin/arm-none-eabi-g++"); const auto versionDetector = new McuPackageExecutableVersionDetector( @@ -129,8 +127,7 @@ static McuToolChainPackage *createGhsToolchainPackage() { const char envVar[] = "GHS_COMPILER_DIR"; - const FilePath defaultPath = qEnvironmentVariableIsSet(envVar) - ? FilePath::fromUserInput(qEnvironmentVariable(envVar)) : FileUtils::homePath(); + const FilePath defaultPath = FilePath::fromUserInput(qEnvironmentVariable(envVar)); const auto versionDetector = new McuPackageExecutableVersionDetector( Utils::HostOsInfo::withExecutableSuffix("as850"), @@ -153,8 +150,7 @@ static McuToolChainPackage *createGhsArmToolchainPackage() { const char envVar[] = "GHS_ARM_COMPILER_DIR"; - const FilePath defaultPath = qEnvironmentVariableIsSet(envVar) - ? FilePath::fromUserInput(qEnvironmentVariable(envVar)) : FileUtils::homePath(); + const FilePath defaultPath = FilePath::fromUserInput(qEnvironmentVariable(envVar)); const auto versionDetector = new McuPackageExecutableVersionDetector( Utils::HostOsInfo::withExecutableSuffix("asarm"), @@ -189,8 +185,6 @@ static McuToolChainPackage *createIarToolChainPackage() const FilePath compilerExecPath = tc->compilerCommand(); defaultPath = compilerExecPath.parentDir().parentDir(); } - else - defaultPath = FileUtils::homePath(); } const QString detectionPath = Utils::HostOsInfo::withExecutableSuffix("bin/iccarm"); @@ -219,8 +213,9 @@ static McuPackage *createRGLPackage() if (qEnvironmentVariableIsSet(envVar)) { defaultPath = FilePath::fromUserInput(qEnvironmentVariable(envVar)); } else if (Utils::HostOsInfo::isWindowsHost()) { - defaultPath = FilePath::fromUserInput(QDir::rootPath() + "Renesas_Electronics/D1x_RGL"); - if (defaultPath.exists()) { + const FilePath rglPath = FilePath::fromString(QDir::rootPath()) / "Renesas_Electronics/D1x_RGL"; + if (rglPath.exists()) { + defaultPath = rglPath; const FilePaths subDirs = defaultPath.dirEntries({QLatin1String("rgl_ghs_D1Mx_*")}, QDir::Dirs | QDir::NoDotAndDotDot); @@ -240,7 +235,7 @@ static McuPackage *createRGLPackage() static McuPackage *createStm32CubeProgrammerPackage() { - FilePath defaultPath = FileUtils::homePath(); + FilePath defaultPath; const QString cubePath = "STMicroelectronics/STM32Cube/STM32CubeProgrammer"; if (HostOsInfo::isWindowsHost()) { const FilePath programPath = findInProgramFiles(cubePath); @@ -272,8 +267,9 @@ static McuPackage *createMcuXpressoIdePackage() if (qEnvironmentVariableIsSet(envVar)) { defaultPath = FilePath::fromUserInput(qEnvironmentVariable(envVar)); } else if (HostOsInfo::isWindowsHost()) { - defaultPath = FilePath::fromString(QDir::rootPath() + "nxp"); - if (defaultPath.exists()) { + const FilePath programPath = FilePath::fromString(QDir::rootPath()) / "nxp"; + if (programPath.exists()) { + defaultPath = programPath; // If default dir has exactly one sub dir that could be the IDE path, pre-select that. const FilePaths subDirs = defaultPath.dirEntries({QLatin1String("MCUXpressoIDE*")}, @@ -282,7 +278,9 @@ static McuPackage *createMcuXpressoIdePackage() defaultPath = subDirs.first(); } } else { - defaultPath = "/usr/local/mcuxpressoide/"; + const FilePath programPath = FilePath::fromString("/usr/local/mcuxpressoide/"); + if (programPath.exists()) + defaultPath = programPath; } auto result = new McuPackage( @@ -303,17 +301,11 @@ static McuPackage *createCypressProgrammerPackage() if (qEnvironmentVariableIsSet(envVar)) { defaultPath = FilePath::fromUserInput(qEnvironmentVariable(envVar)); } else if (HostOsInfo::isWindowsHost()) { - FilePath candidate = findInProgramFiles("Cypress/Cypress Auto Flash Utility 1.0"); - if (candidate.exists()) { + const FilePath candidate = findInProgramFiles("Cypress/Cypress Auto Flash Utility 1.0"); + if (candidate.exists()) defaultPath = candidate; - } - } else { - defaultPath = "/usr"; } - if (defaultPath.isEmpty()) - defaultPath = FileUtils::homePath(); - auto result = new McuPackage( "Cypress Auto Flash Utility", defaultPath, @@ -393,7 +385,7 @@ static McuPackage *createBoardSdkPackage(const McuTargetDescription& desc) if (defaultPath.exists()) return defaultPath; } - return FileUtils::homePath(); + return FilePath(); }(); const auto versionDetector = generatePackageVersionDetector(desc.boardSdk.envVar); @@ -418,8 +410,6 @@ static McuPackage *createFreeRTOSSourcesPackage(const QString &envVar, const Fil defaultPath = FilePath::fromUserInput(qEnvironmentVariable(envVar.toLatin1())); else if (!boardSdkDir.isEmpty() && !freeRTOSBoardSdkSubDir.isEmpty()) defaultPath = boardSdkDir / freeRTOSBoardSdkSubDir; - else - defaultPath = FileUtils::homePath(); auto result = new McuPackage( QString::fromLatin1("FreeRTOS Sources (%1)").arg(envVarPrefix), @@ -634,7 +624,7 @@ static QVector targetsFromDescriptions(const QList