Add option for globally changing the base environment for tools

Fixes: QTCREATORBUG-22123
Change-Id: I00a5bbdf92e5dab513cb12f3518a2abb1adbb9cd
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Eike Ziller
2020-11-16 16:40:12 +01:00
parent 05dca6f09e
commit e755094480
8 changed files with 370 additions and 220 deletions

View File

@@ -313,6 +313,11 @@ void Environment::modifySystemEnvironment(const EnvironmentItems &list)
staticSystemEnvironment->modify(list);
}
void Environment::setSystemEnvironment(const Environment &environment)
{
*staticSystemEnvironment = environment;
}
/** Expand environment variables in a string.
*
* Environment variables are accepted in the following forms:

View File

@@ -82,6 +82,7 @@ public:
QStringList expandVariables(const QStringList &input) const;
static void modifySystemEnvironment(const EnvironmentItems &list); // use with care!!!
static void setSystemEnvironment(const Environment &environment); // don't use at all!!!
private:
FilePath searchInDirectory(const QStringList &execs, const FilePath &directory,

View File

@@ -75,6 +75,16 @@ using namespace Utils;
static CorePlugin *m_instance = nullptr;
const char kEnvironmentChanges[] = "Core/EnvironmentChanges";
void CorePlugin::setupSystemEnvironment()
{
m_instance->m_startupSystemEnvironment = Environment::systemEnvironment();
const EnvironmentItems changes = EnvironmentItem::fromStringList(
ICore::settings()->value(kEnvironmentChanges).toStringList());
setEnvironmentChanges(changes);
}
CorePlugin::CorePlugin()
{
qRegisterMetaType<Id>();
@@ -82,6 +92,7 @@ CorePlugin::CorePlugin()
qRegisterMetaType<Utils::CommandLine>();
qRegisterMetaType<Utils::FilePath>();
m_instance = this;
setupSystemEnvironment();
}
CorePlugin::~CorePlugin()
@@ -266,6 +277,29 @@ QObject *CorePlugin::remoteCommand(const QStringList & /* options */,
return res;
}
Environment CorePlugin::startupSystemEnvironment()
{
return m_instance->m_startupSystemEnvironment;
}
EnvironmentItems CorePlugin::environmentChanges()
{
return m_instance->m_environmentChanges;
}
void CorePlugin::setEnvironmentChanges(const EnvironmentItems &changes)
{
if (m_instance->m_environmentChanges == changes)
return;
m_instance->m_environmentChanges = changes;
Environment systemEnv = m_instance->m_startupSystemEnvironment;
systemEnv.modify(changes);
Environment::setSystemEnvironment(systemEnv);
ICore::settings()->setValue(kEnvironmentChanges, EnvironmentItem::toStringList(changes));
if (ICore::instance())
emit ICore::instance()->systemEnvironmentChanged();
}
void CorePlugin::fileOpenRequest(const QString &f)
{
remoteCommand(QStringList(), QString(), QStringList(f));

View File

@@ -29,6 +29,7 @@
#include "reaper_p.h"
#include <extensionsystem/iplugin.h>
#include <utils/environment.h>
QT_BEGIN_NAMESPACE
class QMenu;
@@ -64,6 +65,10 @@ public:
const QString &workingDirectory,
const QStringList &args) override;
static Utils::Environment startupSystemEnvironment();
static Utils::EnvironmentItems environmentChanges();
static void setEnvironmentChanges(const Utils::EnvironmentItems &changes);
public slots:
void fileOpenRequest(const QString&);
@@ -82,12 +87,15 @@ private slots:
private:
static void addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QMenu *menu);
void setupSystemEnvironment();
void checkSettings();
MainWindow *m_mainWindow = nullptr;
EditMode *m_editMode = nullptr;
Locator *m_locator = nullptr;
ProcessReapers m_reaper;
Utils::Environment m_startupSystemEnvironment;
Utils::EnvironmentItems m_environmentChanges;
};
} // namespace Internal

View File

@@ -148,6 +148,7 @@ signals:
void coreAboutToClose();
void contextAboutToChange(const QList<Core::IContext *> &context);
void contextChanged(const Core::Context &context);
void systemEnvironmentChanged();
public:
/* internal use */

View File

