Files
qt-creator/src/plugins/nim/project/nimblerunconfiguration.cpp
hjk 739f835ef1 ProjectExplorer: Remove unusual {Arguments,WorkingDir}Aspect
Follows suite to 2cc4967 to have the user side code more uniform.
Most of the extra verbosity (setMacroExpander) can go away again
when distributing the expander via the "owning" AspectContainer.

Change-Id: I9e80cb235f0a4a9ebee601dd638aefbaa41efc1b
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2023-07-05 12:55:31 +00:00

100 lines
3.2 KiB
C++

// Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "nimblerunconfiguration.h"
#include "nimbuildsystem.h"
#include "nimconstants.h"
#include "nimtr.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
#include <utils/algorithm.h>
#include <utils/environment.h>
using namespace ProjectExplorer;
namespace Nim {
// NimbleRunConfiguration
class NimbleRunConfiguration : public RunConfiguration
{
public:
NimbleRunConfiguration(Target *target, Utils::Id id)
: RunConfiguration(target, id)
{
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
auto exeAspect = addAspect<ExecutableAspect>();
exeAspect->setDeviceSelector(target, ExecutableAspect::RunDevice);
auto argsAspect = addAspect<ArgumentsAspect>();
argsAspect->setMacroExpander(macroExpander());
auto workingDirAspect = addAspect<WorkingDirectoryAspect>();
workingDirAspect->setMacroExpander(macroExpander());
addAspect<TerminalAspect>();
setUpdater([this] {
BuildTargetInfo bti = buildTargetInfo();
setDisplayName(bti.displayName);
setDefaultDisplayName(bti.displayName);
aspect<ExecutableAspect>()->setExecutable(bti.targetFilePath);
aspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.workingDirectory);
});
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
update();
}
};
NimbleRunConfigurationFactory::NimbleRunConfigurationFactory()
: RunConfigurationFactory()
{
registerRunConfiguration<NimbleRunConfiguration>("Nim.NimbleRunConfiguration");
addSupportedProjectType(Constants::C_NIMBLEPROJECT_ID);
addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
}
// NimbleTestConfiguration
class NimbleTestConfiguration : public RunConfiguration
{
public:
NimbleTestConfiguration(ProjectExplorer::Target *target, Utils::Id id)
: RunConfiguration(target, id)
{
auto exeAspect = addAspect<ExecutableAspect>();
exeAspect->setDeviceSelector(target, ExecutableAspect::BuildDevice);
exeAspect->setExecutable(Nim::nimblePathFromKit(target->kit()));
auto argsAspect = addAspect<ArgumentsAspect>();
argsAspect->setMacroExpander(macroExpander());
argsAspect->setArguments("test");
auto workingDirAspect = addAspect<WorkingDirectoryAspect>();
workingDirAspect->setMacroExpander(macroExpander());
workingDirAspect->setDefaultWorkingDirectory(project()->projectDirectory());
addAspect<TerminalAspect>();
setDisplayName(Tr::tr("Nimble Test"));
setDefaultDisplayName(Tr::tr("Nimble Test"));
}
};
NimbleTestConfigurationFactory::NimbleTestConfigurationFactory()
: FixedRunConfigurationFactory(QString())
{
registerRunConfiguration<NimbleTestConfiguration>("Nim.NimbleTestConfiguration");
addSupportedProjectType(Constants::C_NIMBLEPROJECT_ID);
}
} // Nim