diff --git a/src/plugins/android/android.pro b/src/plugins/android/android.pro index 905a20e6f66..3e8d577740b 100644 --- a/src/plugins/android/android.pro +++ b/src/plugins/android/android.pro @@ -50,8 +50,7 @@ HEADERS += \ androidsdkmanagerwidget.h \ androidpackageinstallationstep.h \ androidextralibrarylistmodel.h \ - createandroidmanifestwizard.h \ - androidrunenvironmentaspect.h + createandroidmanifestwizard.h SOURCES += \ androidconfigurations.cpp \ @@ -95,8 +94,7 @@ SOURCES += \ androidsdkmanagerwidget.cpp \ androidpackageinstallationstep.cpp \ androidextralibrarylistmodel.cpp \ - createandroidmanifestwizard.cpp \ - androidrunenvironmentaspect.cpp + createandroidmanifestwizard.cpp FORMS += \ androidsettingswidget.ui \ diff --git a/src/plugins/android/android.qbs b/src/plugins/android/android.qbs index 0bade6bc138..bcdb8a2e619 100644 --- a/src/plugins/android/android.qbs +++ b/src/plugins/android/android.qbs @@ -75,8 +75,6 @@ Project { "androidqtversion.h", "androidrunconfiguration.cpp", "androidrunconfiguration.h", - "androidrunenvironmentaspect.h", - "androidrunenvironmentaspect.cpp", "androidruncontrol.cpp", "androidruncontrol.h", "androidrunner.cpp", diff --git a/src/plugins/android/androidrunconfiguration.cpp b/src/plugins/android/androidrunconfiguration.cpp index 06f9f548c63..eba5d214e71 100644 --- a/src/plugins/android/androidrunconfiguration.cpp +++ b/src/plugins/android/androidrunconfiguration.cpp @@ -30,7 +30,6 @@ #include "androidtoolchain.h" #include "androidmanager.h" #include "adbcommandswidget.h" -#include "androidrunenvironmentaspect.h" #include #include @@ -108,7 +107,11 @@ void BaseStringListAspect::setLabel(const QString &label) AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id) : RunConfiguration(target, id) { - addAspect(); + enum BaseEnvironmentBase { CleanEnvironmentBase }; + auto envAspect = addAspect(); + envAspect->addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment")); + envAspect->setBaseEnvironmentGetter([] { return Utils::Environment(); }); + addAspect(); auto amStartArgsAspect = addAspect(); diff --git a/src/plugins/android/androidrunenvironmentaspect.cpp b/src/plugins/android/androidrunenvironmentaspect.cpp deleted file mode 100644 index 1db75f03529..00000000000 --- a/src/plugins/android/androidrunenvironmentaspect.cpp +++ /dev/null @@ -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 - diff --git a/src/plugins/android/androidrunenvironmentaspect.h b/src/plugins/android/androidrunenvironmentaspect.h deleted file mode 100644 index 0620f577467..00000000000 --- a/src/plugins/android/androidrunenvironmentaspect.h +++ /dev/null @@ -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 - -namespace Android { - -class AndroidRunEnvironmentAspect : public ProjectExplorer::EnvironmentAspect -{ - Q_OBJECT - -public: - AndroidRunEnvironmentAspect(); - - Utils::Environment baseEnvironment() const override; -}; - -} // namespace Android - diff --git a/src/plugins/projectexplorer/environmentaspect.cpp b/src/plugins/projectexplorer/environmentaspect.cpp index d0b0845a3e2..8daf204cc97 100644 --- a/src/plugins/projectexplorer/environmentaspect.cpp +++ b/src/plugins/projectexplorer/environmentaspect.cpp @@ -113,4 +113,15 @@ void EnvironmentAspect::toMap(QVariantMap &data) const 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 &getter) +{ + m_baseEnvironmentGetter = getter; +} + } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/environmentaspect.h b/src/plugins/projectexplorer/environmentaspect.h index 7d0ecbe4064..69f6ae77a36 100644 --- a/src/plugins/projectexplorer/environmentaspect.h +++ b/src/plugins/projectexplorer/environmentaspect.h @@ -41,8 +41,12 @@ class PROJECTEXPLORER_EXPORT EnvironmentAspect : public ProjectConfigurationAspe Q_OBJECT public: + EnvironmentAspect(); + // 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 &getter); + // The environment including the user's modifications. Utils::Environment environment() const; @@ -64,12 +68,12 @@ signals: void environmentChanged(); protected: - EnvironmentAspect(); void fromMap(const QVariantMap &map) override; void toMap(QVariantMap &map) const override; private: int m_base = -1; + std::function m_baseEnvironmentGetter; QList m_changes; QMap m_displayNames; }; diff --git a/src/plugins/projectexplorer/localenvironmentaspect.cpp b/src/plugins/projectexplorer/localenvironmentaspect.cpp index 2a6eee97c5a..36f7f309169 100644 --- a/src/plugins/projectexplorer/localenvironmentaspect.cpp +++ b/src/plugins/projectexplorer/localenvironmentaspect.cpp @@ -40,25 +40,37 @@ enum BaseEnvironmentBase { BuildEnvironmentBase }; -Utils::Environment LocalEnvironmentAspect::baseEnvironment() const +LocalEnvironmentAspect::LocalEnvironmentAspect(Target *target, + const BaseEnvironmentModifier &modifier) { - int base = baseEnvironmentBase(); - Utils::Environment env; - if (base == static_cast(BuildEnvironmentBase)) { - if (BuildConfiguration *bc = m_target->activeBuildConfiguration()) { - env = bc->environment(); - } else { // Fallback for targets without buildconfigurations: + addPreferredBaseEnvironment(BuildEnvironmentBase, tr("Build Environment")); + addSupportedBaseEnvironment(SystemEnvironmentBase, tr("System Environment")); + addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment")); + + target->subscribeSignal(&BuildConfiguration::environmentChanged, + this, &LocalEnvironmentAspect::buildEnvironmentHasChanged); + connect(target, &Target::activeBuildConfigurationChanged, + this, &LocalEnvironmentAspect::buildEnvironmentHasChanged); + + setBaseEnvironmentGetter([this, target, modifier] { + int base = baseEnvironmentBase(); + Utils::Environment env; + if (base == static_cast(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(SystemEnvironmentBase)) { env = Utils::Environment::systemEnvironment(); - m_target->kit()->addToEnvironment(env); } - } else if (base == static_cast(SystemEnvironmentBase)) { - env = Utils::Environment::systemEnvironment(); - } - if (m_baseEnvironmentModifier) - m_baseEnvironmentModifier(env); + if (modifier) + modifier(env); - return env; + return env; + }); } void LocalEnvironmentAspect::buildEnvironmentHasChanged() @@ -67,19 +79,4 @@ void LocalEnvironmentAspect::buildEnvironmentHasChanged() 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 diff --git a/src/plugins/projectexplorer/localenvironmentaspect.h b/src/plugins/projectexplorer/localenvironmentaspect.h index 967a985e8f4..33b3933f6f8 100644 --- a/src/plugins/projectexplorer/localenvironmentaspect.h +++ b/src/plugins/projectexplorer/localenvironmentaspect.h @@ -37,13 +37,7 @@ public: using BaseEnvironmentModifier = std::function; LocalEnvironmentAspect(Target *parent, const BaseEnvironmentModifier &modifier); - Utils::Environment baseEnvironment() const override; - void buildEnvironmentHasChanged(); - -private: - BaseEnvironmentModifier m_baseEnvironmentModifier; - Target *m_target; }; } // namespace ProjectExplorer diff --git a/src/plugins/qmlprojectmanager/qmlprojectenvironmentaspect.cpp b/src/plugins/qmlprojectmanager/qmlprojectenvironmentaspect.cpp deleted file mode 100644 index 2502747f2ec..00000000000 --- a/src/plugins/qmlprojectmanager/qmlprojectenvironmentaspect.cpp +++ /dev/null @@ -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 -#include -#include - -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(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 diff --git a/src/plugins/qmlprojectmanager/qmlprojectenvironmentaspect.h b/src/plugins/qmlprojectmanager/qmlprojectenvironmentaspect.h deleted file mode 100644 index 65880649fba..00000000000 --- a/src/plugins/qmlprojectmanager/qmlprojectenvironmentaspect.h +++ /dev/null @@ -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 - -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 diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro index b179dac63e3..ffd837e8276 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro +++ b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro @@ -4,8 +4,9 @@ include(../../qtcreatorplugin.pri) include(fileformat/fileformat.pri) DEFINES += QMLPROJECTMANAGER_LIBRARY -HEADERS += qmlproject.h \ - qmlprojectenvironmentaspect.h \ + +HEADERS += \ + qmlproject.h \ qmlprojectplugin.h \ qmlprojectconstants.h \ qmlprojectnodes.h \ @@ -13,8 +14,8 @@ HEADERS += qmlproject.h \ qmlprojectmanager_global.h \ qmlprojectmanagerconstants.h -SOURCES += qmlproject.cpp \ - qmlprojectenvironmentaspect.cpp \ +SOURCES += \ + qmlproject.cpp \ qmlprojectplugin.cpp \ qmlprojectnodes.cpp \ qmlprojectrunconfiguration.cpp diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager.qbs b/src/plugins/qmlprojectmanager/qmlprojectmanager.qbs index 1403127694d..258ef8d754d 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectmanager.qbs +++ b/src/plugins/qmlprojectmanager/qmlprojectmanager.qbs @@ -18,7 +18,6 @@ QtcPlugin { "qmlproject.cpp", "qmlproject.h", "qmlproject.qrc", "qmlprojectconstants.h", - "qmlprojectenvironmentaspect.cpp", "qmlprojectenvironmentaspect.h", "qmlprojectmanager_global.h", "qmlprojectmanagerconstants.h", "qmlprojectnodes.cpp", "qmlprojectnodes.h", diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp index aefeb97719e..49edca194dc 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp @@ -26,13 +26,13 @@ #include "qmlprojectrunconfiguration.h" #include "qmlproject.h" #include "qmlprojectmanagerconstants.h" -#include "qmlprojectenvironmentaspect.h" #include #include #include #include +#include #include #include @@ -41,10 +41,12 @@ #include #include +#include #include #include #include #include + #include #include @@ -55,6 +57,7 @@ using namespace Core; using namespace ProjectExplorer; using namespace QtSupport; +using namespace Utils; namespace QmlProjectManager { @@ -275,7 +278,28 @@ void MainQmlFileAspect::changeCurrentFile(IEditor *editor) QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id) : RunConfiguration(target, id) { - addAspect(target); + enum BaseEnvironmentBase { + SystemEnvironmentBase = 0, + CleanEnvironmentBase + }; + + auto envAspect = addAspect(); + 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(target->project())) + env.modify(project->environment()); + + return env; + }); + + m_qmlViewerAspect = addAspect(); m_qmlViewerAspect->setLabelText(tr("QML Viewer:")); m_qmlViewerAspect->setPlaceHolderText(executable()); @@ -304,7 +328,7 @@ Runnable QmlProjectRunConfiguration::runnable() const Runnable r; r.executable = executable(); r.commandLineArguments = commandLineArguments(); - r.environment = aspect()->environment(); + r.environment = aspect()->environment(); r.workingDirectory = static_cast(project())->targetDirectory(target()).toString(); return r; } diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspect.cpp b/src/plugins/remotelinux/remotelinuxenvironmentaspect.cpp index cfa23b32190..aaaae8e68fb 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentaspect.cpp +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspect.cpp @@ -55,14 +55,13 @@ RemoteLinuxEnvironmentAspect::RemoteLinuxEnvironmentAspect(ProjectExplorer::Targ setConfigWidgetCreator([this, target] { return new RemoteLinuxEnvironmentAspectWidget(this, target); }); -} -Utils::Environment RemoteLinuxEnvironmentAspect::baseEnvironment() const -{ - Utils::Environment env; - if (baseEnvironmentBase() == static_cast(RemoteBaseEnvironment)) - env = m_remoteEnvironment; - return env; + setBaseEnvironmentGetter([this] { + Utils::Environment env; + if (baseEnvironmentBase() == static_cast(RemoteBaseEnvironment)) + env = m_remoteEnvironment; + return env; + }); } Utils::Environment RemoteLinuxEnvironmentAspect::remoteEnvironment() const diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspect.h b/src/plugins/remotelinux/remotelinuxenvironmentaspect.h index 0ac83cd4281..c4413e07e11 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentaspect.h +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspect.h @@ -38,8 +38,6 @@ class REMOTELINUX_EXPORT RemoteLinuxEnvironmentAspect : public ProjectExplorer:: public: RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target); - Utils::Environment baseEnvironment() const override; - Utils::Environment remoteEnvironment() const; void setRemoteEnvironment(const Utils::Environment &env);