forked from qt-creator/qt-creator
Projects: Use qtcEnvironmentVariable* instead of qEnvironmentVariable*
And instead of qgetenv. Takes Qt Creator's setting at "Environment > System > Environment" into account, which makes it easier on some platforms to set them (e.g. macOS), can be configured differently in different settings paths, and potentially can be changed at runtime (depending on usage). Change-Id: I2217f13336ec816d28bd447ccd14a405bff2a3a7 Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -53,9 +53,9 @@ static std::vector<std::unique_ptr<CMakeTool>> autoDetectCMakeTools()
|
||||
path = Utils::filteredUnique(path);
|
||||
|
||||
if (HostOsInfo::isWindowsHost()) {
|
||||
for (auto envVar : {"ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"}) {
|
||||
if (qEnvironmentVariableIsSet(envVar)) {
|
||||
const QString progFiles = qEnvironmentVariable(envVar);
|
||||
for (const auto &envVar : QStringList{"ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"}) {
|
||||
if (qtcEnvironmentVariableIsSet(envVar)) {
|
||||
const QString progFiles = qtcEnvironmentVariable(envVar);
|
||||
path.append(FilePath::fromUserInput(progFiles + "/CMake"));
|
||||
path.append(FilePath::fromUserInput(progFiles + "/CMake/bin"));
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "abi.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -1273,7 +1274,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testAbiOfBinary_data()
|
||||
|
||||
// Clone test data from: https://git.qt.io/chstenge/creator-test-data
|
||||
// Set up prefix for test data now that we can be sure to have some tests to run:
|
||||
QString prefix = QString::fromLocal8Bit(qgetenv("QTC_TEST_EXTRADATALOCATION"));
|
||||
QString prefix = Utils::qtcEnvironmentVariable("QTC_TEST_EXTRADATALOCATION");
|
||||
if (prefix.isEmpty())
|
||||
return;
|
||||
prefix += "/projectexplorer/abi";
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -37,7 +38,7 @@ const char configFileC[] = "wizard.xml";
|
||||
static bool enableLoadTemplateFiles()
|
||||
{
|
||||
#ifdef WITH_TESTS
|
||||
static bool value = qEnvironmentVariableIsEmpty("QTC_DISABLE_LOAD_TEMPLATES_FOR_TEST");
|
||||
static bool value = qtcEnvironmentVariableIsEmpty("QTC_DISABLE_LOAD_TEMPLATES_FOR_TEST");
|
||||
#else
|
||||
static bool value = true;
|
||||
#endif
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include "customwizard.h"
|
||||
#include "customwizardparameters.h"
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
@@ -46,7 +47,7 @@ QStringList fixGeneratorScript(const QString &configFile, QString binary)
|
||||
if (!extension.isEmpty() && extension.compare(QLatin1String("exe"),
|
||||
Qt::CaseInsensitive) != 0) {
|
||||
rc.push_front(QLatin1String("/C"));
|
||||
rc.push_front(QString::fromLocal8Bit(qgetenv("COMSPEC")));
|
||||
rc.push_front(qtcEnvironmentVariable("COMSPEC"));
|
||||
if (rc.front().isEmpty())
|
||||
rc.front() = QLatin1String("cmd.exe");
|
||||
}
|
||||
|
@@ -106,29 +106,29 @@ bool operator!=(const SshParameters &p1, const SshParameters &p2)
|
||||
namespace SshTest {
|
||||
const QString getHostFromEnvironment()
|
||||
{
|
||||
const QString host = QString::fromLocal8Bit(qgetenv("QTC_SSH_TEST_HOST"));
|
||||
if (host.isEmpty() && qEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
|
||||
const QString host = qtcEnvironmentVariable("QTC_SSH_TEST_HOST");
|
||||
if (host.isEmpty() && qtcEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
|
||||
return QString("127.0.0.1");
|
||||
return host;
|
||||
}
|
||||
|
||||
quint16 getPortFromEnvironment()
|
||||
{
|
||||
const int port = qEnvironmentVariableIntValue("QTC_SSH_TEST_PORT");
|
||||
const int port = qtcEnvironmentVariableIntValue("QTC_SSH_TEST_PORT");
|
||||
return port != 0 ? quint16(port) : 22;
|
||||
}
|
||||
|
||||
const QString getUserFromEnvironment()
|
||||
{
|
||||
return QString::fromLocal8Bit(qgetenv("QTC_SSH_TEST_USER"));
|
||||
return qtcEnvironmentVariable("QTC_SSH_TEST_USER");
|
||||
}
|
||||
|
||||
const QString getKeyFileFromEnvironment()
|
||||
{
|
||||
const FilePath defaultKeyFile = FileUtils::homePath() / ".ssh/id_rsa";
|
||||
const QString keyFile = QString::fromLocal8Bit(qgetenv("QTC_SSH_TEST_KEYFILE"));
|
||||
const QString keyFile = qtcEnvironmentVariable("QTC_SSH_TEST_KEYFILE");
|
||||
if (keyFile.isEmpty()) {
|
||||
if (qEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
|
||||
if (qtcEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
|
||||
return defaultKeyFile.toString();
|
||||
}
|
||||
return keyFile;
|
||||
@@ -145,7 +145,7 @@ const QString userAtHost()
|
||||
SshParameters getParameters()
|
||||
{
|
||||
SshParameters params;
|
||||
if (!qEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS")) {
|
||||
if (!qtcEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS")) {
|
||||
params.setUserName(getUserFromEnvironment());
|
||||
params.privateKeyFile = FilePath::fromUserInput(getKeyFileFromEnvironment());
|
||||
}
|
||||
@@ -160,7 +160,7 @@ SshParameters getParameters()
|
||||
|
||||
bool checkParameters(const SshParameters ¶ms)
|
||||
{
|
||||
if (qEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
|
||||
if (qtcEnvironmentVariableIsSet("QTC_SSH_TEST_DEFAULTS"))
|
||||
return true;
|
||||
if (params.host().isEmpty()) {
|
||||
qWarning("No hostname provided. Set QTC_SSH_TEST_HOST.");
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
@@ -492,7 +493,7 @@ static QStringList environmentTemplatesPaths()
|
||||
{
|
||||
QStringList paths;
|
||||
|
||||
QString envTempPath = QString::fromLocal8Bit(qgetenv("QTCREATOR_TEMPLATES_PATH"));
|
||||
QString envTempPath = qtcEnvironmentVariable("QTCREATOR_TEMPLATES_PATH");
|
||||
|
||||
if (!envTempPath.isEmpty()) {
|
||||
for (const QString &path : envTempPath
|
||||
|
@@ -13,13 +13,14 @@
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/optional.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/winutils.h>
|
||||
|
||||
#include <QDir>
|
||||
@@ -196,7 +197,7 @@ static QString windowsProgramFilesDir()
|
||||
#else
|
||||
const char programFilesC[] = "ProgramFiles";
|
||||
#endif
|
||||
return QDir::fromNativeSeparators(QFile::decodeName(qgetenv(programFilesC)));
|
||||
return QDir::fromNativeSeparators(qtcEnvironmentVariable(programFilesC));
|
||||
}
|
||||
|
||||
static Utils::optional<VisualStudioInstallation> installationFromPathAndVersion(
|
||||
@@ -2110,8 +2111,7 @@ Utils::optional<QString> MsvcToolChain::generateEnvironmentSettings(const Utils:
|
||||
runEnv.unset(QLatin1String("ORIGINALPATH"));
|
||||
run.setEnvironment(runEnv);
|
||||
run.setTimeoutS(60);
|
||||
Utils::FilePath cmdPath = Utils::FilePath::fromUserInput(
|
||||
QString::fromLocal8Bit(qgetenv("COMSPEC")));
|
||||
Utils::FilePath cmdPath = Utils::FilePath::fromUserInput(qtcEnvironmentVariable("COMSPEC"));
|
||||
if (cmdPath.isEmpty())
|
||||
cmdPath = env.searchInPath(QLatin1String("cmd.exe"));
|
||||
// Windows SDK setup scripts require command line switches for environment expansion.
|
||||
|
@@ -15,8 +15,9 @@
|
||||
|
||||
#include <app/app_version.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/persistentsettings.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/persistentsettings.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
@@ -184,10 +185,10 @@ static QString generateSuffix(const QString &suffix)
|
||||
// Return path to shared directory for .user files, create if necessary.
|
||||
static inline Utils::optional<QString> defineExternalUserFileDir()
|
||||
{
|
||||
static const char userFilePathVariable[] = "QTC_USER_FILE_PATH";
|
||||
if (Q_LIKELY(!qEnvironmentVariableIsSet(userFilePathVariable)))
|
||||
const char userFilePathVariable[] = "QTC_USER_FILE_PATH";
|
||||
if (Q_LIKELY(!qtcEnvironmentVariableIsSet(userFilePathVariable)))
|
||||
return nullopt;
|
||||
const QFileInfo fi(QFile::decodeName(qgetenv(userFilePathVariable)));
|
||||
const QFileInfo fi(qtcEnvironmentVariable(userFilePathVariable));
|
||||
const QString path = fi.absoluteFilePath();
|
||||
if (fi.isDir() || fi.isSymLink())
|
||||
return path;
|
||||
@@ -379,21 +380,21 @@ QVariant UserFileAccessor::retrieveSharedSettings() const
|
||||
|
||||
FilePath UserFileAccessor::projectUserFile() const
|
||||
{
|
||||
static const QString qtcExt = QLatin1String(qgetenv("QTC_EXTENSION"));
|
||||
static const QString qtcExt = qtcEnvironmentVariable("QTC_EXTENSION");
|
||||
return m_project->projectFilePath()
|
||||
.stringAppended(generateSuffix(qtcExt.isEmpty() ? FILE_EXTENSION_STR : qtcExt));
|
||||
}
|
||||
|
||||
FilePath UserFileAccessor::externalUserFile() const
|
||||
{
|
||||
static const QString qtcExt = QFile::decodeName(qgetenv("QTC_EXTENSION"));
|
||||
static const QString qtcExt = qtcEnvironmentVariable("QTC_EXTENSION");
|
||||
return externalUserFilePath(m_project->projectFilePath(),
|
||||
generateSuffix(qtcExt.isEmpty() ? FILE_EXTENSION_STR : qtcExt));
|
||||
}
|
||||
|
||||
FilePath UserFileAccessor::sharedFile() const
|
||||
{
|
||||
static const QString qtcExt = QLatin1String(qgetenv("QTC_SHARED_EXTENSION"));
|
||||
static const QString qtcExt = qtcEnvironmentVariable("QTC_SHARED_EXTENSION");
|
||||
return m_project->projectFilePath()
|
||||
.stringAppended(generateSuffix(qtcExt.isEmpty() ? ".shared" : qtcExt));
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#include <projectexplorer/taskhub.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
@@ -80,7 +81,7 @@ public:
|
||||
}
|
||||
~OpTimer()
|
||||
{
|
||||
if (qEnvironmentVariableIsSet(Constants::QBS_PROFILING_ENV)) {
|
||||
if (qtcEnvironmentVariableIsSet(Constants::QBS_PROFILING_ENV)) {
|
||||
MessageManager::writeSilently(
|
||||
QString("operation %1 took %2ms").arg(QLatin1String(m_name)).arg(m_timer.elapsed()));
|
||||
}
|
||||
|
@@ -247,10 +247,10 @@ void QbsSession::sendRequest(const QJsonObject &request)
|
||||
qDebug() << request.value("type").toString()
|
||||
<< d->currentRequest.value("type").toString(); return);
|
||||
d->currentRequest = request;
|
||||
const QString logLevelFromEnv = qEnvironmentVariable("QBS_LOG_LEVEL");
|
||||
const QString logLevelFromEnv = qtcEnvironmentVariable("QBS_LOG_LEVEL");
|
||||
if (!logLevelFromEnv.isEmpty())
|
||||
d->currentRequest.insert("log-level", logLevelFromEnv);
|
||||
if (!qEnvironmentVariableIsEmpty(Constants::QBS_PROFILING_ENV))
|
||||
if (!qtcEnvironmentVariableIsEmpty(Constants::QBS_PROFILING_ENV))
|
||||
d->currentRequest.insert("log-time", true);
|
||||
if (d->state == State::Active)
|
||||
sendQueuedRequest();
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include <designer/designerconstants.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
@@ -153,7 +154,7 @@ bool ExternalQtEditor::getEditorLaunchData(const Utils::FilePath &filePath,
|
||||
data->binary = findFirstCommand(qtVersionsToCheck, m_commandForQtVersion);
|
||||
// fallback
|
||||
if (data->binary.isEmpty()) {
|
||||
const QString path = qEnvironmentVariable("PATH");
|
||||
const QString path = qtcEnvironmentVariable("PATH");
|
||||
data->binary = Utils::QtcProcess::locateBinary(path, m_commandForQtVersion(nullptr));
|
||||
}
|
||||
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include <qtsupport/qtversionmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
@@ -35,8 +36,7 @@ namespace Internal {
|
||||
|
||||
static bool debugExamples()
|
||||
{
|
||||
static bool isDebugging = qEnvironmentVariableIsSet("QTC_DEBUG_EXAMPLESMODEL");
|
||||
return isDebugging;
|
||||
return qtcEnvironmentVariableIsSet("QTC_DEBUG_EXAMPLESMODEL");
|
||||
}
|
||||
|
||||
static const char kSelectedExampleSetKey[] = "WelcomePage/SelectedExampleSet";
|
||||
|
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "remotelinuxtr.h"
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -12,7 +13,10 @@ using namespace Utils;
|
||||
|
||||
namespace RemoteLinux {
|
||||
|
||||
static QString defaultDisplay() { return qEnvironmentVariable("DISPLAY"); }
|
||||
static QString defaultDisplay()
|
||||
{
|
||||
return qtcEnvironmentVariable("DISPLAY");
|
||||
}
|
||||
|
||||
X11ForwardingAspect::X11ForwardingAspect(const MacroExpander *expander)
|
||||
: m_macroExpander(expander)
|
||||
|
Reference in New Issue
Block a user