ProjectExplorer: Merge LocalEnvironmentAspect into EnvironmentAspect

This still has some not quite orthogonal features in one blob function,
but at least it's not a separate class anymore.

A step forward to remote support in places where it could make sense.

Change-Id: Ia02003e4340eb2b5ee92bd48c00006a487527828
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-05-25 08:58:36 +02:00
parent 85f1633562
commit 6c66b900db
14 changed files with 45 additions and 84 deletions

View File

@@ -9,7 +9,6 @@
#include "haskellsettings.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/target.h>
@@ -35,7 +34,8 @@ HaskellExecutableAspect::HaskellExecutableAspect()
HaskellRunConfiguration::HaskellRunConfiguration(Target *target, Utils::Id id)
: RunConfiguration(target, id)
{
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
addAspect<HaskellExecutableAspect>();
addAspect<ArgumentsAspect>(macroExpander());
@@ -67,7 +67,7 @@ Runnable HaskellRunConfiguration::runnable() const
args << "--" << arguments;
r.workingDirectory = projectDirectory;
r.environment = aspect<LocalEnvironmentAspect>()->environment();
r.environment = aspect<EnvironmentAspect>()->environment();
r.command = {r.environment.searchInPath(settings().stackPath().path()), args};
return r;
}

View File

@@ -8,7 +8,6 @@
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/desktoprunconfiguration.h>
#include <projectexplorer/environmentaspect.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
@@ -24,7 +23,8 @@ namespace Internal {
MesonRunConfiguration::MesonRunConfiguration(Target *target, Utils::Id id)
: RunConfiguration{target, id}
{
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
addAspect<ArgumentsAspect>(macroExpander());
@@ -65,7 +65,7 @@ void MesonRunConfiguration::updateTargetInformation()
aspect<TerminalAspect>()->setUseTerminalHint(bti.usesTerminal);
aspect<ExecutableAspect>()->setExecutable(bti.targetFilePath);
aspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.workingDirectory);
emit aspect<LocalEnvironmentAspect>()->environmentChanged();
emit aspect<EnvironmentAspect>()->environmentChanged();
}
MesonRunConfigurationFactory::MesonRunConfigurationFactory()

View File

