ProjectExplorer: Move makeInstallCommand()

... from Project to BuildSystem.

More direct and less use of Target::activeBuildConfiguration().

Change-Id: I148381d23be0f9ab0750ed1440e1b2b3e25aded0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-06-10 16:41:27 +02:00
parent 9a411245d3
commit f974488128
15 changed files with 70 additions and 82 deletions

View File

@@ -36,26 +36,31 @@
#include "cmakeprojectplugin.h" #include "cmakeprojectplugin.h"
#include "cmakespecificsettings.h" #include "cmakespecificsettings.h"
#include "projecttreehelper.h" #include "projecttreehelper.h"
#include "utils/algorithm.h"
#include <android/androidconstants.h> #include <android/androidconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <cppeditor/cppeditorconstants.h> #include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cppprojectupdater.h> #include <cppeditor/cppprojectupdater.h>
#include <cppeditor/generatedcodemodelsupport.h> #include <cppeditor/generatedcodemodelsupport.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h> #include <projectexplorer/taskhub.h>
#include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsmodelmanagerinterface.h>
#include <qtsupport/qtcppkitinfo.h> #include <qtsupport/qtcppkitinfo.h>
#include <qtsupport/qtkitinformation.h> #include <qtsupport/qtkitinformation.h>
#include <app/app_version.h> #include <app/app_version.h>
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h> #include <utils/checkablemessagebox.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/macroexpander.h> #include <utils/macroexpander.h>
@@ -1314,5 +1319,31 @@ void CMakeBuildSystem::updateInitialCMakeExpandableVars()
emit configurationChanged(config); 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 Internal
} // namespace CMakeProjectManager } // namespace CMakeProjectManager

View File

@@ -98,6 +98,9 @@ public:
Utils::CommandLine commandLineForTests(const QList<QString> &tests, Utils::CommandLine commandLineForTests(const QList<QString> &tests,
const QStringList &options) const final; const QStringList &options) const final;
ProjectExplorer::MakeInstallCommand makeInstallCommand(
const Utils::FilePath &installRoot) const final;
static bool filteredOutTarget(const CMakeBuildTarget &target); static bool filteredOutTarget(const CMakeBuildTarget &target);
bool isMultiConfig() const; bool isMultiConfig() const;

View File

@@ -116,40 +116,4 @@ ProjectExplorer::DeploymentKnowledge CMakeProject::deploymentKnowledge() const
: DeploymentKnowledge::Bad; : 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<CMakeBuildStep>()) {
if (CMakeTool *tool = CMakeKitAspect::cmakeTool(target->kit()))
cmd.command.setExecutable(tool->cmakeExecutable());
}
}
QString installTarget = "install";
QStringList config;
auto bs = qobject_cast<CMakeBuildSystem*>(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 } // namespace CMakeProjectManager

View File

@@ -54,8 +54,6 @@ protected:
private: private:
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override; ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override;
ProjectExplorer::MakeInstallCommand makeInstallCommand(const ProjectExplorer::Target *target,
const Utils::FilePath &installRoot) final;
mutable Internal::CMakeProjectImporter *m_projectImporter = nullptr; mutable Internal::CMakeProjectImporter *m_projectImporter = nullptr;

View File

@@ -77,14 +77,5 @@ ProjectExplorer::DeploymentKnowledge MesonProject::deploymentKnowledge() const
return ProjectExplorer::DeploymentKnowledge::Bad; 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 Internal
} // namespace MesonProjectManager } // namespace MesonProjectManager

View File

@@ -46,8 +46,6 @@ public:
private: private:
ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override; ProjectExplorer::DeploymentKnowledge deploymentKnowledge() const override;
ProjectExplorer::MakeInstallCommand makeInstallCommand(const ProjectExplorer::Target *target,
const Utils::FilePath &installRoot) final;
mutable std::unique_ptr<MesonProjectImporter> m_projectImporter; mutable std::unique_ptr<MesonProjectImporter> m_projectImporter;
}; };

View File

