From 17e0c2b0445e29e97b2b2a1cf9eb0fa5c6935ba3 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 31 Aug 2020 09:52:57 +0200 Subject: [PATCH] Nim: Fix building with nimble Do not expect nimble to be in PATH, but assume it is located where nim resides. Use kit's information of nim to construct the nimble path and add the path of nim explicitly to the build environment as nimble uses it. Also fixes running nimble test. Change-Id: If7be425f7b811486afe39fc1618709dbb2f75ac9 Reviewed-by: hjk --- src/plugins/nim/project/nimblebuildstep.cpp | 11 ++++++++-- .../nim/project/nimblerunconfiguration.cpp | 15 ++++++++++--- src/plugins/nim/project/nimbuildsystem.cpp | 21 +++++++++++++++++++ src/plugins/nim/project/nimbuildsystem.h | 3 +++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/plugins/nim/project/nimblebuildstep.cpp b/src/plugins/nim/project/nimblebuildstep.cpp index 85e5bdfe9a7..a8a84ff9018 100644 --- a/src/plugins/nim/project/nimblebuildstep.cpp +++ b/src/plugins/nim/project/nimblebuildstep.cpp @@ -26,6 +26,8 @@ #include "nimblebuildstep.h" #include "nimconstants.h" #include "nimbleproject.h" +#include "nimbuildsystem.h" +#include "nimtoolchain.h" #include #include @@ -105,10 +107,15 @@ NimbleBuildStep::NimbleBuildStep(BuildStepList *parentList, Id id) m_arguments->setArguments(defaultArguments()); setCommandLineProvider([this] { - return CommandLine(QStandardPaths::findExecutable("nimble"), - {"build", m_arguments->arguments(macroExpander())}); + auto bs = static_cast(buildSystem()); + return CommandLine(bs->defaultNimble(), + {"build", m_arguments->arguments(macroExpander())}); }); setWorkingDirectoryProvider([this] { return project()->projectDirectory(); }); + setEnvironmentModifier([this](Environment &env) { + auto bs = static_cast(buildSystem()); + env.appendOrSetPath(bs->nimPathFromKit().toUserOutput()); + }); QTC_ASSERT(buildConfiguration(), return); QObject::connect(buildConfiguration(), &BuildConfiguration::buildTypeChanged, diff --git a/src/plugins/nim/project/nimblerunconfiguration.cpp b/src/plugins/nim/project/nimblerunconfiguration.cpp index 53b7b6dd5e7..6b01571c96c 100644 --- a/src/plugins/nim/project/nimblerunconfiguration.cpp +++ b/src/plugins/nim/project/nimblerunconfiguration.cpp @@ -24,9 +24,13 @@ ****************************************************************************/ #include "nimblerunconfiguration.h" + +#include "nimbuildsystem.h" #include "nimconstants.h" #include "nimbleproject.h" +#include +#include #include #include #include @@ -35,8 +39,6 @@ #include #include -#include - using namespace ProjectExplorer; namespace Nim { @@ -89,7 +91,14 @@ public: NimbleTestConfiguration(ProjectExplorer::Target *target, Utils::Id id) : RunConfiguration(target, id) { - addAspect()->setExecutable(Utils::FilePath::fromString(QStandardPaths::findExecutable("nimble"))); + QString nimble; + auto bc = this->target()->activeBuildConfiguration(); + auto nimbleBuildStep = bc->buildSteps()->firstStepWithId(Constants::C_NIMBLEBUILDSTEP_ID); + if (nimbleBuildStep && nimbleBuildStep->buildSystem()) { + nimble = static_cast(nimbleBuildStep->buildSystem())->defaultNimble(); + } + + addAspect()->setExecutable(Utils::FilePath::fromString(nimble)); addAspect()->setArguments("test"); addAspect()->setDefaultWorkingDirectory(project()->projectDirectory()); addAspect(); diff --git a/src/plugins/nim/project/nimbuildsystem.cpp b/src/plugins/nim/project/nimbuildsystem.cpp index 74347691fae..01e37d5d854 100644 --- a/src/plugins/nim/project/nimbuildsystem.cpp +++ b/src/plugins/nim/project/nimbuildsystem.cpp @@ -25,16 +25,21 @@ #include "nimbuildsystem.h" +#include "nimconstants.h" #include "nimproject.h" #include "nimbleproject.h" #include "nimprojectnode.h" #include +#include +#include #include #include #include +#include + using namespace ProjectExplorer; using namespace Utils; @@ -191,6 +196,22 @@ void NimBuildSystem::triggerParsing() m_projectScanner.startScan(); } +FilePath NimBuildSystem::nimPathFromKit() const +{ + auto tc = ToolChainKitAspect::toolChain(kit(), Constants::C_NIMLANGUAGE_ID); + QTC_ASSERT(tc, return {}); + const FilePath command = tc->compilerCommand(); + return command.isEmpty() ? FilePath() : command.absolutePath(); +} + +QString NimBuildSystem::defaultNimble() const +{ + const QString nimbleFromPath = QStandardPaths::findExecutable("nimble"); + const FilePath nimPath = nimPathFromKit(); + const FilePath nimbleFromKit = nimPath.pathAppended(HostOsInfo::withExecutableSuffix("nimble")); + return nimbleFromKit.exists() ? nimbleFromKit.canonicalPath().toUserOutput() : nimbleFromPath; +} + void NimBuildSystem::loadSettings() { QVariantMap settings = project()->namedSettings(SETTINGS_KEY).toMap(); diff --git a/src/plugins/nim/project/nimbuildsystem.h b/src/plugins/nim/project/nimbuildsystem.h index 91d2e931c91..6403d454302 100644 --- a/src/plugins/nim/project/nimbuildsystem.h +++ b/src/plugins/nim/project/nimbuildsystem.h @@ -86,6 +86,9 @@ public: void triggerParsing() override; + Utils::FilePath nimPathFromKit() const; + QString defaultNimble() const; + protected: void loadSettings(); void saveSettings();