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

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