From 0567f35e210cb4d40cca124aaf0878a1dd4441e4 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 2 Aug 2021 18:39:02 +0200 Subject: [PATCH] Utils: Use Utils::CommandLine as input for ProcessArgs::prepareCommand Change-Id: Ib5878a159bda0e6b6253f1f4e1abc1acb5ecb573 Reviewed-by: Jarek Kobus --- src/libs/utils/commandline.cpp | 17 ++++++++--------- src/libs/utils/commandline.h | 4 ++-- src/libs/utils/qtcprocess.cpp | 8 +++----- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/libs/utils/commandline.cpp b/src/libs/utils/commandline.cpp index baa848f9e4f..abe74202c93 100644 --- a/src/libs/utils/commandline.cpp +++ b/src/libs/utils/commandline.cpp @@ -643,20 +643,20 @@ void ProcessArgs::addArgs(QString *args, const QStringList &inArgs) addArg(args, arg); } -bool ProcessArgs::prepareCommand(const QString &command, const QString &arguments, - QString *outCmd, ProcessArgs *outArgs, OsType osType, +bool ProcessArgs::prepareCommand(const CommandLine &cmdLine, QString *outCmd, ProcessArgs *outArgs, const Environment *env, const FilePath *pwd) { + const FilePath executable = cmdLine.executable(); + const QString arguments = cmdLine.arguments(); ProcessArgs::SplitError err; - *outArgs = ProcessArgs::prepareArgs(arguments, &err, osType, env, pwd); + *outArgs = ProcessArgs::prepareArgs(arguments, &err, executable.osType(), env, pwd); if (err == ProcessArgs::SplitOk) { - *outCmd = command; + *outCmd = executable.toString(); } else { - if (osType == OsTypeWindows) { + if (executable.osType() == OsTypeWindows) { *outCmd = QString::fromLatin1(qgetenv("COMSPEC")); *outArgs = ProcessArgs::createWindowsArgs(QLatin1String("/v:off /s /c \"") - + quoteArg(QDir::toNativeSeparators(command)) + QLatin1Char(' ') + arguments - + QLatin1Char('"')); + + quoteArg(executable.toUserOutput()) + ' ' + arguments + '"'); } else { if (err != ProcessArgs::FoundMeta) return false; @@ -667,8 +667,7 @@ bool ProcessArgs::prepareCommand(const QString &command, const QString &argument *outCmd = qEnvironmentVariableIsSet("SHELL") ? QString::fromLocal8Bit(qgetenv("SHELL")) : QString("/bin/sh"); #endif - *outArgs = ProcessArgs::createUnixArgs( - QStringList({"-c", (quoteArg(command) + ' ' + arguments)})); + *outArgs = ProcessArgs::createUnixArgs({"-c", quoteArg(executable.toString()) + ' ' + arguments}); } } return true; diff --git a/src/libs/utils/commandline.h b/src/libs/utils/commandline.h index 99c7377f44a..fc1e9566ef5 100644 --- a/src/libs/utils/commandline.h +++ b/src/libs/utils/commandline.h @@ -35,6 +35,7 @@ namespace Utils { class AbstractMacroExpander; +class CommandLine; class Environment; class QTCREATOR_UTILS_EXPORT ProcessArgs @@ -67,8 +68,7 @@ public: const Environment *env = nullptr, const FilePath *pwd = nullptr, bool abortOnMeta = true); //! Prepare a shell command for feeding into QProcess - static bool prepareCommand(const QString &command, const QString &arguments, - QString *outCmd, ProcessArgs *outArgs, OsType osType = HostOsInfo::hostOs(), + static bool prepareCommand(const CommandLine &cmdLine, QString *outCmd, ProcessArgs *outArgs, const Environment *env = nullptr, const FilePath *pwd = nullptr); //! Quote and append each argument to a shell command static void addArgs(QString *args, const QStringList &inArgs); diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index 87997f1e625..34e2248b44e 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -579,7 +579,6 @@ void QtcProcess::start() } Environment env; - const OsType osType = HostOsInfo::hostOs(); if (d->m_haveEnv) { if (d->m_environment.size() == 0) qWarning("QtcProcess::start: Empty environment set when running '%s'.", @@ -595,11 +594,10 @@ void QtcProcess::start() QString command; ProcessArgs arguments; - bool success = ProcessArgs::prepareCommand(d->m_commandLine.executable().toString(), - d->m_commandLine.arguments(), - &command, &arguments, osType, &env, + bool success = ProcessArgs::prepareCommand(d->m_commandLine, &command, &arguments, &env, &d->m_workingDirectory); - if (osType == OsTypeWindows) { + + if (d->m_commandLine.executable().osType() == OsTypeWindows) { QString args; if (d->m_useCtrlCStub) { if (d->m_process->lowPriority())