@@ -7,7 +7,6 @@
#include "nimconstants.h"
#include "nimtr.h"
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
@@ -27,7 +26,9 @@ public:
NimbleRunConfiguration(Target *target, Utils::Id id)
: RunConfiguration(target, id)
{
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
addAspect<ArgumentsAspect>(macroExpander());
addAspect<WorkingDirectoryAspect>(macroExpander(), envAspect);

View File

@@ -8,7 +8,6 @@
#include "../nimtr.h"
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <utils/qtcassert.h>
@@ -27,7 +26,9 @@ public:
NimRunConfiguration(Target *target, Utils::Id id)
: RunConfiguration(target, id)
{
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
addAspect<ArgumentsAspect>(macroExpander());
addAspect<WorkingDirectoryAspect>(macroExpander(), envAspect);

View File

@@ -115,7 +115,6 @@ add_qtc_plugin(ProjectExplorer
ldparser.cpp ldparser.h
lldparser.cpp lldparser.h
linuxiccparser.cpp linuxiccparser.h
localenvironmentaspect.cpp localenvironmentaspect.h
makestep.cpp makestep.h
miniprojecttargetselector.cpp miniprojecttargetselector.h
msvcparser.cpp msvcparser.h

View File

@@ -3,7 +3,6 @@
#include "customexecutablerunconfiguration.h"
#include "localenvironmentaspect.h"
#include "projectexplorerconstants.h"
#include "projectexplorertr.h"
#include "runconfigurationaspects.h"
@@ -24,7 +23,8 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id)
{
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
auto exeAspect = addAspect<ExecutableAspect>(target, ExecutableAspect::HostDevice);
exeAspect->setSettingsKey("ProjectExplorer.CustomExecutableRunConfiguration.Executable");

View File

@@ -4,7 +4,6 @@
#include "desktoprunconfiguration.h"
#include "buildsystem.h"
#include "localenvironmentaspect.h"
#include "projectexplorerconstants.h"
#include "projectexplorertr.h"
#include "runconfigurationaspects.h"
@@ -43,7 +42,8 @@ private:
DesktopRunConfiguration::DesktopRunConfiguration(Target *target, Id id, Kind kind)
: RunConfiguration(target, id), m_kind(kind)
{
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
addAspect<ArgumentsAspect>(macroExpander());
@@ -122,7 +122,7 @@ void DesktopRunConfiguration::updateTargetInformation()
aspect<ExecutableAspect>()->setExecutable(bti.targetFilePath);
aspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.workingDirectory);
emit aspect<LocalEnvironmentAspect>()->environmentChanged();
emit aspect<EnvironmentAspect>()->environmentChanged();
}
}

View File

@@ -3,8 +3,11 @@
#include "environmentaspect.h"
#include "buildconfiguration.h"
#include "environmentaspectwidget.h"
#include "kit.h"
#include "projectexplorertr.h"
#include "target.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
@@ -102,6 +105,27 @@ int EnvironmentAspect::addPreferredBaseEnvironment(const QString &displayName,
return index;
}
void EnvironmentAspect::setSupportForBuildEnvironment(Target *target)
{
setIsLocal(true);
addSupportedBaseEnvironment(Tr::tr("Clean Environment"), {});
addSupportedBaseEnvironment(Tr::tr("System Environment"), [] {
return Environment::systemEnvironment();
});
addPreferredBaseEnvironment(Tr::tr("Build Environment"), [target] {
if (BuildConfiguration *bc = target->activeBuildConfiguration())
return bc->environment();
// Fallback for targets without buildconfigurations:
return target->kit()->buildEnvironment();
});
connect(target, &Target::activeBuildConfigurationChanged,
this, &EnvironmentAspect::environmentChanged);
connect(target, &Target::buildEnvironmentChanged,
this, &EnvironmentAspect::environmentChanged);
}
void EnvironmentAspect::fromMap(const QVariantMap &map)
{
m_base = map.value(QLatin1String(BASE_KEY), -1).toInt();

View File

@@ -39,6 +39,8 @@ public:
int addPreferredBaseEnvironment(const QString &displayName,
const std::function<Utils::Environment()> &getter);
void setSupportForBuildEnvironment(Target *target);
QString currentDisplayName() const;
const QStringList displayNames() const;

View File

@@ -1,46 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "localenvironmentaspect.h"
#include "buildconfiguration.h"
#include "kit.h"
#include "projectexplorertr.h"
#include "target.h"
using namespace Utils;
namespace ProjectExplorer {
LocalEnvironmentAspect::LocalEnvironmentAspect(Target *target, bool includeBuildEnvironment)
{
setIsLocal(true);
addSupportedBaseEnvironment(Tr::tr("Clean Environment"), {});
addSupportedBaseEnvironment(Tr::tr("System Environment"), [] {
return Environment::systemEnvironment();
});
if (includeBuildEnvironment) {
addPreferredBaseEnvironment(Tr::tr("Build Environment"), [target] {
Environment env;
if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
env = bc->environment();
} else { // Fallback for targets without buildconfigurations:
env = target->kit()->buildEnvironment();
}
return env;
});
connect(target,
&Target::activeBuildConfigurationChanged,
this,
&EnvironmentAspect::environmentChanged);
connect(target,
&Target::buildEnvironmentChanged,
this,
&EnvironmentAspect::environmentChanged);
}
}
} // namespace ProjectExplorer

View File

@@ -1,18 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "environmentaspect.h"
namespace ProjectExplorer {
class PROJECTEXPLORER_EXPORT LocalEnvironmentAspect : public EnvironmentAspect
{
Q_OBJECT
public:
explicit LocalEnvironmentAspect(Target *parent, bool includeBuildEnvironment = true);
};
} // namespace ProjectExplorer

View File

@@ -92,7 +92,6 @@ Project {
"ldparser.cpp", "ldparser.h",
"lldparser.cpp", "lldparser.h",
"linuxiccparser.cpp", "linuxiccparser.h",
"localenvironmentaspect.cpp", "localenvironmentaspect.h",
"makestep.cpp", "makestep.h",
"miniprojecttargetselector.cpp", "miniprojecttargetselector.h",
"msvcparser.cpp", "msvcparser.h",

View File

@@ -12,7 +12,6 @@
#include <projectexplorer/buildtargetinfo.h>
#include <projectexplorer/jsonwizard/jsonwizardfactory.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/taskhub.h>

View File

@@ -24,7 +24,6 @@
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
@@ -190,7 +189,8 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id)
scriptAspect->setLabelText(Tr::tr("Script:"));
scriptAspect->setDisplayStyle(StringAspect::LabelDisplay);
addAspect<LocalEnvironmentAspect>(target);
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
auto argumentsAspect = addAspect<ArgumentsAspect>(macroExpander());