forked from qt-creator/qt-creator
Utils: Make SynchronousProcess use Utils::Environment for environments
Makes the interface more similar to QtcProcess. Change-Id: I58e57d9fdb7c37eb0d2a5c5eef8643d6be97c3cc Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -73,7 +73,7 @@ bool AndroidAvdManager::avdManagerCommand(const AndroidConfig &config, const QSt
|
||||
{
|
||||
CommandLine cmd(config.avdManagerToolPath(), args);
|
||||
Utils::SynchronousProcess proc;
|
||||
auto env = AndroidConfigurations::toolsEnvironment(config).toStringList();
|
||||
Environment env = AndroidConfigurations::toolsEnvironment(config);
|
||||
proc.setEnvironment(env);
|
||||
qCDebug(avdManagerLog) << "Running AVD Manager command:" << cmd.toUserOutput();
|
||||
SynchronousProcessResponse response = proc.runBlocking(cmd);
|
||||
|
||||
@@ -1377,15 +1377,15 @@ bool AndroidConfigurations::force32bitEmulator()
|
||||
return m_instance->m_force32bit;
|
||||
}
|
||||
|
||||
QProcessEnvironment AndroidConfigurations::toolsEnvironment(const AndroidConfig &config)
|
||||
Environment AndroidConfigurations::toolsEnvironment(const AndroidConfig &config)
|
||||
{
|
||||
Environment env = Environment::systemEnvironment();
|
||||
Utils::FilePath jdkLocation = config.openJDKLocation();
|
||||
FilePath jdkLocation = config.openJDKLocation();
|
||||
if (!jdkLocation.isEmpty()) {
|
||||
env.set("JAVA_HOME", jdkLocation.toUserOutput());
|
||||
env.prependOrSetPath(jdkLocation.pathAppended("bin").toUserOutput());
|
||||
}
|
||||
return env.toProcessEnvironment();
|
||||
return env;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <qtsupport/qtversionmanager.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
@@ -248,7 +247,7 @@ public:
|
||||
static void removeOldToolChains();
|
||||
static void updateAutomaticKitList();
|
||||
static bool force32bitEmulator();
|
||||
static QProcessEnvironment toolsEnvironment(const AndroidConfig &config);
|
||||
static Utils::Environment toolsEnvironment(const AndroidConfig &config);
|
||||
|
||||
signals:
|
||||
void aboutToUpdate();
|
||||
|
||||
@@ -147,7 +147,7 @@ static bool sdkManagerCommand(const AndroidConfig &config, const QStringList &ar
|
||||
<< CommandLine(config.sdkManagerToolPath(), newArgs)
|
||||
.toUserOutput();
|
||||
SynchronousProcess proc;
|
||||
proc.setProcessEnvironment(AndroidConfigurations::toolsEnvironment(config));
|
||||
proc.setEnvironment(AndroidConfigurations::toolsEnvironment(config));
|
||||
proc.setTimeoutS(timeout);
|
||||
proc.setTimeOutMessageBoxEnabled(true);
|
||||
SynchronousProcessResponse response = proc.run({config.sdkManagerToolPath(), newArgs});
|
||||
@@ -173,7 +173,7 @@ static void sdkManagerCommand(const AndroidConfig &config, const QStringList &ar
|
||||
<< CommandLine(config.sdkManagerToolPath(), newArgs).toUserOutput();
|
||||
int offset = fi.progressValue();
|
||||
SynchronousProcess proc;
|
||||
proc.setProcessEnvironment(AndroidConfigurations::toolsEnvironment(config));
|
||||
proc.setEnvironment(AndroidConfigurations::toolsEnvironment(config));
|
||||
bool assertionFound = false;
|
||||
proc.setStdErrBufferedSignalsEnabled(true);
|
||||
proc.setStdOutBufferedSignalsEnabled(true);
|
||||
@@ -1030,7 +1030,7 @@ void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdFutureInterface &fi)
|
||||
AndroidSdkManager::OperationOutput result;
|
||||
result.type = AndroidSdkManager::LicenseWorkflow;
|
||||
QtcProcess licenseCommand;
|
||||
licenseCommand.setProcessEnvironment(AndroidConfigurations::toolsEnvironment(m_config));
|
||||
licenseCommand.setEnvironment(AndroidConfigurations::toolsEnvironment(m_config));
|
||||
bool reviewingLicenses = false;
|
||||
licenseCommand.setCommand(CommandLine(m_config.sdkManagerToolPath(), {"--licenses", sdkRootArg(m_config)}));
|
||||
if (Utils::HostOsInfo::isWindowsHost())
|
||||
|
||||
@@ -87,7 +87,7 @@ static QString cppLanguageOption(const FilePath &compiler)
|
||||
}
|
||||
|
||||
static Macros dumpPredefinedMacros(const FilePath &compiler, const QStringList &extraArgs,
|
||||
const Utils::Id languageId, const QStringList &env)
|
||||
const Id languageId, const Environment &env)
|
||||
{
|
||||
if (compiler.isEmpty() || !compiler.toFileInfo().isExecutable())
|
||||
return {};
|
||||
@@ -128,8 +128,8 @@ static Macros dumpPredefinedMacros(const FilePath &compiler, const QStringList &
|
||||
return Macro::toMacros(output);
|
||||
}
|
||||
|
||||
static HeaderPaths dumpHeaderPaths(const FilePath &compiler, const Utils::Id languageId,
|
||||
const QStringList &env)
|
||||
static HeaderPaths dumpHeaderPaths(const FilePath &compiler, const Id languageId,
|
||||
const Environment &env)
|
||||
{
|
||||
if (!compiler.exists())
|
||||
return {};
|
||||
@@ -310,7 +310,7 @@ ToolChain::MacroInspectionRunner IarToolChain::createMacroInspectionRunner() con
|
||||
(const QStringList &flags) {
|
||||
Q_UNUSED(flags)
|
||||
|
||||
Macros macros = dumpPredefinedMacros(compiler, extraArgs, languageId, env.toStringList());
|
||||
Macros macros = dumpPredefinedMacros(compiler, extraArgs, languageId, env);
|
||||
macros.append({"__intrinsic", "", MacroType::Define});
|
||||
macros.append({"__nounwind", "", MacroType::Define});
|
||||
macros.append({"__noreturn", "", MacroType::Define});
|
||||
@@ -354,7 +354,7 @@ ToolChain::BuiltInHeaderPathsRunner IarToolChain::createBuiltInHeaderPathsRunner
|
||||
Q_UNUSED(flags)
|
||||
Q_UNUSED(fileName)
|
||||
|
||||
const HeaderPaths paths = dumpHeaderPaths(compiler, languageId, env.toStringList());
|
||||
const HeaderPaths paths = dumpHeaderPaths(compiler, languageId, env);
|
||||
headerPaths->insert({}, paths);
|
||||
|
||||
return paths;
|
||||
@@ -539,8 +539,7 @@ QList<ToolChain *> IarToolChainFactory::autoDetectToolchain(
|
||||
const Candidate &candidate, Utils::Id languageId) const
|
||||
{
|
||||
const auto env = Environment::systemEnvironment();
|
||||
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, {}, languageId,
|
||||
env.toStringList());
|
||||
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, {}, languageId, env);
|
||||
if (macros.isEmpty())
|
||||
return {};
|
||||
const Abi abi = guessAbi(macros);
|
||||
@@ -641,9 +640,8 @@ void IarToolChainConfigWidget::handleCompilerCommandChange()
|
||||
if (haveCompiler) {
|
||||
const auto env = Environment::systemEnvironment();
|
||||
const QStringList extraArgs = splitString(m_platformCodeGenFlagsLineEdit->text());
|
||||
const auto languageId = toolChain()->language();
|
||||
m_macros = dumpPredefinedMacros(compilerPath, extraArgs, languageId,
|
||||
env.toStringList());
|
||||
const Id languageId = toolChain()->language();
|
||||
m_macros = dumpPredefinedMacros(compilerPath, extraArgs, languageId, env);
|
||||
const Abi guessed = guessAbi(m_macros);
|
||||
m_abiWidget->setAbis({}, guessed);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ static Abi::Architecture guessArchitecture(const FilePath &compilerPath)
|
||||
return Abi::Architecture::UnknownArchitecture;
|
||||
}
|
||||
|
||||
static Macros dumpMcsPredefinedMacros(const FilePath &compiler, const QStringList &env)
|
||||
static Macros dumpMcsPredefinedMacros(const FilePath &compiler, const Environment &env)
|
||||
{
|
||||
// Note: The KEIL C51 or C251 compiler does not support the predefined
|
||||
// macros dumping. So, we do it with the following trick, where we try
|
||||
@@ -156,7 +156,7 @@ static Macros dumpMcsPredefinedMacros(const FilePath &compiler, const QStringLis
|
||||
return macros;
|
||||
}
|
||||
|
||||
static Macros dumpC166PredefinedMacros(const FilePath &compiler, const QStringList &env)
|
||||
static Macros dumpC166PredefinedMacros(const FilePath &compiler, const Environment &env)
|
||||
{
|
||||
// Note: The KEIL C166 compiler does not support the predefined
|
||||
// macros dumping. Also, it does not support the '#pragma' and
|
||||
@@ -276,7 +276,7 @@ static Macros dumpC166PredefinedMacros(const FilePath &compiler, const QStringLi
|
||||
return macros;
|
||||
}
|
||||
|
||||
static Macros dumpArmPredefinedMacros(const FilePath &compiler, const QStringList &extraArgs, const QStringList &env)
|
||||
static Macros dumpArmPredefinedMacros(const FilePath &compiler, const QStringList &extraArgs, const Environment &env)
|
||||
{
|
||||
SynchronousProcess cpp;
|
||||
cpp.setEnvironment(env);
|
||||
@@ -314,7 +314,7 @@ static bool isArmArchitecture(Abi::Architecture arch)
|
||||
return arch == Abi::Architecture::ArmArchitecture;
|
||||
}
|
||||
|
||||
static Macros dumpPredefinedMacros(const FilePath &compiler, const QStringList &args, const QStringList &env)
|
||||
static Macros dumpPredefinedMacros(const FilePath &compiler, const QStringList &args, const Environment &env)
|
||||
{
|
||||
if (compiler.isEmpty() || !compiler.toFileInfo().isExecutable())
|
||||
return {};
|
||||
@@ -449,7 +449,7 @@ ToolChain::MacroInspectionRunner KeilToolChain::createMacroInspectionRunner() co
|
||||
return [env, compiler, extraArgs, macroCache, lang](const QStringList &flags) {
|
||||
Q_UNUSED(flags)
|
||||
|
||||
const Macros macros = dumpPredefinedMacros(compiler, extraArgs, env.toStringList());
|
||||
const Macros macros = dumpPredefinedMacros(compiler, extraArgs, env);
|
||||
const auto report = MacroInspectionReport{macros, languageVersion(lang, macros)};
|
||||
macroCache->insert({}, report);
|
||||
|
||||
@@ -692,7 +692,7 @@ QList<ToolChain *> KeilToolChainFactory::autoDetectToolchain(
|
||||
|
||||
QStringList extraArgs;
|
||||
addDefaultCpuArgs(candidate.compilerPath, extraArgs);
|
||||
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, extraArgs, env.toStringList());
|
||||
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, extraArgs, env);
|
||||
if (macros.isEmpty())
|
||||
return {};
|
||||
|
||||
@@ -804,7 +804,7 @@ void KeilToolChainConfigWidget::handleCompilerCommandChange()
|
||||
addDefaultCpuArgs(compilerPath, newExtraArgs);
|
||||
if (prevExtraArgs != newExtraArgs)
|
||||
m_platformCodeGenFlagsLineEdit->setText(QtcProcess::joinArgs(newExtraArgs));
|
||||
m_macros = dumpPredefinedMacros(compilerPath, newExtraArgs, env.toStringList());
|
||||
m_macros = dumpPredefinedMacros(compilerPath, newExtraArgs, env);
|
||||
const Abi guessed = guessAbi(m_macros);
|
||||
m_abiWidget->setAbis({}, guessed);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ static QString compilerTargetFlag(const Abi &abi)
|
||||
}
|
||||
}
|
||||
|
||||
static Macros dumpPredefinedMacros(const FilePath &compiler, const QStringList &env,
|
||||
static Macros dumpPredefinedMacros(const FilePath &compiler, const Environment &env,
|
||||
const Abi &abi)
|
||||
{
|
||||
if (compiler.isEmpty() || !compiler.toFileInfo().isExecutable())
|
||||
@@ -104,7 +104,7 @@ static Macros dumpPredefinedMacros(const FilePath &compiler, const QStringList &
|
||||
return Macro::toMacros(output);
|
||||
}
|
||||
|
||||
static HeaderPaths dumpHeaderPaths(const FilePath &compiler, const QStringList &env,
|
||||
static HeaderPaths dumpHeaderPaths(const FilePath &compiler, const Environment &env,
|
||||
const Abi &abi)
|
||||
{
|
||||
if (!compiler.exists())
|
||||
@@ -234,8 +234,7 @@ ToolChain::MacroInspectionRunner SdccToolChain::createMacroInspectionRunner() co
|
||||
(const QStringList &flags) {
|
||||
Q_UNUSED(flags)
|
||||
|
||||
const Macros macros = dumpPredefinedMacros(compiler, env.toStringList(),
|
||||
abi);
|
||||
const Macros macros = dumpPredefinedMacros(compiler, env, abi);
|
||||
const auto report = MacroInspectionReport{macros, languageVersion(lang, macros)};
|
||||
macrosCache->insert({}, report);
|
||||
|
||||
@@ -264,7 +263,7 @@ ToolChain::BuiltInHeaderPathsRunner SdccToolChain::createBuiltInHeaderPathsRunne
|
||||
const Abi abi = targetAbi();
|
||||
|
||||
return [env, compiler, abi](const QStringList &, const QString &, const QString &) {
|
||||
return dumpHeaderPaths(compiler, env.toStringList(), abi);
|
||||
return dumpHeaderPaths(compiler, env, abi);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -361,8 +360,8 @@ QList<ToolChain *> SdccToolChainFactory::autoDetect(const QList<ToolChain *> &al
|
||||
|
||||
const FilePath fn = compilerPathFromEnvironment("sdcc");
|
||||
if (fn.exists()) {
|
||||
const auto env = Environment::systemEnvironment();
|
||||
const auto macros = dumpPredefinedMacros(fn, env.toStringList(), {});
|
||||
const Environment env = Environment::systemEnvironment();
|
||||
const Macros macros = dumpPredefinedMacros(fn, env, {});
|
||||
const QString version = guessVersion(macros);
|
||||
const Candidate candidate = {fn, version};
|
||||
if (!candidates.contains(candidate))
|
||||
@@ -413,8 +412,7 @@ QList<ToolChain *> SdccToolChainFactory::autoDetectToolchain(
|
||||
// Probe each ABI from the table, because the SDCC compiler
|
||||
// can be compiled with or without the specified architecture.
|
||||
for (const auto &knownAbi : knownAbis) {
|
||||
const Macros macros = dumpPredefinedMacros(candidate.compilerPath,
|
||||
env.toStringList(), knownAbi);
|
||||
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, env, knownAbi);
|
||||
if (macros.isEmpty())
|
||||
continue;
|
||||
const Abi abi = guessAbi(macros);
|
||||
@@ -511,7 +509,7 @@ void SdccToolChainConfigWidget::handleCompilerCommandChange()
|
||||
const bool haveCompiler = compilerExists(compilerPath);
|
||||
if (haveCompiler) {
|
||||
const auto env = Environment::systemEnvironment();
|
||||
m_macros = dumpPredefinedMacros(compilerPath, env.toStringList(), {});
|
||||
m_macros = dumpPredefinedMacros(compilerPath, env, {});
|
||||
const Abi guessed = guessAbi(m_macros);
|
||||
m_abiWidget->setAbis({}, guessed);
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ static QString runExecutable(const Utils::CommandLine &commandLine,
|
||||
return {};
|
||||
|
||||
SynchronousProcess cpp;
|
||||
Utils::Environment env = Environment::systemEnvironment();
|
||||
Environment env = Environment::systemEnvironment();
|
||||
Environment::setupEnglishOutput(&env);
|
||||
cpp.setEnvironment(env.toStringList());
|
||||
cpp.setEnvironment(env);
|
||||
|
||||
const SynchronousProcessResponse response = cpp.runBlocking(commandLine);
|
||||
if (response.result != SynchronousProcessResponse::Finished
|
||||
|
||||
@@ -4976,8 +4976,8 @@ CoreInfo CoreInfo::readExecutableNameFromCore(const Runnable &debugger, const QS
|
||||
args += {"-ex", "core " + coreFile};
|
||||
|
||||
SynchronousProcess proc;
|
||||
QStringList envLang = QProcess::systemEnvironment();
|
||||
Utils::Environment::setupEnglishOutput(&envLang);
|
||||
Environment envLang(QProcess::systemEnvironment());
|
||||
Environment::setupEnglishOutput(&envLang);
|
||||
proc.setEnvironment(envLang);
|
||||
SynchronousProcessResponse response = proc.runBlocking({debugger.executable, args});
|
||||
|
||||
|
||||
@@ -84,8 +84,8 @@ static QByteArray runGcc(const FilePath &gcc, const QStringList &arguments, cons
|
||||
return QByteArray();
|
||||
|
||||
SynchronousProcess cpp;
|
||||
QStringList environment(env);
|
||||
Utils::Environment::setupEnglishOutput(&environment);
|
||||
Environment environment(env);
|
||||
Environment::setupEnglishOutput(&environment);
|
||||
|
||||
cpp.setEnvironment(environment);
|
||||
cpp.setTimeoutS(10);
|
||||
|
||||
@@ -610,7 +610,7 @@ Macros MsvcToolChain::msvcPredefinedMacros(const QStringList &cxxflags,
|
||||
return predefinedMacros;
|
||||
}
|
||||
Utils::SynchronousProcess cpp;
|
||||
cpp.setEnvironment(env.toStringList());
|
||||
cpp.setEnvironment(env);
|
||||
cpp.setWorkingDirectory(Utils::TemporaryDirectory::masterDirectoryPath());
|
||||
QStringList arguments;
|
||||
const Utils::FilePath binary = env.searchInPath(QLatin1String("cl.exe"));
|
||||
@@ -1679,7 +1679,7 @@ Macros ClangClToolChain::msvcPredefinedMacros(const QStringList &cxxflags,
|
||||
return MsvcToolChain::msvcPredefinedMacros(cxxflags, env);
|
||||
|
||||
Utils::SynchronousProcess cpp;
|
||||
cpp.setEnvironment(env.toStringList());
|
||||
cpp.setEnvironment(env);
|
||||
cpp.setWorkingDirectory(Utils::TemporaryDirectory::masterDirectoryPath());
|
||||
|
||||
QStringList arguments = cxxflags;
|
||||
@@ -2011,7 +2011,7 @@ Utils::optional<QString> MsvcToolChain::generateEnvironmentSettings(const Utils:
|
||||
// if Creator is launched within a session set up by setenv.cmd.
|
||||
Utils::Environment runEnv = env;
|
||||
runEnv.unset(QLatin1String("ORIGINALPATH"));
|
||||
run.setEnvironment(runEnv.toStringList());
|
||||
run.setEnvironment(runEnv);
|
||||
run.setTimeoutS(30);
|
||||
Utils::FilePath cmdPath = Utils::FilePath::fromUserInput(
|
||||
QString::fromLocal8Bit(qgetenv("COMSPEC")));
|
||||
|
||||
@@ -105,8 +105,11 @@ FilePath getPylsModulePath(CommandLine pylsCommand)
|
||||
return modulePath;
|
||||
|
||||
pylsCommand.addArg("-h");
|
||||
|
||||
SynchronousProcess pythonProcess;
|
||||
pythonProcess.setEnvironment(pythonProcess.environment() + QStringList("PYTHONVERBOSE=x"));
|
||||
Environment env = pythonProcess.environment();
|
||||
env.set("PYTHONVERBOSE", "x");
|
||||
pythonProcess.setEnvironment(env);
|
||||
SynchronousProcessResponse response = pythonProcess.runBlocking(pylsCommand);
|
||||
|
||||
static const QString pylsInitPattern = "(.*)"
|
||||
|
||||
Reference in New Issue
Block a user