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 <jaroslaw.kobus@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2022-08-24 09:43:33 +02:00
parent 7801fda463
commit e77c90469b
5 changed files with 15 additions and 11 deletions

View File

@@ -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 <QCoreApplication>
#include <QLoggingCategory>
@@ -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;

View File

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

View File

@@ -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<FileInfoGatherer *>(this)->

View File

@@ -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 <typename Function, typename... Args>
std::invoke_result_t<Function, Args...> 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;
}

View File

@@ -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())});