ProjectExplorer: De-virtualize EnvironmentAspect::baseEnvironment

Will help to streamline *EnvironmentAspect constructor signature,
which in turn will help to have a generic cloning mechanism to
clone aspect data, which in turn will help to finally execute on
the idea that RunControls should be re-runnable in their original
setup and also resilient to changes in the setup while they are
running.

Change-Id: Ibdaca487c1f7ce043e675fd014fe923a70273639
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-03-07 09:08:40 +01:00
parent 2f02dcf994
commit ac1b0facc0
16 changed files with 88 additions and 262 deletions

View File

@@ -50,8 +50,7 @@ HEADERS += \
androidsdkmanagerwidget.h \ androidsdkmanagerwidget.h \
androidpackageinstallationstep.h \ androidpackageinstallationstep.h \
androidextralibrarylistmodel.h \ androidextralibrarylistmodel.h \
createandroidmanifestwizard.h \ createandroidmanifestwizard.h
androidrunenvironmentaspect.h
SOURCES += \ SOURCES += \
androidconfigurations.cpp \ androidconfigurations.cpp \
@@ -95,8 +94,7 @@ SOURCES += \
androidsdkmanagerwidget.cpp \ androidsdkmanagerwidget.cpp \
androidpackageinstallationstep.cpp \ androidpackageinstallationstep.cpp \
androidextralibrarylistmodel.cpp \ androidextralibrarylistmodel.cpp \
createandroidmanifestwizard.cpp \ createandroidmanifestwizard.cpp
androidrunenvironmentaspect.cpp
FORMS += \ FORMS += \
androidsettingswidget.ui \ androidsettingswidget.ui \

View File

@@ -75,8 +75,6 @@ Project {
"androidqtversion.h", "androidqtversion.h",
"androidrunconfiguration.cpp", "androidrunconfiguration.cpp",
"androidrunconfiguration.h", "androidrunconfiguration.h",
"androidrunenvironmentaspect.h",
"androidrunenvironmentaspect.cpp",
"androidruncontrol.cpp", "androidruncontrol.cpp",
"androidruncontrol.h", "androidruncontrol.h",
"androidrunner.cpp", "androidrunner.cpp",

View File

@@ -30,7 +30,6 @@
#include "androidtoolchain.h" #include "androidtoolchain.h"
#include "androidmanager.h" #include "androidmanager.h"
#include "adbcommandswidget.h" #include "adbcommandswidget.h"
#include "androidrunenvironmentaspect.h"
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
@@ -108,7 +107,11 @@ void BaseStringListAspect::setLabel(const QString &label)
AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id) AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
addAspect<AndroidRunEnvironmentAspect>(); enum BaseEnvironmentBase { CleanEnvironmentBase };
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
envAspect->setBaseEnvironmentGetter([] { return Utils::Environment(); });
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
auto amStartArgsAspect = addAspect<BaseStringAspect>(); auto amStartArgsAspect = addAspect<BaseStringAspect>();

View File

@@ -1,47 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "androidrunenvironmentaspect.h"
namespace {
enum BaseEnvironmentBase {
CleanEnvironmentBase
};
}
namespace Android {
AndroidRunEnvironmentAspect::AndroidRunEnvironmentAspect()
{
addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
}
Utils::Environment AndroidRunEnvironmentAspect::baseEnvironment() const
{
// Clean Environment
return Utils::Environment();
}
} // namespace Android

View File

@@ -1,42 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <projectexplorer/environmentaspect.h>
namespace Android {
class AndroidRunEnvironmentAspect : public ProjectExplorer::EnvironmentAspect
{
Q_OBJECT
public:
AndroidRunEnvironmentAspect();
Utils::Environment baseEnvironment() const override;
};
} // namespace Android

View File

