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 <hjk@qt.io>
This commit is contained in:
Christian Stenger
2020-08-31 09:52:57 +02:00
parent bbbb7d421b
commit 17e0c2b044
4 changed files with 45 additions and 5 deletions

View File

@@ -26,6 +26,8 @@
#include "nimblebuildstep.h"
#include "nimconstants.h"
#include "nimbleproject.h"
#include "nimbuildsystem.h"
#include "nimtoolchain.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/ioutputparser.h>
@@ -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<NimBuildSystem *>(buildSystem());
return CommandLine(bs->defaultNimble(),
{"build", m_arguments->arguments(macroExpander())});
});
setWorkingDirectoryProvider([this] { return project()->projectDirectory(); });
setEnvironmentModifier([this](Environment &env) {
auto bs = static_cast<NimBuildSystem *>(buildSystem());
env.appendOrSetPath(bs->nimPathFromKit().toUserOutput());
});
QTC_ASSERT(buildConfiguration(), return);
QObject::connect(buildConfiguration(), &BuildConfiguration::buildTypeChanged,

View File

@@ -24,9 +24,13 @@
****************************************************************************/
#include "nimblerunconfiguration.h"
#include "nimbuildsystem.h"
#include "nimconstants.h"
#include "nimbleproject.h"
#include <projectexplorer/buildstep.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/runcontrol.h>
@@ -35,8 +39,6 @@
#include <utils/algorithm.h>
#include <utils/environment.h>
#include <QStandardPaths>
using namespace ProjectExplorer;
namespace Nim {
@@ -89,7 +91,14 @@ public:
NimbleTestConfiguration(ProjectExplorer::Target *target, Utils::Id id)
: RunConfiguration(target, id)
{
addAspect<ExecutableAspect>()->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<NimBuildSystem *>(nimbleBuildStep->buildSystem())->defaultNimble();
}
addAspect<ExecutableAspect>()->setExecutable(Utils::FilePath::fromString(nimble));
addAspect<ArgumentsAspect>()->setArguments("test");
addAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(project()->projectDirectory());
addAspect<TerminalAspect>();

View File

@@ -25,16 +25,21 @@
#include "nimbuildsystem.h"
#include "nimconstants.h"
#include "nimproject.h"
#include "nimbleproject.h"
#include "nimprojectnode.h"
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/kitinformation.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <QStandardPaths>
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();

View File

@@ -86,6 +86,9 @@ public:
void triggerParsing() override;
Utils::FilePath nimPathFromKit() const;
QString defaultNimble() const;
protected:
void loadSettings();
void saveSettings();