CMakeProjectManager: Fix a wrong use of Target

The ConfigureEnvironmentAspect belongs to the build configuration and can
and should get all its information from there, rather than going via
Target.

Change-Id: I65edf3b2017345ba30ae53e1d78a7b88a1d6a74e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2025-03-11 12:21:29 +01:00
parent d0e454fa17
commit ba3265769d
2 changed files with 19 additions and 33 deletions

View File

@@ -2340,30 +2340,26 @@ InitialCMakeArgumentsAspect::InitialCMakeArgumentsAspect(AspectContainer *contai
class ConfigureEnvironmentAspectWidget final : public EnvironmentAspectWidget
{
public:
ConfigureEnvironmentAspectWidget(ConfigureEnvironmentAspect *aspect, Target *target)
ConfigureEnvironmentAspectWidget(ConfigureEnvironmentAspect *aspect, BuildConfiguration *bc)
: EnvironmentAspectWidget(aspect)
{
envWidget()->setOpenTerminalFunc([target](const Environment &env) {
if (BuildConfiguration *bc = target->activeBuildConfiguration())
Core::FileUtils::openTerminal(bc->buildDirectory(), env);
envWidget()->setOpenTerminalFunc([bc](const Environment &env) {
Core::FileUtils::openTerminal(bc->buildDirectory(), env);
});
}
};
ConfigureEnvironmentAspect::ConfigureEnvironmentAspect(AspectContainer *container,
BuildConfiguration *bc)
: EnvironmentAspect(container)
ConfigureEnvironmentAspect::ConfigureEnvironmentAspect(BuildConfiguration *bc)
: EnvironmentAspect(bc)
{
Target *target = bc->target();
setIsLocal(true);
setAllowPrintOnRun(false);
setConfigWidgetCreator(
[this, target] { return new ConfigureEnvironmentAspectWidget(this, target); });
setConfigWidgetCreator([this, bc] { return new ConfigureEnvironmentAspectWidget(this, bc); });
addSupportedBaseEnvironment(Tr::tr("Clean Environment"), {});
setLabelText(Tr::tr("Base environment for the CMake configure step:"));
const int systemEnvIndex = addSupportedBaseEnvironment(Tr::tr("System Environment"), [target] {
IDevice::ConstPtr device = BuildDeviceKitAspect::device(target->kit());
const int systemEnvIndex = addSupportedBaseEnvironment(Tr::tr("System Environment"), [bc] {
IDevice::ConstPtr device = BuildDeviceKitAspect::device(bc->kit());
return device ? device->systemEnvironment() : Environment::systemEnvironment();
});
@@ -2371,18 +2367,11 @@ ConfigureEnvironmentAspect::ConfigureEnvironmentAspect(AspectContainer *containe
return bc->environment();
});
connect(target,
&Target::activeBuildConfigurationChanged,
this,
&EnvironmentAspect::environmentChanged);
connect(target,
&Target::buildEnvironmentChanged,
this,
&EnvironmentAspect::environmentChanged);
connect(bc, &BuildConfiguration::environmentChanged,
this, &EnvironmentAspect::environmentChanged);
const CMakeConfigItem presetItem = CMakeConfigurationKitAspect::cmakePresetConfigItem(
target->kit());
bc->kit());
setBaseEnvironmentBase(presetItem.isNull() ? buildEnvIndex : systemEnvIndex);
@@ -2391,18 +2380,16 @@ ConfigureEnvironmentAspect::ConfigureEnvironmentAspect(AspectContainer *containe
this,
&EnvironmentAspect::environmentChanged);
connect(KitManager::instance(), &KitManager::kitUpdated, this, [this, target](const Kit *k) {
if (target->kit() == k)
connect(KitManager::instance(), &KitManager::kitUpdated, this, [this, bc](const Kit *k) {
if (bc->kit() == k)
emit EnvironmentAspect::environmentChanged();
});
addModifier([target](Utils::Environment &env) {
addModifier([bc](Utils::Environment &env) {
// This will add ninja to path
if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
bc->addToEnvironment(env);
}
target->kit()->addToBuildEnvironment(env);
env.modify(target->project()->additionalEnvironment());
bc->addToEnvironment(env);
bc->kit()->addToBuildEnvironment(env);
env.modify(bc->project()->additionalEnvironment());
});
}

View File

@@ -41,8 +41,7 @@ private:
class ConfigureEnvironmentAspect final: public ProjectExplorer::EnvironmentAspect
{
public:
ConfigureEnvironmentAspect(Utils::AspectContainer *container,
ProjectExplorer::BuildConfiguration *buildConfig);
ConfigureEnvironmentAspect(ProjectExplorer::BuildConfiguration *buildConfig);
void fromMap(const Utils::Store &map) override;
void toMap(Utils::Store &map) const override;
@@ -87,7 +86,7 @@ public:
Utils::FilePathAspect sourceDirectory{this};
Utils::StringAspect buildTypeAspect{this};
QtSupport::QmlDebuggingAspect qmlDebugging{this};
Internal::ConfigureEnvironmentAspect configureEnv{this, this};
Internal::ConfigureEnvironmentAspect configureEnv{this};
void updateInitialCMakeArguments();
QStringList initialCMakeOptions() const;