@@ -113,4 +113,15 @@ void EnvironmentAspect::toMap(QVariantMap &data) const
data.insert(QLatin1String(CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_changes)); data.insert(QLatin1String(CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_changes));
} }
Utils::Environment EnvironmentAspect::baseEnvironment() const
{
QTC_ASSERT(m_baseEnvironmentGetter, return Utils::Environment());
return m_baseEnvironmentGetter();
}
void EnvironmentAspect::setBaseEnvironmentGetter(const std::function<Utils::Environment ()> &getter)
{
m_baseEnvironmentGetter = getter;
}
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -41,8 +41,12 @@ class PROJECTEXPLORER_EXPORT EnvironmentAspect : public ProjectConfigurationAspe
Q_OBJECT Q_OBJECT
public: public:
EnvironmentAspect();
// The environment the user chose as base for his modifications. // The environment the user chose as base for his modifications.
virtual Utils::Environment baseEnvironment() const = 0; Utils::Environment baseEnvironment() const;
void setBaseEnvironmentGetter(const std::function<Utils::Environment ()> &getter);
// The environment including the user's modifications. // The environment including the user's modifications.
Utils::Environment environment() const; Utils::Environment environment() const;
@@ -64,12 +68,12 @@ signals:
void environmentChanged(); void environmentChanged();
protected: protected:
EnvironmentAspect();
void fromMap(const QVariantMap &map) override; void fromMap(const QVariantMap &map) override;
void toMap(QVariantMap &map) const override; void toMap(QVariantMap &map) const override;
private: private:
int m_base = -1; int m_base = -1;
std::function<Utils::Environment()> m_baseEnvironmentGetter;
QList<Utils::EnvironmentItem> m_changes; QList<Utils::EnvironmentItem> m_changes;
QMap<int, QString> m_displayNames; QMap<int, QString> m_displayNames;
}; };

View File

@@ -40,25 +40,37 @@ enum BaseEnvironmentBase {
BuildEnvironmentBase BuildEnvironmentBase
}; };
Utils::Environment LocalEnvironmentAspect::baseEnvironment() const LocalEnvironmentAspect::LocalEnvironmentAspect(Target *target,
const BaseEnvironmentModifier &modifier)
{ {
int base = baseEnvironmentBase(); addPreferredBaseEnvironment(BuildEnvironmentBase, tr("Build Environment"));
Utils::Environment env; addSupportedBaseEnvironment(SystemEnvironmentBase, tr("System Environment"));
if (base == static_cast<int>(BuildEnvironmentBase)) { addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
if (BuildConfiguration *bc = m_target->activeBuildConfiguration()) {
env = bc->environment(); target->subscribeSignal(&BuildConfiguration::environmentChanged,
} else { // Fallback for targets without buildconfigurations: this, &LocalEnvironmentAspect::buildEnvironmentHasChanged);
connect(target, &Target::activeBuildConfigurationChanged,
this, &LocalEnvironmentAspect::buildEnvironmentHasChanged);
setBaseEnvironmentGetter([this, target, modifier] {
int base = baseEnvironmentBase();
Utils::Environment env;
if (base == static_cast<int>(BuildEnvironmentBase)) {
if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
env = bc->environment();
} else { // Fallback for targets without buildconfigurations:
env = Utils::Environment::systemEnvironment();
target->kit()->addToEnvironment(env);
}
} else if (base == static_cast<int>(SystemEnvironmentBase)) {
env = Utils::Environment::systemEnvironment(); env = Utils::Environment::systemEnvironment();
m_target->kit()->addToEnvironment(env);
} }
} else if (base == static_cast<int>(SystemEnvironmentBase)) {
env = Utils::Environment::systemEnvironment();
}
if (m_baseEnvironmentModifier) if (modifier)
m_baseEnvironmentModifier(env); modifier(env);
return env; return env;
});
} }
void LocalEnvironmentAspect::buildEnvironmentHasChanged() void LocalEnvironmentAspect::buildEnvironmentHasChanged()
@@ -67,19 +79,4 @@ void LocalEnvironmentAspect::buildEnvironmentHasChanged()
emit environmentChanged(); emit environmentChanged();
} }
LocalEnvironmentAspect::LocalEnvironmentAspect(Target *target,
const BaseEnvironmentModifier &modifier) :
m_baseEnvironmentModifier(modifier),
m_target(target)
{
addPreferredBaseEnvironment(BuildEnvironmentBase, tr("Build Environment"));
addSupportedBaseEnvironment(SystemEnvironmentBase, tr("System Environment"));
addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
m_target->subscribeSignal(&BuildConfiguration::environmentChanged,
this, &LocalEnvironmentAspect::buildEnvironmentHasChanged);
connect(m_target, &Target::activeBuildConfigurationChanged,
this, &LocalEnvironmentAspect::buildEnvironmentHasChanged);
}
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -37,13 +37,7 @@ public:
using BaseEnvironmentModifier = std::function<void(Utils::Environment &)>; using BaseEnvironmentModifier = std::function<void(Utils::Environment &)>;
LocalEnvironmentAspect(Target *parent, const BaseEnvironmentModifier &modifier); LocalEnvironmentAspect(Target *parent, const BaseEnvironmentModifier &modifier);
Utils::Environment baseEnvironment() const override;
void buildEnvironmentHasChanged(); void buildEnvironmentHasChanged();
private:
BaseEnvironmentModifier m_baseEnvironmentModifier;
Target *m_target;
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -1,66 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "qmlprojectenvironmentaspect.h"
#include "qmlproject.h"
#include <projectexplorer/kit.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/target.h>
using namespace ProjectExplorer;
using namespace Utils;
namespace QmlProjectManager {
enum BaseEnvironmentBase {
SystemEnvironmentBase = 0,
CleanEnvironmentBase
};
Environment QmlProjectEnvironmentAspect::baseEnvironment() const
{
Environment env = baseEnvironmentBase() == SystemEnvironmentBase
? Environment::systemEnvironment()
: Environment();
if (auto project = qobject_cast<const QmlProject *>(m_target->project()))
env.modify(project->environment());
return env;
}
QmlProjectEnvironmentAspect::QmlProjectEnvironmentAspect(Target *target)
: m_target(target)
{
if (DeviceTypeKitAspect::deviceTypeId(target->kit())
== Constants::DESKTOP_DEVICE_TYPE)
addPreferredBaseEnvironment(SystemEnvironmentBase, tr("System Environment"));
addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
}
} // namespace QmlProjectManager