@@ -196,7 +196,7 @@ void BuildStepList::moveStepUp(int position)
emit stepMoved(position, position - 1); emit stepMoved(position, position - 1);
} }
BuildStep *BuildStepList::at(int position) BuildStep *BuildStepList::at(int position) const
{ {
return m_steps.at(position); return m_steps.at(position);
} }

View File

@@ -49,7 +49,7 @@ public:
QList<BuildStep *> steps() const; QList<BuildStep *> steps() const;
template <class BS> BS *firstOfType() { template <class BS> BS *firstOfType() const {
BS *bs = nullptr; BS *bs = nullptr;
for (int i = 0; i < count(); ++i) { for (int i = 0; i < count(); ++i) {
bs = qobject_cast<BS *>(at(i)); bs = qobject_cast<BS *>(at(i));
@@ -76,7 +76,7 @@ public:
bool removeStep(int position); bool removeStep(int position);
void moveStepUp(int position); void moveStepUp(int position);
BuildStep *at(int position); BuildStep *at(int position) const;
Target *target() { return m_target; } Target *target() { return m_target; }

View File

@@ -34,7 +34,11 @@
#include <coreplugin/messagemanager.h> #include <coreplugin/messagemanager.h>
#include <coreplugin/outputwindow.h> #include <coreplugin/outputwindow.h>
#include <projectexplorer/buildaspects.h> #include <projectexplorer/buildaspects.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/makestep.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -253,6 +257,22 @@ bool BuildSystem::supportsAction(Node *, ProjectAction, const Node *) const
return false; 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<MakeStep>()) {
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 FilePaths BuildSystem::filesGeneratedFrom(const FilePath &sourceFile) const
{ {
Q_UNUSED(sourceFile) Q_UNUSED(sourceFile)

View File

@@ -40,6 +40,7 @@ class CommandLine;
namespace ProjectExplorer { namespace ProjectExplorer {
class BuildConfiguration; class BuildConfiguration;
class BuildStepList;
class Node; class Node;
struct TestCaseInfo struct TestCaseInfo
@@ -103,6 +104,8 @@ public:
virtual bool supportsAction(Node *context, ProjectAction action, const Node *node) const; virtual bool supportsAction(Node *context, ProjectAction action, const Node *node) const;
virtual QString name() const = 0; virtual QString name() const = 0;
virtual MakeInstallCommand makeInstallCommand(const Utils::FilePath &installRoot) const;
virtual Utils::FilePaths filesGeneratedFrom(const Utils::FilePath &sourceFile) const; virtual Utils::FilePaths filesGeneratedFrom(const Utils::FilePath &sourceFile) const;
virtual QVariant additionalData(Utils::Id id) const; virtual QVariant additionalData(Utils::Id id) const;

View File

@@ -32,11 +32,9 @@
#include "editorconfiguration.h" #include "editorconfiguration.h"
#include "kit.h" #include "kit.h"
#include "kitinformation.h" #include "kitinformation.h"
#include "makestep.h"
#include "projectexplorer.h" #include "projectexplorer.h"
#include "projectnodes.h" #include "projectnodes.h"
#include "runconfiguration.h" #include "runconfiguration.h"
#include "runcontrol.h"
#include "session.h" #include "session.h"
#include "target.h" #include "target.h"
#include "taskhub.h" #include "taskhub.h"
@@ -971,19 +969,6 @@ bool Project::hasMakeInstallEquivalent() const
return d->m_hasMakeInstallEquivalent; 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<MakeStep>())
cmd.command.setExecutable(makeStep->makeExecutable());
}
cmd.command.addArg("install");
cmd.command.addArg("INSTALL_ROOT=" + installRoot.nativePath());
return cmd;
}
void Project::setup(const QList<BuildInfo> &infoList) void Project::setup(const QList<BuildInfo> &infoList)
{ {
std::vector<std::unique_ptr<Target>> toRegister; std::vector<std::unique_ptr<Target>> toRegister;

View File

@@ -149,8 +149,6 @@ public:
virtual DeploymentKnowledge deploymentKnowledge() const { return DeploymentKnowledge::Bad; } virtual DeploymentKnowledge deploymentKnowledge() const { return DeploymentKnowledge::Bad; }
bool hasMakeInstallEquivalent() const; bool hasMakeInstallEquivalent() const;
virtual MakeInstallCommand makeInstallCommand(const Target *target,
const Utils::FilePath &installRoot);
void setup(const QList<BuildInfo> &infoList); void setup(const QList<BuildInfo> &infoList);
Utils::MacroExpander *macroExpander() const; Utils::MacroExpander *macroExpander() const;

View File

@@ -803,11 +803,6 @@ QVariant Target::additionalData(Utils::Id id) const
return {}; return {};
} }
MakeInstallCommand Target::makeInstallCommand(const FilePath &installRoot) const
{
return project()->makeInstallCommand(this, installRoot);
}
MacroExpander *Target::macroExpander() const MacroExpander *Target::macroExpander() const
{ {
return &d->m_macroExpander; return &d->m_macroExpander;

View File

@@ -25,9 +25,12 @@
#pragma once #pragma once
#include "projectconfiguration.h"
#include "projectexplorer_export.h" #include "projectexplorer_export.h"
#include <utils/id.h>
#include <QObject>
#include <memory> #include <memory>
QT_FORWARD_DECLARE_CLASS(QIcon) QT_FORWARD_DECLARE_CLASS(QIcon)
@@ -41,7 +44,6 @@ class BuildSystem;
class DeployConfiguration; class DeployConfiguration;
class DeploymentData; class DeploymentData;
class Kit; class Kit;
class MakeInstallCommand;
class Project; class Project;
class ProjectConfigurationModel; class ProjectConfigurationModel;
class RunConfiguration; class RunConfiguration;
@@ -114,7 +116,6 @@ public:
void setNamedSettings(const QString &name, const QVariant &value); void setNamedSettings(const QString &name, const QVariant &value);
QVariant additionalData(Utils::Id id) const; QVariant additionalData(Utils::Id id) const;
MakeInstallCommand makeInstallCommand(const Utils::FilePath &installRoot) const;
Utils::MacroExpander *macroExpander() const; Utils::MacroExpander *macroExpander() const;

View File

@@ -119,7 +119,8 @@ MakeInstallStep::MakeInstallStep(BuildStepList *parent, Id id) : MakeStep(parent
QTemporaryDir tmpDir; QTemporaryDir tmpDir;
installRootAspect->setFilePath(FilePath::fromString(tmpDir.path())); 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); QTC_ASSERT(!cmd.command.isEmpty(), return);
makeAspect->setExecutable(cmd.command.executable()); makeAspect->setExecutable(cmd.command.executable());
} }
@@ -168,7 +169,8 @@ bool MakeInstallStep::init()
"last in the list of deploy steps. " "last in the list of deploy steps. "
"Consider moving it up."))); "Consider moving it up.")));
} }
const MakeInstallCommand cmd = target()->makeInstallCommand(rootDir);
const MakeInstallCommand cmd = buildSystem()->makeInstallCommand(rootDir);
if (cmd.environment.isValid()) { if (cmd.environment.isValid()) {
Environment env = processParameters()->environment(); Environment env = processParameters()->environment();
for (auto it = cmd.environment.constBegin(); it != cmd.environment.constEnd(); ++it) { for (auto it = cmd.environment.constBegin(); it != cmd.environment.constEnd(); ++it) {
@@ -255,8 +257,7 @@ void MakeInstallStep::updateArgsFromAspect()
{ {
if (customCommandLineAspect()->isChecked()) if (customCommandLineAspect()->isChecked())
return; return;
const CommandLine cmd = buildSystem()->makeInstallCommand(installRoot()).command;
const CommandLine cmd = target()->makeInstallCommand(installRoot()).command;
setUserArguments(cmd.arguments()); setUserArguments(cmd.arguments());
updateFullCommandLine(); updateFullCommandLine();
} }