From e77c90469bd1b2a503f22e52712726b516d70222 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 24 Aug 2022 09:43:33 +0200 Subject: [PATCH] Utils: 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: I50e457bab2d3495e5c69676fe1a0257a5fea3e52 Reviewed-by: Jarek Kobus Reviewed-by: Qt CI Bot Reviewed-by: hjk --- src/libs/utils/benchmarker.cpp | 3 ++- src/libs/utils/commandline.cpp | 4 ++-- src/libs/utils/filesystemmodel.cpp | 4 +++- src/libs/utils/qtcprocess.cpp | 5 +++-- src/libs/utils/terminalprocess.cpp | 10 +++++----- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/libs/utils/benchmarker.cpp b/src/libs/utils/benchmarker.cpp index 06a8132fb09..dfbdf1242e8 100644 --- a/src/libs/utils/benchmarker.cpp +++ b/src/libs/utils/benchmarker.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 #include "benchmarker.h" +#include "environment.h" #include #include @@ -48,7 +49,7 @@ void Benchmarker::report(const QString &testsuite, void Benchmarker::report(const QLoggingCategory &cat, const QString &testsuite, const QString &testcase, qint64 ms, const QString &tags) { - static const QByteArray quitAfter = qgetenv("QTC_QUIT_AFTER_BENCHMARK"); + static const QByteArray quitAfter = qtcEnvironmentVariable("QTC_QUIT_AFTER_BENCHMARK").toLatin1(); QString t = "unit=ms"; if (!tags.isEmpty()) t += "," + tags; diff --git a/src/libs/utils/commandline.cpp b/src/libs/utils/commandline.cpp index d82448d0e4c..725fbeea24b 100644 --- a/src/libs/utils/commandline.cpp +++ b/src/libs/utils/commandline.cpp @@ -644,13 +644,13 @@ bool ProcessArgs::prepareCommand(const CommandLine &cmdLine, QString *outCmd, Pr *outCmd = executable.toString(); } else { if (executable.osType() == OsTypeWindows) { - *outCmd = QString::fromLatin1(qgetenv("COMSPEC")); + *outCmd = qtcEnvironmentVariable("COMSPEC"); *outArgs = ProcessArgs::createWindowsArgs(QLatin1String("/v:off /s /c \"") + quoteArg(executable.toUserOutput()) + ' ' + arguments + '"'); } else { if (err != ProcessArgs::FoundMeta) return false; - *outCmd = qEnvironmentVariable("SHELL", "/bin/sh"); + *outCmd = qtcEnvironmentVariable("SHELL", "/bin/sh"); *outArgs = ProcessArgs::createUnixArgs({"-c", quoteArg(executable.toString()) + ' ' + arguments}); } } diff --git a/src/libs/utils/filesystemmodel.cpp b/src/libs/utils/filesystemmodel.cpp index 2765d2bfbac..645d979fc9c 100644 --- a/src/libs/utils/filesystemmodel.cpp +++ b/src/libs/utils/filesystemmodel.cpp @@ -3,6 +3,7 @@ #include "filesystemmodel.h" +#include "environment.h" #include "hostosinfo.h" #include "qtcassert.h" @@ -432,7 +433,8 @@ ExtendedInformation FileInfoGatherer::getInfo(const QFileInfo &fileInfo) const info.displayType = m_iconProvider->type(fileInfo); if (useFileSystemWatcher()) { // ### Not ready to listen all modifications by default - static const bool watchFiles = qEnvironmentVariableIsSet("QT_FILESYSTEMMODEL_WATCH_FILES"); + static const bool watchFiles = qtcEnvironmentVariableIsSet( + "QT_FILESYSTEMMODEL_WATCH_FILES"); if (watchFiles) { if (!fileInfo.exists() && !fileInfo.isSymLink()) { const_cast(this)-> diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index bda2cf195ce..d2fc6c3b327 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -4,6 +4,7 @@ #include "qtcprocess.h" #include "algorithm.h" +#include "environment.h" #include "guard.h" #include "hostosinfo.h" #include "launcherinterface.h" @@ -50,7 +51,7 @@ class MeasureAndRun public: MeasureAndRun(const char *functionName) : m_functionName(functionName) - , m_measureProcess(qEnvironmentVariableIsSet("QTC_MEASURE_PROCESS")) + , m_measureProcess(qtcEnvironmentVariableIsSet("QTC_MEASURE_PROCESS")) {} template std::invoke_result_t measureAndRun(Function &&function, Args&&... args) @@ -507,7 +508,7 @@ private: static ProcessImpl defaultProcessImpl() { - if (qEnvironmentVariableIsSet("QTC_USE_QPROCESS")) + if (qtcEnvironmentVariableIsSet("QTC_USE_QPROCESS")) return ProcessImpl::QProcess; return ProcessImpl::ProcessLauncher; } diff --git a/src/libs/utils/terminalprocess.cpp b/src/libs/utils/terminalprocess.cpp index e5b1cdcaac7..c140a1e6e63 100644 --- a/src/libs/utils/terminalprocess.cpp +++ b/src/libs/utils/terminalprocess.cpp @@ -182,15 +182,15 @@ void TerminalImpl::start() QStringList envStrings = env; // add PATH if necessary (for DLL loading) if (envStrings.filter(QRegularExpression("^PATH=.*", QRegularExpression::CaseInsensitiveOption)).isEmpty()) { - QByteArray path = qgetenv("PATH"); + const QString path = qtcEnvironmentVariable("PATH"); if (!path.isEmpty()) - envStrings.prepend(QString::fromLatin1("PATH=%1").arg(QString::fromLocal8Bit(path))); + envStrings.prepend(QString::fromLatin1("PATH=%1").arg(path)); } // add systemroot if needed if (envStrings.filter(QRegularExpression("^SystemRoot=.*", QRegularExpression::CaseInsensitiveOption)).isEmpty()) { - QByteArray systemRoot = qgetenv("SystemRoot"); + const QString systemRoot = qtcEnvironmentVariable("SystemRoot"); if (!systemRoot.isEmpty()) - envStrings.prepend(QString::fromLatin1("SystemRoot=%1").arg(QString::fromLocal8Bit(systemRoot))); + envStrings.prepend(QString::fromLatin1("SystemRoot=%1").arg(systemRoot)); } return envStrings; }(); @@ -324,7 +324,7 @@ void TerminalImpl::start() " is currently not supported.")); return; } - pcmd = qEnvironmentVariable("SHELL", "/bin/sh"); + pcmd = qtcEnvironmentVariable("SHELL", "/bin/sh"); pargs = ProcessArgs::createUnixArgs( {"-c", (ProcessArgs::quoteArg(m_setup.m_commandLine.executable().toString()) + ' ' + m_setup.m_commandLine.arguments())});