@@ -25,6 +25,7 @@
#include "systemsettings.h"
#include "coreconstants.h"
#include "coreplugin.h"
#include "editormanager/editormanager_p.h"
#include "fileutils.h"
#include "icore.h"
@@ -37,6 +38,7 @@
#include <utils/checkablemessagebox.h>
#include <utils/consoleprocess.h>
#include <utils/environment.h>
#include <utils/environmentdialog.h>
#include <utils/hostosinfo.h>
#include <utils/unixutils.h>
@@ -153,6 +155,20 @@ public:
updatePath();
m_ui.environmentChangesLabel->setElideMode(Qt::ElideRight);
m_environmentChanges = CorePlugin::environmentChanges();
updateEnvironmentChangesLabel();
connect(m_ui.environmentButton, &QPushButton::clicked, [this] {
Utils::optional<EnvironmentItems> changes
= Utils::EnvironmentDialog::getEnvironmentItems(m_ui.environmentButton,
m_environmentChanges);
if (!changes)
return;
m_environmentChanges = *changes;
updateEnvironmentChangesLabel();
updatePath();
});
connect(VcsManager::instance(), &VcsManager::configurationChanged,
this, &SystemSettingsWidget::updatePath);
}
@@ -165,10 +181,12 @@ private:
void resetTerminal();
void updateTerminalUi(const Utils::TerminalCommand &term);
void updatePath();
void updateEnvironmentChangesLabel();
void variableHelpDialogCreator(const QString &helpText);
Ui::SystemSettings m_ui;
QPointer<QMessageBox> m_dialog;
EnvironmentItems m_environmentChanges;
};
void SystemSettingsWidget::apply()
@@ -206,6 +224,8 @@ void SystemSettingsWidget::apply()
else
HostOsInfo::setOverrideFileNameCaseSensitivity(selectedSensitivity);
}
CorePlugin::setEnvironmentChanges(m_environmentChanges);
}
void SystemSettingsWidget::resetTerminal()
@@ -235,6 +255,14 @@ void SystemSettingsWidget::updatePath()
m_ui.patchChooser->setEnvironment(env);
}
void SystemSettingsWidget::updateEnvironmentChangesLabel()
{
const QString shortSummary = Utils::EnvironmentItem::toStringList(m_environmentChanges)
.join("; ");
m_ui.environmentChangesLabel->setText(shortSummary.isEmpty() ? tr("No changes to apply.")
: shortSummary);
}
void SystemSettingsWidget::variableHelpDialogCreator(const QString &helpText)
{
if (m_dialog) {

View File

@@ -17,112 +17,7 @@
<string>System</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="terminalLabel">
<property name="text">
<string>Terminal:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QComboBox" name="terminalComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="terminalOpenArgs"/>
</item>
<item>
<widget class="QLineEdit" name="terminalExecuteArgs">
<property name="toolTip">
<string>Command line arguments used for &quot;Run in terminal&quot;.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="resetTerminalButton">
<property name="toolTip">
<string comment="Terminal">Reset to default.</string>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="externalFileBrowserLabel">
<property name="text">
<string>External file browser:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QWidget" name="externalFileBrowserWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="externalFileBrowserEdit"/>
</item>
<item>
<widget class="QPushButton" name="resetFileBrowserButton">
<property name="toolTip">
<string comment="File Browser">Reset to default.</string>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="helpExternalFileBrowserButton">
<property name="text">
<string>?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="patchCommandLabel">
<property name="text">
<string>Patch command:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="Utils::PathChooser" name="patchChooser" native="true"/>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="fileSystemCaseSensitivityLabel">
<property name="toolTip">
<string>Influences how file names are matched to decide if they are the same.</string>
@@ -132,7 +27,20 @@
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<item row="7" column="0">
<widget class="QCheckBox" name="autoSuspendCheckBox">
<property name="toolTip">
<string>Automatically free resources of old documents that are not visible and not modified. They stay visible in the list of open documents.</string>
</property>
<property name="text">
<string>Auto-suspend unmodified files</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QWidget" name="fileSystemCaseSensitivityWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
@@ -166,110 +74,14 @@
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="modifiedLabel">
<item row="1" column="0">
<widget class="QLabel" name="terminalLabel">
<property name="text">
<string>When files are externally modified:</string>
<string>Terminal:</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="reloadBehavior">
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Always Ask</string>
</property>
</item>
<item>
<property name="text">
<string>Reload All Unchanged Editors</string>
</property>
</item>
<item>
<property name="text">
<string>Ignore Modifications</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="autoSaveCheckBox">
<property name="text">
<string>Auto-save modified files</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="autoSaveIntervalLabel">
<property name="text">
<string>Interval:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="autoSaveInterval">
<property name="suffix">
<string extracomment="unit for minutes">min</string>
</property>
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="autoSuspendCheckBox">
<property name="toolTip">
<string>Automatically free resources of old documents that are not visible and not modified. They stay visible in the list of open documents.</string>
</property>
<property name="text">
<string>Auto-suspend unmodified files</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<item row="7" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="autoSuspendLabel">
@@ -309,7 +121,95 @@
</item>
</layout>
</item>
<item row="7" column="0" colspan="3">
<item row="9" column="0" colspan="2">
<widget class="QLabel" name="maxRecentFilesLabel">
<property name="text">
<string>Maximum number of entries in &quot;Recent Files&quot;:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="autoSaveCheckBox">
<property name="text">
<string>Auto-save modified files</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="modifiedLabel">
<property name="text">
<string>When files are externally modified:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="externalFileBrowserLabel">
<property name="text">
<string>External file browser:</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="Utils::PathChooser" name="patchChooser" native="true"/>
</item>
<item row="9" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QSpinBox" name="maxRecentFilesSpinBox"/>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="6" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="autoSaveIntervalLabel">
<property name="text">
<string>Interval:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="autoSaveInterval">
<property name="suffix">
<string extracomment="unit for minutes">min</string>
</property>
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="8" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="warnBeforeOpeningBigFiles">
@@ -352,20 +252,32 @@
</item>
</layout>
</item>
<item row="8" column="0" colspan="2">
<widget class="QLabel" name="maxRecentFilesLabel">
<property name="text">
<string>Maximum number of entries in &quot;Recent Files&quot;:</string>
</property>
</widget>
</item>
<item row="8" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item row="5" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="maxRecentFilesSpinBox"/>
<widget class="QComboBox" name="reloadBehavior">
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Always Ask</string>
</property>
</item>
<item>
<property name="text">
<string>Reload All Unchanged Editors</string>
</property>
</item>
<item>
<property name="text">
<string>Ignore Modifications</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -379,7 +291,14 @@
</item>
</layout>
</item>
<item row="9" column="0">
<item row="3" column="0">
<widget class="QLabel" name="patchCommandLabel">
<property name="text">
<string>Patch command:</string>
</property>
</widget>
</item>
<item row="10" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QCheckBox" name="askBeforeExitCheckBox">
@@ -390,6 +309,152 @@
</item>
</layout>
</item>
<item row="2" column="1" colspan="2">
<widget class="QWidget" name="externalFileBrowserWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="externalFileBrowserEdit"/>
</item>
<item>
<widget class="QPushButton" name="resetFileBrowserButton">
<property name="toolTip">
<string comment="File Browser">Reset to default.</string>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="helpExternalFileBrowserButton">
<property name="text">
<string>?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="environmentLabel">
<property name="text">
<string>Environment:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QWidget" name="terminalWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="terminalComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="terminalOpenArgs"/>
</item>
<item>
<widget class="QLineEdit" name="terminalExecuteArgs">
<property name="toolTip">
<string>Command line arguments used for &quot;Run in terminal&quot;.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="resetTerminalButton">
<property name="toolTip">
<string comment="Terminal">Reset to default.</string>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QWidget" name="environmentWidget" native="true">
<layout class="QHBoxLayout" name="environmentLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="Utils::ElidingLabel" name="environmentChangesLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="environmentButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Change...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
@@ -419,6 +484,11 @@
<signal>browsingFinished()</signal>
</slots>
</customwidget>
<customwidget>
<class>Utils::ElidingLabel</class>
<extends>QLabel</extends>
<header location="global">utils/elidinglabel.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>resetTerminalButton</tabstop>

View File

@@ -45,6 +45,7 @@
#include "target.h"
#include "toolchain.h"
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <utils/algorithm.h>
@@ -188,6 +189,8 @@ BuildConfiguration::BuildConfiguration(Target *target, Utils::Id id)
[this](const QString &var) { return environment().expandedValueForKey(var); });
updateCacheAndEmitEnvironmentChanged();
connect(Core::ICore::instance(), &Core::ICore::systemEnvironmentChanged,
this, &BuildConfiguration::updateCacheAndEmitEnvironmentChanged);
connect(target, &Target::kitChanged,
this, &BuildConfiguration::updateCacheAndEmitEnvironmentChanged);
connect(this, &BuildConfiguration::environmentChanged,