View File

@@ -1,45 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <projectexplorer/environmentaspect.h>
namespace QmlProjectManager {
class QmlProjectEnvironmentAspect : public ProjectExplorer::EnvironmentAspect
{
Q_OBJECT
public:
QmlProjectEnvironmentAspect(ProjectExplorer::Target *target);
Utils::Environment baseEnvironment() const override;
private:
ProjectExplorer::Target *m_target;
};
} // namespace QmlProjectManager

View File

@@ -4,8 +4,9 @@ include(../../qtcreatorplugin.pri)
include(fileformat/fileformat.pri) include(fileformat/fileformat.pri)
DEFINES += QMLPROJECTMANAGER_LIBRARY DEFINES += QMLPROJECTMANAGER_LIBRARY
HEADERS += qmlproject.h \
qmlprojectenvironmentaspect.h \ HEADERS += \
qmlproject.h \
qmlprojectplugin.h \ qmlprojectplugin.h \
qmlprojectconstants.h \ qmlprojectconstants.h \
qmlprojectnodes.h \ qmlprojectnodes.h \
@@ -13,8 +14,8 @@ HEADERS += qmlproject.h \
qmlprojectmanager_global.h \ qmlprojectmanager_global.h \
qmlprojectmanagerconstants.h qmlprojectmanagerconstants.h
SOURCES += qmlproject.cpp \ SOURCES += \
qmlprojectenvironmentaspect.cpp \ qmlproject.cpp \
qmlprojectplugin.cpp \ qmlprojectplugin.cpp \
qmlprojectnodes.cpp \ qmlprojectnodes.cpp \
qmlprojectrunconfiguration.cpp qmlprojectrunconfiguration.cpp

View File

