forked from qt-creator/qt-creator
Utils: Use Utils::CommandLine as input for ProcessArgs::prepareCommand
Change-Id: Ib5878a159bda0e6b6253f1f4e1abc1acb5ecb573 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -643,20 +643,20 @@ void ProcessArgs::addArgs(QString *args, const QStringList &inArgs)
|
|||||||
addArg(args, arg);
|
addArg(args, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProcessArgs::prepareCommand(const QString &command, const QString &arguments,
|
bool ProcessArgs::prepareCommand(const CommandLine &cmdLine, QString *outCmd, ProcessArgs *outArgs,
|
||||||
QString *outCmd, ProcessArgs *outArgs, OsType osType,
|
|
||||||
const Environment *env, const FilePath *pwd)
|
const Environment *env, const FilePath *pwd)
|
||||||
{
|
{
|
||||||
|
const FilePath executable = cmdLine.executable();
|
||||||
|
const QString arguments = cmdLine.arguments();
|
||||||
ProcessArgs::SplitError err;
|
ProcessArgs::SplitError err;
|
||||||
*outArgs = ProcessArgs::prepareArgs(arguments, &err, osType, env, pwd);
|
*outArgs = ProcessArgs::prepareArgs(arguments, &err, executable.osType(), env, pwd);
|
||||||
if (err == ProcessArgs::SplitOk) {
|
if (err == ProcessArgs::SplitOk) {
|
||||||
*outCmd = command;
|
*outCmd = executable.toString();
|
||||||
} else {
|
} else {
|
||||||
if (osType == OsTypeWindows) {
|
if (executable.osType() == OsTypeWindows) {
|
||||||
*outCmd = QString::fromLatin1(qgetenv("COMSPEC"));
|
*outCmd = QString::fromLatin1(qgetenv("COMSPEC"));
|
||||||
*outArgs = ProcessArgs::createWindowsArgs(QLatin1String("/v:off /s /c \"")
|
*outArgs = ProcessArgs::createWindowsArgs(QLatin1String("/v:off /s /c \"")
|
||||||
+ quoteArg(QDir::toNativeSeparators(command)) + QLatin1Char(' ') + arguments
|
+ quoteArg(executable.toUserOutput()) + ' ' + arguments + '"');
|
||||||
+ QLatin1Char('"'));
|
|
||||||
} else {
|
} else {
|
||||||
if (err != ProcessArgs::FoundMeta)
|
if (err != ProcessArgs::FoundMeta)
|
||||||
return false;
|
return false;
|
||||||
@@ -667,8 +667,7 @@ bool ProcessArgs::prepareCommand(const QString &command, const QString &argument
|
|||||||
*outCmd = qEnvironmentVariableIsSet("SHELL") ? QString::fromLocal8Bit(qgetenv("SHELL"))
|
*outCmd = qEnvironmentVariableIsSet("SHELL") ? QString::fromLocal8Bit(qgetenv("SHELL"))
|
||||||
: QString("/bin/sh");
|
: QString("/bin/sh");
|
||||||
#endif
|
#endif
|
||||||
*outArgs = ProcessArgs::createUnixArgs(
|
*outArgs = ProcessArgs::createUnixArgs({"-c", quoteArg(executable.toString()) + ' ' + arguments});
|
||||||
QStringList({"-c", (quoteArg(command) + ' ' + arguments)}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class AbstractMacroExpander;
|
class AbstractMacroExpander;
|
||||||
|
class CommandLine;
|
||||||
class Environment;
|
class Environment;
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT ProcessArgs
|
class QTCREATOR_UTILS_EXPORT ProcessArgs
|
||||||
@@ -67,8 +68,7 @@ public:
|
|||||||
const Environment *env = nullptr, const FilePath *pwd = nullptr,
|
const Environment *env = nullptr, const FilePath *pwd = nullptr,
|
||||||
bool abortOnMeta = true);
|
bool abortOnMeta = true);
|
||||||
//! Prepare a shell command for feeding into QProcess
|
//! Prepare a shell command for feeding into QProcess
|
||||||
static bool prepareCommand(const QString &command, const QString &arguments,
|
static bool prepareCommand(const CommandLine &cmdLine, QString *outCmd, ProcessArgs *outArgs,
|
||||||
QString *outCmd, ProcessArgs *outArgs, OsType osType = HostOsInfo::hostOs(),
|
|
||||||
const Environment *env = nullptr, const FilePath *pwd = nullptr);
|
const Environment *env = nullptr, const FilePath *pwd = nullptr);
|
||||||
//! Quote and append each argument to a shell command
|
//! Quote and append each argument to a shell command
|
||||||
static void addArgs(QString *args, const QStringList &inArgs);
|
static void addArgs(QString *args, const QStringList &inArgs);
|
||||||
|
@@ -579,7 +579,6 @@ void QtcProcess::start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Environment env;
|
Environment env;
|
||||||
const OsType osType = HostOsInfo::hostOs();
|
|
||||||
if (d->m_haveEnv) {
|
if (d->m_haveEnv) {
|
||||||
if (d->m_environment.size() == 0)
|
if (d->m_environment.size() == 0)
|
||||||
qWarning("QtcProcess::start: Empty environment set when running '%s'.",
|
qWarning("QtcProcess::start: Empty environment set when running '%s'.",
|
||||||
@@ -595,11 +594,10 @@ void QtcProcess::start()
|
|||||||
|
|
||||||
QString command;
|
QString command;
|
||||||
ProcessArgs arguments;
|
ProcessArgs arguments;
|
||||||
bool success = ProcessArgs::prepareCommand(d->m_commandLine.executable().toString(),
|
bool success = ProcessArgs::prepareCommand(d->m_commandLine, &command, &arguments, &env,
|
||||||
d->m_commandLine.arguments(),
|
|
||||||
&command, &arguments, osType, &env,
|
|
||||||
&d->m_workingDirectory);
|
&d->m_workingDirectory);
|
||||||
if (osType == OsTypeWindows) {
|
|
||||||
|
if (d->m_commandLine.executable().osType() == OsTypeWindows) {
|
||||||
QString args;
|
QString args;
|
||||||
if (d->m_useCtrlCStub) {
|
if (d->m_useCtrlCStub) {
|
||||||
if (d->m_process->lowPriority())
|
if (d->m_process->lowPriority())
|
||||||
|
Reference in New Issue
Block a user