From 8df9ed5b76a63612045139fba40b395463d2e6f9 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 29 Jan 2013 17:04:19 +0100 Subject: [PATCH] Add specialization of environmentaspect for local processes ... and attach that to localapplicationrunconfigurations Change-Id: I1d93820d45295bb0e8dd1ac2648070891eff6ddf Reviewed-by: Daniel Teske --- .../localapplicationrunconfiguration.cpp | 19 +++- .../localapplicationrunconfiguration.h | 5 + .../localenvironmentaspect.cpp | 106 ++++++++++++++++++ .../projectexplorer/localenvironmentaspect.h | 65 +++++++++++ .../projectexplorer/projectexplorer.pro | 2 + .../projectexplorer/projectexplorer.qbs | 2 + .../qt-desktop/qt4runconfiguration.cpp | 28 +++++ .../qt-desktop/qt4runconfiguration.h | 3 + 8 files changed, 228 insertions(+), 2 deletions(-) create mode 100644 src/plugins/projectexplorer/localenvironmentaspect.cpp create mode 100644 src/plugins/projectexplorer/localenvironmentaspect.h diff --git a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp index f1335329892..3c5951805c7 100644 --- a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp +++ b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp @@ -30,6 +30,7 @@ #include "localapplicationrunconfiguration.h" #include "buildconfiguration.h" +#include "localenvironmentaspect.h" #include @@ -39,11 +40,20 @@ namespace ProjectExplorer { LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, const Core::Id id) : RunConfiguration(target, id) -{ } +{ + ctor(); +} LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc) : RunConfiguration(target, rc) -{ } +{ + ctor(); +} + +void LocalApplicationRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const +{ + Q_UNUSED(env); +} Utils::AbstractMacroExpander *LocalApplicationRunConfiguration::macroExpander() const { @@ -52,4 +62,9 @@ Utils::AbstractMacroExpander *LocalApplicationRunConfiguration::macroExpander() return Core::VariableManager::macroExpander(); } +void LocalApplicationRunConfiguration::ctor() +{ + addExtraAspect(new LocalEnvironmentAspect(this)); +} + } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/localapplicationrunconfiguration.h b/src/plugins/projectexplorer/localapplicationrunconfiguration.h index e805fefcdd7..de3d15b309f 100644 --- a/src/plugins/projectexplorer/localapplicationrunconfiguration.h +++ b/src/plugins/projectexplorer/localapplicationrunconfiguration.h @@ -57,11 +57,16 @@ public: virtual QString dumperLibrary() const = 0; virtual QStringList dumperLibraryLocations() const = 0; + virtual void addToBaseEnvironment(Utils::Environment &env) const; + protected: explicit LocalApplicationRunConfiguration(Target *target, const Core::Id id); explicit LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc); Utils::AbstractMacroExpander *macroExpander() const; + +private: + void ctor(); }; } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/localenvironmentaspect.cpp b/src/plugins/projectexplorer/localenvironmentaspect.cpp new file mode 100644 index 00000000000..7b1cec55fa3 --- /dev/null +++ b/src/plugins/projectexplorer/localenvironmentaspect.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "localenvironmentaspect.h" + +#include "buildconfiguration.h" +#include "environmentaspectwidget.h" +#include "localapplicationrunconfiguration.h" +#include "target.h" + +#include + +namespace ProjectExplorer { + +// -------------------------------------------------------------------- +// LocalEnvironmentAspect: +// -------------------------------------------------------------------- + +QList LocalEnvironmentAspect::possibleBaseEnvironments() const +{ + return QList() << static_cast(BuildEnvironmentBase) + << static_cast(SystemEnvironmentBase) + << static_cast(CleanEnvironmentBase); +} + +QString LocalEnvironmentAspect::baseEnvironmentDisplayName(int base) const +{ + if (base == static_cast(BuildEnvironmentBase)) + return tr("Build Environment"); + if (base == static_cast(SystemEnvironmentBase)) + return tr("System Environment"); + if (base == static_cast(CleanEnvironmentBase)) + return tr("Clean Environment"); + return QString(); +} + +Utils::Environment LocalEnvironmentAspect::baseEnvironment() const +{ + int base = baseEnvironmentBase(); + Utils::Environment env; + if (base == static_cast(BuildEnvironmentBase)) { + if (BuildConfiguration *bc = runConfiguration()->target()->activeBuildConfiguration()) + env = bc->environment(); + } else if (base == static_cast(SystemEnvironmentBase)) { + env = Utils::Environment::systemEnvironment(); + } + + if (const LocalApplicationRunConfiguration *rc = qobject_cast(runConfiguration())) + rc->addToBaseEnvironment(env); + + return env; +} + +void LocalEnvironmentAspect::buildEnvironmentHasChanged() +{ + if (baseEnvironmentBase() == static_cast(BuildEnvironmentBase)) { + emit baseEnvironmentChanged(); + emit environmentChanged(); + } +} + +LocalEnvironmentAspect::LocalEnvironmentAspect(RunConfiguration *rc) : + EnvironmentAspect(rc) +{ + connect(rc->target(), SIGNAL(environmentChanged()), + this, SLOT(buildEnvironmentHasChanged())); +} + +LocalEnvironmentAspect::LocalEnvironmentAspect(const LocalEnvironmentAspect *other, + ProjectExplorer::RunConfiguration *parent) : + EnvironmentAspect(other, parent) +{ } + +LocalEnvironmentAspect *LocalEnvironmentAspect::clone(RunConfiguration *parent) const +{ + Q_UNUSED(parent); + return new LocalEnvironmentAspect(this, parent); +} + +} // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/localenvironmentaspect.h b/src/plugins/projectexplorer/localenvironmentaspect.h new file mode 100644 index 00000000000..82f7d9e4816 --- /dev/null +++ b/src/plugins/projectexplorer/localenvironmentaspect.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef LOCALENVIRONMENTASPECT_H +#define LOCALENVIRONMENTASPECT_H + +#include "environmentaspect.h" + +namespace ProjectExplorer { + +class LocalEnvironmentAspect : public EnvironmentAspect +{ + Q_OBJECT + +public: + LocalEnvironmentAspect(RunConfiguration *rc); + + LocalEnvironmentAspect *clone(RunConfiguration *parent) const; + + QList possibleBaseEnvironments() const; + QString baseEnvironmentDisplayName(int base) const; + Utils::Environment baseEnvironment() const; + +public slots: + void buildEnvironmentHasChanged(); + +private: + enum BaseEnvironmentBase { + CleanEnvironmentBase = 0, + SystemEnvironmentBase, + BuildEnvironmentBase + }; + + LocalEnvironmentAspect(const LocalEnvironmentAspect *other, RunConfiguration *parent); +}; + +} // namespace ProjectExplorer + +#endif // LOCALENVIRONMENTASPECT_H diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index ee0506e047b..8c381ecc48d 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -11,6 +11,7 @@ HEADERS += projectexplorer.h \ environmentaspectwidget.h \ gcctoolchain.h \ localapplicationrunconfiguration.h \ + localenvironmentaspect.h \ projectexplorer_export.h \ projectwindow.h \ removetaskhandler.h \ @@ -138,6 +139,7 @@ SOURCES += projectexplorer.cpp \ environmentaspectwidget.cpp \ gcctoolchain.cpp \ localapplicationrunconfiguration.cpp \ + localenvironmentaspect.cpp \ projectwindow.cpp \ removetaskhandler.cpp \ kit.cpp \ diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index c31d5fb0c3d..dd76e03c3f5 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -142,6 +142,8 @@ QtcPlugin { "localapplicationrunconfiguration.h", "localapplicationruncontrol.cpp", "localapplicationruncontrol.h", + "localenvironmentaspect.cpp", + "localenvironmentaspect.h", "metatypedeclarations.h", "miniprojecttargetselector.cpp", "miniprojecttargetselector.h", diff --git a/src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.cpp b/src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.cpp index c69f1546034..e316f635286 100644 --- a/src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.cpp @@ -666,6 +666,34 @@ void Qt4RunConfiguration::setRunMode(RunMode runMode) emit runModeChanged(runMode); } +void Qt4RunConfiguration::addToBaseEnvironment(Utils::Environment &env) const +{ + if (m_isUsingDyldImageSuffix) + env.set(QLatin1String("DYLD_IMAGE_SUFFIX"), QLatin1String("_debug")); + + // The user could be linking to a library found via a -L/some/dir switch + // to find those libraries while actually running we explicitly prepend those + // dirs to the library search path + const Qt4ProFileNode *node = static_cast(target()->project())->rootQt4ProjectNode()->findProFileFor(m_proFilePath); + if (node) { + const QStringList libDirectories = node->variableValue(LibDirectoriesVar); + if (!libDirectories.isEmpty()) { + const QString proDirectory = node->buildDir(); + foreach (QString dir, libDirectories) { + // Fix up relative entries like "LIBS+=-L.." + const QFileInfo fi(dir); + if (!fi.isAbsolute()) + dir = QDir::cleanPath(proDirectory + QLatin1Char('/') + dir); + env.prependOrSetLibrarySearchPath(dir); + } // foreach + } // libDirectories + } // node + + QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(target()->kit()); + if (qtVersion) + env.prependOrSetLibrarySearchPath(qtVersion->qmakeProperty("QT_INSTALL_LIBS")); +} + QString Qt4RunConfiguration::proFilePath() const { return m_proFilePath; diff --git a/src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.h b/src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.h index 2e5e5184b7e..62c3d78d6f7 100644 --- a/src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.h +++ b/src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.h @@ -99,6 +99,9 @@ public: Utils::OutputFormatter *createOutputFormatter() const; void setRunMode(RunMode runMode); + + void addToBaseEnvironment(Utils::Environment &env) const; + signals: void commandLineArgumentsChanged(const QString&); void baseWorkingDirectoryChanged(const QString&);