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