@@ -18,7 +18,6 @@ QtcPlugin {
"qmlproject.cpp", "qmlproject.h", "qmlproject.cpp", "qmlproject.h",
"qmlproject.qrc", "qmlproject.qrc",
"qmlprojectconstants.h", "qmlprojectconstants.h",
"qmlprojectenvironmentaspect.cpp", "qmlprojectenvironmentaspect.h",
"qmlprojectmanager_global.h", "qmlprojectmanager_global.h",
"qmlprojectmanagerconstants.h", "qmlprojectmanagerconstants.h",
"qmlprojectnodes.cpp", "qmlprojectnodes.h", "qmlprojectnodes.cpp", "qmlprojectnodes.h",

View File

@@ -26,13 +26,13 @@
#include "qmlprojectrunconfiguration.h" #include "qmlprojectrunconfiguration.h"
#include "qmlproject.h" #include "qmlproject.h"
#include "qmlprojectmanagerconstants.h" #include "qmlprojectmanagerconstants.h"
#include "qmlprojectenvironmentaspect.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
@@ -41,10 +41,12 @@
#include <qtsupport/qtsupportconstants.h> #include <qtsupport/qtsupportconstants.h>
#include <qtsupport/desktopqtversion.h> #include <qtsupport/desktopqtversion.h>
#include <utils/environment.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/mimetypes/mimedatabase.h> #include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/winutils.h> #include <utils/winutils.h>
#include <qmljstools/qmljstoolsconstants.h> #include <qmljstools/qmljstoolsconstants.h>
#include <QComboBox> #include <QComboBox>
@@ -55,6 +57,7 @@
using namespace Core; using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace QtSupport; using namespace QtSupport;
using namespace Utils;
namespace QmlProjectManager { namespace QmlProjectManager {
@@ -275,7 +278,28 @@ void MainQmlFileAspect::changeCurrentFile(IEditor *editor)
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id) QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
addAspect<QmlProjectEnvironmentAspect>(target); enum BaseEnvironmentBase {
SystemEnvironmentBase = 0,
CleanEnvironmentBase
};
auto envAspect = addAspect<EnvironmentAspect>();
const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit());
if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
envAspect->addPreferredBaseEnvironment(SystemEnvironmentBase, tr("System Environment"));
envAspect->addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
envAspect->setBaseEnvironmentGetter([envAspect, target]() -> Utils::Environment {
Environment env = envAspect->baseEnvironmentBase() == SystemEnvironmentBase
? Environment::systemEnvironment()
: Environment();
if (auto project = qobject_cast<const QmlProject *>(target->project()))
env.modify(project->environment());
return env;
});
m_qmlViewerAspect = addAspect<BaseStringAspect>(); m_qmlViewerAspect = addAspect<BaseStringAspect>();
m_qmlViewerAspect->setLabelText(tr("QML Viewer:")); m_qmlViewerAspect->setLabelText(tr("QML Viewer:"));
m_qmlViewerAspect->setPlaceHolderText(executable()); m_qmlViewerAspect->setPlaceHolderText(executable());
@@ -304,7 +328,7 @@ Runnable QmlProjectRunConfiguration::runnable() const
Runnable r; Runnable r;
r.executable = executable(); r.executable = executable();
r.commandLineArguments = commandLineArguments(); r.commandLineArguments = commandLineArguments();
r.environment = aspect<QmlProjectEnvironmentAspect>()->environment(); r.environment = aspect<EnvironmentAspect>()->environment();
r.workingDirectory = static_cast<QmlProject *>(project())->targetDirectory(target()).toString(); r.workingDirectory = static_cast<QmlProject *>(project())->targetDirectory(target()).toString();
return r; return r;
} }

View File

@@ -55,14 +55,13 @@ RemoteLinuxEnvironmentAspect::RemoteLinuxEnvironmentAspect(ProjectExplorer::Targ
setConfigWidgetCreator([this, target] { setConfigWidgetCreator([this, target] {
return new RemoteLinuxEnvironmentAspectWidget(this, target); return new RemoteLinuxEnvironmentAspectWidget(this, target);
}); });
}
Utils::Environment RemoteLinuxEnvironmentAspect::baseEnvironment() const setBaseEnvironmentGetter([this] {
{ Utils::Environment env;
Utils::Environment env; if (baseEnvironmentBase() == static_cast<int>(RemoteBaseEnvironment))
if (baseEnvironmentBase() == static_cast<int>(RemoteBaseEnvironment)) env = m_remoteEnvironment;
env = m_remoteEnvironment; return env;
return env; });
} }
Utils::Environment RemoteLinuxEnvironmentAspect::remoteEnvironment() const Utils::Environment RemoteLinuxEnvironmentAspect::remoteEnvironment() const

View File

@@ -38,8 +38,6 @@ class REMOTELINUX_EXPORT RemoteLinuxEnvironmentAspect : public ProjectExplorer::
public: public:
RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target); RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target);
Utils::Environment baseEnvironment() const override;
Utils::Environment remoteEnvironment() const; Utils::Environment remoteEnvironment() const;
void setRemoteEnvironment(const Utils::Environment &env); void setRemoteEnvironment(const Utils::Environment &env);