forked from qt-creator/qt-creator
Utils: Encourage marking of raw command line parameters
Change-Id: Id66ac07732c66ab8c1232fe1f58042de8a61abb0 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -74,6 +74,22 @@ namespace Utils {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
CommandLine::CommandLine(const FilePath &executable)
|
||||||
|
: m_executable(executable)
|
||||||
|
{}
|
||||||
|
|
||||||
|
CommandLine::CommandLine(const FilePath &exe, const QStringList &args)
|
||||||
|
: m_executable(exe)
|
||||||
|
{
|
||||||
|
addArgs(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType)
|
||||||
|
: m_executable(exe)
|
||||||
|
{
|
||||||
|
addArgs(args, Raw);
|
||||||
|
}
|
||||||
|
|
||||||
void CommandLine::addArg(const QString &arg, OsType osType)
|
void CommandLine::addArg(const QString &arg, OsType osType)
|
||||||
{
|
{
|
||||||
QtcProcess::addArg(&m_arguments, arg, osType);
|
QtcProcess::addArg(&m_arguments, arg, osType);
|
||||||
@@ -85,7 +101,7 @@ void CommandLine::addArgs(const QStringList &inArgs, OsType osType)
|
|||||||
addArg(arg, osType);
|
addArg(arg, osType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandLine::addArgs(const QString &inArgs)
|
void CommandLine::addArgs(const QString &inArgs, RawType)
|
||||||
{
|
{
|
||||||
QtcProcess::addArgs(&m_arguments, inArgs);
|
QtcProcess::addArgs(&m_arguments, inArgs);
|
||||||
}
|
}
|
||||||
|
@@ -131,15 +131,17 @@ using FileNameList = FilePathList;
|
|||||||
class QTCREATOR_UTILS_EXPORT CommandLine
|
class QTCREATOR_UTILS_EXPORT CommandLine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CommandLine() {}
|
enum RawType { Raw };
|
||||||
|
|
||||||
CommandLine(const FilePath &executable, const QString &arguments)
|
CommandLine() {}
|
||||||
: m_executable(executable), m_arguments(arguments)
|
explicit CommandLine(const FilePath &executable);
|
||||||
{}
|
CommandLine(const FilePath &exe, const QStringList &args);
|
||||||
|
CommandLine(const FilePath &exe, const QString &unparsedArgs, RawType);
|
||||||
|
|
||||||
void addArg(const QString &arg, OsType osType = HostOsInfo::hostOs());
|
void addArg(const QString &arg, OsType osType = HostOsInfo::hostOs());
|
||||||
void addArgs(const QStringList &inArgs, OsType osType = HostOsInfo::hostOs());
|
void addArgs(const QStringList &inArgs, OsType osType = HostOsInfo::hostOs());
|
||||||
void addArgs(const QString &inArgs);
|
|
||||||
|
void addArgs(const QString &inArgs, RawType);
|
||||||
|
|
||||||
QString toUserOutput() const;
|
QString toUserOutput() const;
|
||||||
|
|
||||||
|
@@ -297,9 +297,9 @@ bool AndroidDeployQtStep::init()
|
|||||||
|
|
||||||
AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy()
|
AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy()
|
||||||
{
|
{
|
||||||
CommandLine cmd(m_command, {});
|
CommandLine cmd(m_command);
|
||||||
if (m_useAndroiddeployqt && m_apkPath.isEmpty()) {
|
if (m_useAndroiddeployqt && m_apkPath.isEmpty()) {
|
||||||
cmd.addArgs(m_androiddeployqtArgs.arguments());
|
cmd.addArgs(m_androiddeployqtArgs.arguments(), CommandLine::Raw);
|
||||||
if (m_uninstallPreviousPackageRun)
|
if (m_uninstallPreviousPackageRun)
|
||||||
cmd.addArg("--install");
|
cmd.addArg("--install");
|
||||||
else
|
else
|
||||||
|
@@ -930,7 +930,7 @@ void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdFutureInterface &fi)
|
|||||||
QtcProcess licenseCommand;
|
QtcProcess licenseCommand;
|
||||||
licenseCommand.setProcessEnvironment(AndroidConfigurations::toolsEnvironment(m_config));
|
licenseCommand.setProcessEnvironment(AndroidConfigurations::toolsEnvironment(m_config));
|
||||||
bool reviewingLicenses = false;
|
bool reviewingLicenses = false;
|
||||||
licenseCommand.setCommand(CommandLine(m_config.sdkManagerToolPath(), "--licenses"));
|
licenseCommand.setCommand(CommandLine(m_config.sdkManagerToolPath(), {"--licenses"}));
|
||||||
if (Utils::HostOsInfo::isWindowsHost())
|
if (Utils::HostOsInfo::isWindowsHost())
|
||||||
licenseCommand.setUseCtrlCStub(true);
|
licenseCommand.setUseCtrlCStub(true);
|
||||||
licenseCommand.start();
|
licenseCommand.start();
|
||||||
|
@@ -112,7 +112,7 @@ QString OpenOcdGdbServerProvider::channel() const
|
|||||||
|
|
||||||
CommandLine OpenOcdGdbServerProvider::command() const
|
CommandLine OpenOcdGdbServerProvider::command() const
|
||||||
{
|
{
|
||||||
CommandLine cmd{m_executableFile, {}};
|
CommandLine cmd{m_executableFile};
|
||||||
|
|
||||||
cmd.addArg("-c");
|
cmd.addArg("-c");
|
||||||
if (startupMode() == StartupOnPipe)
|
if (startupMode() == StartupOnPipe)
|
||||||
@@ -127,7 +127,7 @@ CommandLine OpenOcdGdbServerProvider::command() const
|
|||||||
cmd.addArgs({"-f", m_configurationFile});
|
cmd.addArgs({"-f", m_configurationFile});
|
||||||
|
|
||||||
if (!m_additionalArguments.isEmpty())
|
if (!m_additionalArguments.isEmpty())
|
||||||
cmd.addArgs(m_additionalArguments);
|
cmd.addArgs(m_additionalArguments, CommandLine::Raw);
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
@@ -361,7 +361,7 @@ Utils::CommandLine CMakeBuildStep::cmakeCommand(CMakeRunConfiguration *rc) const
|
|||||||
|
|
||||||
if (!m_toolArguments.isEmpty()) {
|
if (!m_toolArguments.isEmpty()) {
|
||||||
cmd.addArg("--");
|
cmd.addArg("--");
|
||||||
cmd.addArgs(m_toolArguments);
|
cmd.addArgs(m_toolArguments, Utils::CommandLine::Raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
|
@@ -519,7 +519,7 @@ void TeaLeafReader::startCMake(const QStringList &configurationArguments)
|
|||||||
tr("Configuring \"%1\"").arg(m_parameters.projectName),
|
tr("Configuring \"%1\"").arg(m_parameters.projectName),
|
||||||
"CMake.Configure");
|
"CMake.Configure");
|
||||||
|
|
||||||
m_cmakeProcess->setCommand(CommandLine(cmake->cmakeExecutable(), args));
|
m_cmakeProcess->setCommand(CommandLine(cmake->cmakeExecutable(), args, CommandLine::Raw));
|
||||||
emit configurationStarted();
|
emit configurationStarted();
|
||||||
m_cmakeProcess->start();
|
m_cmakeProcess->start();
|
||||||
}
|
}
|
||||||
|
@@ -663,11 +663,11 @@ void ExternalToolRunner::run()
|
|||||||
this, &ExternalToolRunner::readStandardError);
|
this, &ExternalToolRunner::readStandardError);
|
||||||
if (!m_resolvedWorkingDirectory.isEmpty())
|
if (!m_resolvedWorkingDirectory.isEmpty())
|
||||||
m_process->setWorkingDirectory(m_resolvedWorkingDirectory);
|
m_process->setWorkingDirectory(m_resolvedWorkingDirectory);
|
||||||
m_process->setCommand(CommandLine(m_resolvedExecutable, m_resolvedArguments));
|
const CommandLine cmd{m_resolvedExecutable, m_resolvedArguments, CommandLine::Raw};
|
||||||
|
m_process->setCommand(cmd);
|
||||||
m_process->setEnvironment(m_resolvedEnvironment);
|
m_process->setEnvironment(m_resolvedEnvironment);
|
||||||
MessageManager::write(tr("Starting external tool \"%1\" %2")
|
MessageManager::write(tr("Starting external tool \"%1\"")
|
||||||
.arg(m_resolvedExecutable.toUserOutput(), m_resolvedArguments),
|
.arg(cmd.toUserOutput()), MessageManager::Silent);
|
||||||
MessageManager::Silent);
|
|
||||||
m_process->start();
|
m_process->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -169,7 +169,7 @@ void ExecuteFilter::runHeadCommand()
|
|||||||
}
|
}
|
||||||
MessageManager::write(tr("Starting command \"%1\".").arg(headCommand()));
|
MessageManager::write(tr("Starting command \"%1\".").arg(headCommand()));
|
||||||
m_process->setWorkingDirectory(d.workingDirectory);
|
m_process->setWorkingDirectory(d.workingDirectory);
|
||||||
m_process->setCommand(Utils::CommandLine(fullPath, d.arguments));
|
m_process->setCommand({fullPath, d.arguments, Utils::CommandLine::Raw});
|
||||||
m_process->start();
|
m_process->start();
|
||||||
m_process->closeWriteChannel();
|
m_process->closeWriteChannel();
|
||||||
if (!m_process->waitForStarted(1000)) {
|
if (!m_process->waitForStarted(1000)) {
|
||||||
|
@@ -155,7 +155,7 @@ void CppcheckRunner::checkQueued()
|
|||||||
else
|
else
|
||||||
m_queue.begin().value() = files;
|
m_queue.begin().value() = files;
|
||||||
|
|
||||||
m_process->setCommand(CommandLine(FilePath::fromString(m_binary), arguments));
|
m_process->setCommand(CommandLine(FilePath::fromString(m_binary), arguments, CommandLine::Raw));
|
||||||
m_process->start();
|
m_process->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3551,7 +3551,7 @@ void GdbEngine::setupEngine()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdbCommand.addArgs("-i mi");
|
gdbCommand.addArgs({"-i", "mi"});
|
||||||
if (!boolSetting(LoadGdbInit))
|
if (!boolSetting(LoadGdbInit))
|
||||||
gdbCommand.addArg("-n");
|
gdbCommand.addArg("-n");
|
||||||
|
|
||||||
|
@@ -207,7 +207,7 @@ void LldbEngine::setupEngine()
|
|||||||
if (QFileInfo(runParameters().debugger.workingDirectory).isDir())
|
if (QFileInfo(runParameters().debugger.workingDirectory).isDir())
|
||||||
m_lldbProc.setWorkingDirectory(runParameters().debugger.workingDirectory);
|
m_lldbProc.setWorkingDirectory(runParameters().debugger.workingDirectory);
|
||||||
|
|
||||||
m_lldbProc.setCommand(CommandLine(FilePath::fromString(lldbCmd), QString()));
|
m_lldbProc.setCommand(CommandLine(FilePath::fromString(lldbCmd)));
|
||||||
m_lldbProc.start();
|
m_lldbProc.start();
|
||||||
|
|
||||||
if (!m_lldbProc.waitForStarted()) {
|
if (!m_lldbProc.waitForStarted()) {
|
||||||
|
@@ -213,7 +213,9 @@ void AbstractProcessStep::doRun()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommandLine effectiveCommand{d->m_param.effectiveCommand(), d->m_param.effectiveArguments()};
|
const CommandLine effectiveCommand(d->m_param.effectiveCommand(),
|
||||||
|
d->m_param.effectiveArguments(),
|
||||||
|
CommandLine::Raw);
|
||||||
if (!effectiveCommand.executable().exists()) {
|
if (!effectiveCommand.executable().exists()) {
|
||||||
processStartupFailed();
|
processStartupFailed();
|
||||||
finish(false);
|
finish(false);
|
||||||
|
@@ -1551,7 +1551,7 @@ void RunWorker::stop()
|
|||||||
|
|
||||||
CommandLine Runnable::commandLine() const
|
CommandLine Runnable::commandLine() const
|
||||||
{
|
{
|
||||||
return CommandLine(FilePath::fromString(executable), commandLineArguments);
|
return CommandLine(FilePath::fromString(executable), commandLineArguments, CommandLine::Raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runnable::setCommandLine(const CommandLine &cmdLine)
|
void Runnable::setCommandLine(const CommandLine &cmdLine)
|
||||||
|
@@ -299,9 +299,8 @@ void PythonRunConfiguration::updateTargetInformation()
|
|||||||
|
|
||||||
Runnable PythonRunConfiguration::runnable() const
|
Runnable PythonRunConfiguration::runnable() const
|
||||||
{
|
{
|
||||||
CommandLine cmd{executable(), {}};
|
CommandLine cmd{executable(), {mainScript()}};
|
||||||
cmd.addArg(mainScript());
|
cmd.addArgs(aspect<ArgumentsAspect>()->arguments(macroExpander()), CommandLine::Raw);
|
||||||
cmd.addArgs(aspect<ArgumentsAspect>()->arguments(macroExpander()));
|
|
||||||
|
|
||||||
Runnable r;
|
Runnable r;
|
||||||
r.setCommandLine(cmd);
|
r.setCommandLine(cmd);
|
||||||
|
@@ -79,28 +79,28 @@ QString LinuxDeviceProcess::fullCommandLine(const Runnable &runnable) const
|
|||||||
|
|
||||||
for (const QString &filePath : rcFilesToSource()) {
|
for (const QString &filePath : rcFilesToSource()) {
|
||||||
cmd.addArgs({"test", "-f", filePath});
|
cmd.addArgs({"test", "-f", filePath});
|
||||||
cmd.addArgs("&&");
|
cmd.addArgs("&&", CommandLine::Raw);
|
||||||
cmd.addArgs({".", filePath});
|
cmd.addArgs({".", filePath});
|
||||||
cmd.addArgs(";");
|
cmd.addArgs(";", CommandLine::Raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!runnable.workingDirectory.isEmpty()) {
|
if (!runnable.workingDirectory.isEmpty()) {
|
||||||
cmd.addArgs({"cd", runnable.workingDirectory});
|
cmd.addArgs({"cd", runnable.workingDirectory});
|
||||||
cmd.addArgs("&&");
|
cmd.addArgs("&&", CommandLine::Raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!runInTerminal())
|
if (!runInTerminal())
|
||||||
cmd.addArgs("echo $$ && ");
|
cmd.addArgs("echo $$ && ", CommandLine::Raw);
|
||||||
|
|
||||||
const Environment &env = runnable.environment;
|
const Environment &env = runnable.environment;
|
||||||
for (auto it = env.constBegin(); it != env.constEnd(); ++it)
|
for (auto it = env.constBegin(); it != env.constEnd(); ++it)
|
||||||
cmd.addArgs(env.key(it) + "='" + env.value(it) + '\'');
|
cmd.addArgs(env.key(it) + "='" + env.value(it) + '\'', CommandLine::Raw);
|
||||||
|
|
||||||
if (!runInTerminal())
|
if (!runInTerminal())
|
||||||
cmd.addArg("exec");
|
cmd.addArg("exec");
|
||||||
|
|
||||||
cmd.addArg(runnable.executable);
|
cmd.addArg(runnable.executable);
|
||||||
cmd.addArgs(runnable.commandLineArguments);
|
cmd.addArgs(runnable.commandLineArguments, CommandLine::Raw);
|
||||||
|
|
||||||
return cmd.arguments();
|
return cmd.arguments();
|
||||||
}
|
}
|
||||||
|
@@ -159,11 +159,10 @@ void WinRtDeviceFactory::autoDetect()
|
|||||||
this, &WinRtDeviceFactory::onProcessFinished);
|
this, &WinRtDeviceFactory::onProcessFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString args = QStringLiteral("--list-devices");
|
const CommandLine cmd(FilePath::fromString(runnerFilePath), {"--list-devices"});
|
||||||
m_process->setCommand(CommandLine(FilePath::fromString(runnerFilePath), args));
|
m_process->setCommand(cmd);
|
||||||
qCDebug(winrtDeviceLog) << __FUNCTION__ << "Starting process" << runnerFilePath
|
qCDebug(winrtDeviceLog) << __FUNCTION__ << "Starting process" << cmd.toUserOutput();
|
||||||
<< "with arguments" << args;
|
MessageManager::write(cmd.toUserOutput());
|
||||||
MessageManager::write(runnerFilePath + QLatin1Char(' ') + args);
|
|
||||||
m_process->start();
|
m_process->start();
|
||||||
qCDebug(winrtDeviceLog) << __FUNCTION__ << "Process started";
|
qCDebug(winrtDeviceLog) << __FUNCTION__ << "Process started";
|
||||||
}
|
}
|
||||||
|
@@ -94,11 +94,11 @@ WinRtRunnerHelper::WinRtRunnerHelper(ProjectExplorer::RunWorker *runWorker, QStr
|
|||||||
if (auto aspect = runControl->aspect<LoopbackExemptServerAspect>())
|
if (auto aspect = runControl->aspect<LoopbackExemptServerAspect>())
|
||||||
loopbackExemptServer = aspect->value();
|
loopbackExemptServer = aspect->value();
|
||||||
if (loopbackExemptClient && loopbackExemptServer)
|
if (loopbackExemptClient && loopbackExemptServer)
|
||||||
m_loopbackArguments = "--loopbackexempt clientserver";
|
m_loopbackArguments = QStringList{"--loopbackexempt", "clientserver"};
|
||||||
else if (loopbackExemptClient)
|
else if (loopbackExemptClient)
|
||||||
m_loopbackArguments = "--loopbackexempt client";
|
m_loopbackArguments = QStringList{"--loopbackexempt", "client"};
|
||||||
else if (loopbackExemptServer)
|
else if (loopbackExemptServer)
|
||||||
m_loopbackArguments = "--loopbackexempt server";
|
m_loopbackArguments = QStringList{"--loopbackexempt", "server"};
|
||||||
|
|
||||||
if (BuildConfiguration *bc = runControl->target()->activeBuildConfiguration())
|
if (BuildConfiguration *bc = runControl->target()->activeBuildConfiguration())
|
||||||
m_environment = bc->environment();
|
m_environment = bc->environment();
|
||||||
@@ -190,29 +190,29 @@ void WinRtRunnerHelper::startWinRtRunner(const RunConf &conf)
|
|||||||
}
|
}
|
||||||
Q_FALLTHROUGH();
|
Q_FALLTHROUGH();
|
||||||
case Start:
|
case Start:
|
||||||
cmdLine.addArgs("--start --stop --wait 0");
|
cmdLine.addArgs({"--start", "--stop", "--wait", "0"});
|
||||||
connectProcess = true;
|
connectProcess = true;
|
||||||
QTC_ASSERT(!m_process, m_process->deleteLater());
|
QTC_ASSERT(!m_process, m_process->deleteLater());
|
||||||
m_process = new QtcProcess(this);
|
m_process = new QtcProcess(this);
|
||||||
process = m_process;
|
process = m_process;
|
||||||
break;
|
break;
|
||||||
case Stop:
|
case Stop:
|
||||||
cmdLine.addArgs("--stop");
|
cmdLine.addArg("--stop");
|
||||||
process = new QtcProcess(this);
|
process = new QtcProcess(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_device->type() == Constants::WINRT_DEVICE_TYPE_LOCAL)
|
if (m_device->type() == Constants::WINRT_DEVICE_TYPE_LOCAL)
|
||||||
cmdLine.addArgs("--profile appx");
|
cmdLine.addArgs({"--profile", "appx"});
|
||||||
else if (m_device->type() == Constants::WINRT_DEVICE_TYPE_PHONE ||
|
else if (m_device->type() == Constants::WINRT_DEVICE_TYPE_PHONE ||
|
||||||
m_device->type() == Constants::WINRT_DEVICE_TYPE_EMULATOR)
|
m_device->type() == Constants::WINRT_DEVICE_TYPE_EMULATOR)
|
||||||
cmdLine.addArgs("--profile appxphone");
|
cmdLine.addArgs({"--profile", "appxphone"});
|
||||||
|
|
||||||
cmdLine.addArgs(m_loopbackArguments);
|
cmdLine.addArgs(m_loopbackArguments);
|
||||||
cmdLine.addArg(m_executableFilePath);
|
cmdLine.addArg(m_executableFilePath);
|
||||||
cmdLine.addArgs(m_arguments);
|
cmdLine.addArgs(m_arguments, CommandLine::Raw);
|
||||||
|
|
||||||
appendMessage("winrtrunner " + cmdLine.arguments() + '\n', NormalMessageFormat);
|
appendMessage(cmdLine.toUserOutput(), NormalMessageFormat);
|
||||||
|
|
||||||
if (connectProcess) {
|
if (connectProcess) {
|
||||||
connect(process, &QProcess::started, this, &WinRtRunnerHelper::started);
|
connect(process, &QProcess::started, this, &WinRtRunnerHelper::started);
|
||||||
|
@@ -77,7 +77,7 @@ private:
|
|||||||
QString m_debuggerExecutable;
|
QString m_debuggerExecutable;
|
||||||
QString m_debuggerArguments;
|
QString m_debuggerArguments;
|
||||||
QString m_arguments;
|
QString m_arguments;
|
||||||
QString m_loopbackArguments;
|
QStringList m_loopbackArguments;
|
||||||
bool m_uninstallAfterStop = false;
|
bool m_uninstallAfterStop = false;
|
||||||
Utils::QtcProcess *m_process = nullptr;
|
Utils::QtcProcess *m_process = nullptr;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user