From f97448812860c682e5e7cf716478c8ee24a577be Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 10 Jun 2022 16:41:27 +0200 Subject: [PATCH] ProjectExplorer: Move makeInstallCommand() ... from Project to BuildSystem. More direct and less use of Target::activeBuildConfiguration(). Change-Id: I148381d23be0f9ab0750ed1440e1b2b3e25aded0 Reviewed-by: Christian Kandeler --- .../cmakeprojectmanager/cmakebuildsystem.cpp | 33 ++++++++++++++++- .../cmakeprojectmanager/cmakebuildsystem.h | 3 ++ .../cmakeprojectmanager/cmakeproject.cpp | 36 ------------------- .../cmakeprojectmanager/cmakeproject.h | 2 -- .../project/mesonproject.cpp | 9 ----- .../project/mesonproject.h | 2 -- src/plugins/projectexplorer/buildsteplist.cpp | 2 +- src/plugins/projectexplorer/buildsteplist.h | 4 +-- src/plugins/projectexplorer/buildsystem.cpp | 20 +++++++++++ src/plugins/projectexplorer/buildsystem.h | 3 ++ src/plugins/projectexplorer/project.cpp | 15 -------- src/plugins/projectexplorer/project.h | 2 -- src/plugins/projectexplorer/target.cpp | 5 --- src/plugins/projectexplorer/target.h | 7 ++-- src/plugins/remotelinux/makeinstallstep.cpp | 9 ++--- 15 files changed, 70 insertions(+), 82 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index 0ce9e360e29..5add4f4e559 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -36,26 +36,31 @@ #include "cmakeprojectplugin.h" #include "cmakespecificsettings.h" #include "projecttreehelper.h" -#include "utils/algorithm.h" #include + #include #include + #include #include #include + +#include #include #include #include #include #include #include + #include #include #include #include +#include #include #include #include @@ -1314,5 +1319,31 @@ void CMakeBuildSystem::updateInitialCMakeExpandableVars() emit configurationChanged(config); } +MakeInstallCommand CMakeBuildSystem::makeInstallCommand(const FilePath &installRoot) const +{ + MakeInstallCommand cmd; + if (CMakeTool *tool = CMakeKitAspect::cmakeTool(target()->kit())) + cmd.command.setExecutable(tool->cmakeExecutable()); + + QString installTarget = "install"; + if (usesAllCapsTargets()) + installTarget = "INSTALL"; + + FilePath buildDirectory = "."; + if (auto bc = buildConfiguration()) + buildDirectory = bc->buildDirectory(); + + cmd.command.addArg("--build"); + cmd.command.addArg(buildDirectory.onDevice(cmd.command.executable()).path()); + cmd.command.addArg("--target"); + cmd.command.addArg(installTarget); + + if (isMultiConfigReader()) + cmd.command.addArgs({"--config", cmakeBuildType()}); + + cmd.environment.set("DESTDIR", installRoot.nativePath()); + return cmd; +} + } // namespace Internal } // namespace CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.h b/src/plugins/cmakeprojectmanager/cmakebuildsystem.h index bb505b65f34..5ebfd6dfbe0 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.h +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.h @@ -98,6 +98,9 @@ public: Utils::CommandLine commandLineForTests(const QList &tests, const QStringList &options) const final; + ProjectExplorer::MakeInstallCommand makeInstallCommand( + const Utils::FilePath &installRoot) const final; + static bool filteredOutTarget(const CMakeBuildTarget &target); bool isMultiConfig() const; diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 445e9b1ab3b..ee6696b0e62 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -116,40 +116,4 @@ ProjectExplorer::DeploymentKnowledge CMakeProject::deploymentKnowledge() const : DeploymentKnowledge::Bad; } -MakeInstallCommand CMakeProject::makeInstallCommand(const Target *target, - const FilePath &installRoot) -{ - MakeInstallCommand cmd; - if (const BuildConfiguration * const bc = target->activeBuildConfiguration()) { - if (const auto cmakeStep = bc->buildSteps()->firstOfType()) { - if (CMakeTool *tool = CMakeKitAspect::cmakeTool(target->kit())) - cmd.command.setExecutable(tool->cmakeExecutable()); - } - } - - QString installTarget = "install"; - QStringList config; - - auto bs = qobject_cast(target->buildSystem()); - QTC_ASSERT(bs, return {}); - - if (bs->usesAllCapsTargets()) - installTarget = "INSTALL"; - if (bs->isMultiConfigReader()) - config << "--config" << bs->cmakeBuildType(); - - FilePath buildDirectory = "."; - if (auto bc = bs->buildConfiguration()) - buildDirectory = bc->buildDirectory(); - - cmd.command.addArg("--build"); - cmd.command.addArg(buildDirectory.onDevice(cmd.command.executable()).path()); - cmd.command.addArg("--target"); - cmd.command.addArg(installTarget); - cmd.command.addArgs(config); - - cmd.environment.set("DESTDIR", installRoot.nativePath()); - return cmd; -} - } // namespace CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index a1f1db439d4..33239234046 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -54,8 +54,6 @@ protected: private: ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override; - ProjectExplorer::MakeInstallCommand makeInstallCommand(const ProjectExplorer::Target *target, - const Utils::FilePath &installRoot) final; mutable Internal::CMakeProjectImporter *m_projectImporter = nullptr; diff --git a/src/plugins/mesonprojectmanager/project/mesonproject.cpp b/src/plugins/mesonprojectmanager/project/mesonproject.cpp index 2406e35755f..4b770f2793f 100644 --- a/src/plugins/mesonprojectmanager/project/mesonproject.cpp +++ b/src/plugins/mesonprojectmanager/project/mesonproject.cpp @@ -77,14 +77,5 @@ ProjectExplorer::DeploymentKnowledge MesonProject::deploymentKnowledge() const return ProjectExplorer::DeploymentKnowledge::Bad; } -ProjectExplorer::MakeInstallCommand MesonProject::makeInstallCommand(const ProjectExplorer::Target *target, - const Utils::FilePath &installRoot) -{ - Q_UNUSED(target) - Q_UNUSED(installRoot) - // TODO in next releases - return {}; -} - } // namespace Internal } // namespace MesonProjectManager diff --git a/src/plugins/mesonprojectmanager/project/mesonproject.h b/src/plugins/mesonprojectmanager/project/mesonproject.h index e07b82aa56b..29920b03fa7 100644 --- a/src/plugins/mesonprojectmanager/project/mesonproject.h +++ b/src/plugins/mesonprojectmanager/project/mesonproject.h @@ -46,8 +46,6 @@ public: private: ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override; - ProjectExplorer::MakeInstallCommand makeInstallCommand(const ProjectExplorer::Target *target, - const Utils::FilePath &installRoot) final; mutable std::unique_ptr m_projectImporter; }; diff --git a/src/plugins/projectexplorer/buildsteplist.cpp b/src/plugins/projectexplorer/buildsteplist.cpp index 0a60422dbb1..de9f7611717 100644 --- a/src/plugins/projectexplorer/buildsteplist.cpp +++ b/src/plugins/projectexplorer/buildsteplist.cpp @@ -196,7 +196,7 @@ void BuildStepList::moveStepUp(int position) emit stepMoved(position, position - 1); } -BuildStep *BuildStepList::at(int position) +BuildStep *BuildStepList::at(int position) const { return m_steps.at(position); } diff --git a/src/plugins/projectexplorer/buildsteplist.h b/src/plugins/projectexplorer/buildsteplist.h index 49c0f8b206b..4d55a4a023f 100644 --- a/src/plugins/projectexplorer/buildsteplist.h +++ b/src/plugins/projectexplorer/buildsteplist.h @@ -49,7 +49,7 @@ public: QList steps() const; - template BS *firstOfType() { + template BS *firstOfType() const { BS *bs = nullptr; for (int i = 0; i < count(); ++i) { bs = qobject_cast(at(i)); @@ -76,7 +76,7 @@ public: bool removeStep(int position); void moveStepUp(int position); - BuildStep *at(int position); + BuildStep *at(int position) const; Target *target() { return m_target; } diff --git a/src/plugins/projectexplorer/buildsystem.cpp b/src/plugins/projectexplorer/buildsystem.cpp index 1cfeec74c23..930416f3bef 100644 --- a/src/plugins/projectexplorer/buildsystem.cpp +++ b/src/plugins/projectexplorer/buildsystem.cpp @@ -34,7 +34,11 @@ #include #include + #include +#include +#include + #include #include @@ -253,6 +257,22 @@ bool BuildSystem::supportsAction(Node *, ProjectAction, const Node *) const return false; } +MakeInstallCommand BuildSystem::makeInstallCommand(const FilePath &installRoot) const +{ + QTC_ASSERT(target()->project()->hasMakeInstallEquivalent(), return {}); + + BuildStepList *buildSteps = buildConfiguration()->buildSteps(); + QTC_ASSERT(buildSteps, return {}); + + MakeInstallCommand cmd; + if (const auto makeStep = buildSteps->firstOfType()) { + cmd.command.setExecutable(makeStep->makeExecutable()); + cmd.command.addArg("install"); + cmd.command.addArg("INSTALL_ROOT=" + installRoot.nativePath()); + } + return cmd; +} + FilePaths BuildSystem::filesGeneratedFrom(const FilePath &sourceFile) const { Q_UNUSED(sourceFile) diff --git a/src/plugins/projectexplorer/buildsystem.h b/src/plugins/projectexplorer/buildsystem.h index 263738d8e45..e9bcd90edaf 100644 --- a/src/plugins/projectexplorer/buildsystem.h +++ b/src/plugins/projectexplorer/buildsystem.h @@ -40,6 +40,7 @@ class CommandLine; namespace ProjectExplorer { class BuildConfiguration; +class BuildStepList; class Node; struct TestCaseInfo @@ -103,6 +104,8 @@ public: virtual bool supportsAction(Node *context, ProjectAction action, const Node *node) const; virtual QString name() const = 0; + virtual MakeInstallCommand makeInstallCommand(const Utils::FilePath &installRoot) const; + virtual Utils::FilePaths filesGeneratedFrom(const Utils::FilePath &sourceFile) const; virtual QVariant additionalData(Utils::Id id) const; diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index 23998359fb4..cd0c64aec34 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -32,11 +32,9 @@ #include "editorconfiguration.h" #include "kit.h" #include "kitinformation.h" -#include "makestep.h" #include "projectexplorer.h" #include "projectnodes.h" #include "runconfiguration.h" -#include "runcontrol.h" #include "session.h" #include "target.h" #include "taskhub.h" @@ -971,19 +969,6 @@ bool Project::hasMakeInstallEquivalent() const return d->m_hasMakeInstallEquivalent; } -MakeInstallCommand Project::makeInstallCommand(const Target *target, const FilePath &installRoot) -{ - QTC_ASSERT(hasMakeInstallEquivalent(), return MakeInstallCommand()); - MakeInstallCommand cmd; - if (const BuildConfiguration * const bc = target->activeBuildConfiguration()) { - if (const auto makeStep = bc->buildSteps()->firstOfType()) - cmd.command.setExecutable(makeStep->makeExecutable()); - } - cmd.command.addArg("install"); - cmd.command.addArg("INSTALL_ROOT=" + installRoot.nativePath()); - return cmd; -} - void Project::setup(const QList &infoList) { std::vector> toRegister; diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index 36cb94feeb0..039d191c1be 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -149,8 +149,6 @@ public: virtual DeploymentKnowledge deploymentKnowledge() const { return DeploymentKnowledge::Bad; } bool hasMakeInstallEquivalent() const; - virtual MakeInstallCommand makeInstallCommand(const Target *target, - const Utils::FilePath &installRoot); void setup(const QList &infoList); Utils::MacroExpander *macroExpander() const; diff --git a/src/plugins/projectexplorer/target.cpp b/src/plugins/projectexplorer/target.cpp index 76de5d0da66..964461bfb5a 100644 --- a/src/plugins/projectexplorer/target.cpp +++ b/src/plugins/projectexplorer/target.cpp @@ -803,11 +803,6 @@ QVariant Target::additionalData(Utils::Id id) const return {}; } -MakeInstallCommand Target::makeInstallCommand(const FilePath &installRoot) const -{ - return project()->makeInstallCommand(this, installRoot); -} - MacroExpander *Target::macroExpander() const { return &d->m_macroExpander; diff --git a/src/plugins/projectexplorer/target.h b/src/plugins/projectexplorer/target.h index a5503ff833b..b1ff67c2d2f 100644 --- a/src/plugins/projectexplorer/target.h +++ b/src/plugins/projectexplorer/target.h @@ -25,9 +25,12 @@ #pragma once -#include "projectconfiguration.h" #include "projectexplorer_export.h" +#include + +#include + #include QT_FORWARD_DECLARE_CLASS(QIcon) @@ -41,7 +44,6 @@ class BuildSystem; class DeployConfiguration; class DeploymentData; class Kit; -class MakeInstallCommand; class Project; class ProjectConfigurationModel; class RunConfiguration; @@ -114,7 +116,6 @@ public: void setNamedSettings(const QString &name, const QVariant &value); QVariant additionalData(Utils::Id id) const; - MakeInstallCommand makeInstallCommand(const Utils::FilePath &installRoot) const; Utils::MacroExpander *macroExpander() const; diff --git a/src/plugins/remotelinux/makeinstallstep.cpp b/src/plugins/remotelinux/makeinstallstep.cpp index c61df08f6cc..d676a26f46d 100644 --- a/src/plugins/remotelinux/makeinstallstep.cpp +++ b/src/plugins/remotelinux/makeinstallstep.cpp @@ -119,7 +119,8 @@ MakeInstallStep::MakeInstallStep(BuildStepList *parent, Id id) : MakeStep(parent QTemporaryDir tmpDir; installRootAspect->setFilePath(FilePath::fromString(tmpDir.path())); - const MakeInstallCommand cmd = target()->makeInstallCommand(FilePath::fromString(tmpDir.path())); + const MakeInstallCommand cmd = + buildSystem()->makeInstallCommand(FilePath::fromString(tmpDir.path())); QTC_ASSERT(!cmd.command.isEmpty(), return); makeAspect->setExecutable(cmd.command.executable()); } @@ -168,7 +169,8 @@ bool MakeInstallStep::init() "last in the list of deploy steps. " "Consider moving it up."))); } - const MakeInstallCommand cmd = target()->makeInstallCommand(rootDir); + + const MakeInstallCommand cmd = buildSystem()->makeInstallCommand(rootDir); if (cmd.environment.isValid()) { Environment env = processParameters()->environment(); for (auto it = cmd.environment.constBegin(); it != cmd.environment.constEnd(); ++it) { @@ -255,8 +257,7 @@ void MakeInstallStep::updateArgsFromAspect() { if (customCommandLineAspect()->isChecked()) return; - - const CommandLine cmd = target()->makeInstallCommand(installRoot()).command; + const CommandLine cmd = buildSystem()->makeInstallCommand(installRoot()).command; setUserArguments(cmd.arguments()); updateFullCommandLine(); }