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

@@ -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)
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

View File

@@ -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",

View File

@@ -26,13 +26,13 @@
#include "qmlprojectrunconfiguration.h"
#include "qmlproject.h"
#include "qmlprojectmanagerconstants.h"
#include "qmlprojectenvironmentaspect.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/target.h>
@@ -41,10 +41,12 @@
#include <qtsupport/qtsupportconstants.h>
#include <qtsupport/desktopqtversion.h>
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcprocess.h>
#include <utils/winutils.h>
#include <qmljstools/qmljstoolsconstants.h>
#include <QComboBox>
@@ -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<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->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<QmlProjectEnvironmentAspect>()->environment();
r.environment = aspect<EnvironmentAspect>()->environment();
r.workingDirectory = static_cast<QmlProject *>(project())->targetDirectory(target()).toString();
return r;
}