CommandLine: Reuse new c'tor

Change-Id: Id154881b4f5d8c488e5c1f5e0f843d36bf838759
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2024-05-16 14:07:59 +02:00
parent d857af4cec
commit 982ad24243
39 changed files with 104 additions and 165 deletions

View File

@@ -675,11 +675,9 @@ bool AndroidConfig::isConnected(const QString &serialNumber) const
QString AndroidConfig::getDeviceProperty(const QString &device, const QString &property) QString AndroidConfig::getDeviceProperty(const QString &device, const QString &property)
{ {
// workaround for '????????????' serial numbers // workaround for '????????????' serial numbers
CommandLine cmd(androidConfig().adbToolPath(), AndroidDeviceInfo::adbSelector(device));
cmd.addArgs({"shell", "getprop", property});
Process adbProc; Process adbProc;
adbProc.setCommand(cmd); adbProc.setCommand({androidConfig().adbToolPath(),
{AndroidDeviceInfo::adbSelector(device), "shell", "getprop", property}});
adbProc.runBlocking(); adbProc.runBlocking();
if (adbProc.result() != ProcessResult::FinishedWithSuccess) if (adbProc.result() != ProcessResult::FinishedWithSuccess)
return {}; return {};
@@ -752,10 +750,9 @@ QStringList AndroidConfig::getAbis(const QString &device)
const FilePath adbTool = androidConfig().adbToolPath(); const FilePath adbTool = androidConfig().adbToolPath();
QStringList result; QStringList result;
// First try via ro.product.cpu.abilist // First try via ro.product.cpu.abilist
QStringList arguments = AndroidDeviceInfo::adbSelector(device);
arguments << "shell" << "getprop" << "ro.product.cpu.abilist";
Process adbProc; Process adbProc;
adbProc.setCommand({adbTool, arguments}); adbProc.setCommand({adbTool,
{AndroidDeviceInfo::adbSelector(device), "shell", "getprop", "ro.product.cpu.abilist"}});
adbProc.runBlocking(); adbProc.runBlocking();
if (adbProc.result() != ProcessResult::FinishedWithSuccess) if (adbProc.result() != ProcessResult::FinishedWithSuccess)
return result; return result;
@@ -769,15 +766,13 @@ QStringList AndroidConfig::getAbis(const QString &device)
// Fall back to ro.product.cpu.abi, ro.product.cpu.abi2 ... // Fall back to ro.product.cpu.abi, ro.product.cpu.abi2 ...
for (int i = 1; i < 6; ++i) { for (int i = 1; i < 6; ++i) {
QStringList arguments = AndroidDeviceInfo::adbSelector(device); CommandLine cmd{adbTool, {AndroidDeviceInfo::adbSelector(device), "shell", "getprop"}};
arguments << QLatin1String("shell") << QLatin1String("getprop");
if (i == 1) if (i == 1)
arguments << QLatin1String("ro.product.cpu.abi"); cmd.addArg("ro.product.cpu.abi");
else else
arguments << QString::fromLatin1("ro.product.cpu.abi%1").arg(i); cmd.addArg(QString::fromLatin1("ro.product.cpu.abi%1").arg(i));
Process abiProc; Process abiProc;
abiProc.setCommand({adbTool, arguments}); abiProc.setCommand(cmd);
abiProc.runBlocking(); abiProc.runBlocking();
if (abiProc.result() != ProcessResult::FinishedWithSuccess) if (abiProc.result() != ProcessResult::FinishedWithSuccess)
return result; return result;

View File

@@ -169,7 +169,7 @@ bool AndroidDeployQtStep::init()
return false; return false;
} }
m_androiddeployqtArgs = CommandLine(); m_androiddeployqtArgs = {};
m_androidABIs = AndroidManager::applicationAbis(target()); m_androidABIs = AndroidManager::applicationAbis(target());
if (m_androidABIs.isEmpty()) { if (m_androidABIs.isEmpty()) {
@@ -371,8 +371,7 @@ AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy(QPromise<voi
qCDebug(deployStepLog) << msg; qCDebug(deployStepLog) << msg;
emit addOutput(msg, OutputFormat::NormalMessage); emit addOutput(msg, OutputFormat::NormalMessage);
runCommand({m_adbPath, runCommand({m_adbPath,
AndroidDeviceInfo::adbSelector(m_serialNumber) {AndroidDeviceInfo::adbSelector(m_serialNumber), "uninstall", packageName}});
<< "uninstall" << packageName});
} }
cmd.addArgs(AndroidDeviceInfo::adbSelector(m_serialNumber)); cmd.addArgs(AndroidDeviceInfo::adbSelector(m_serialNumber));
@@ -519,9 +518,8 @@ void AndroidDeployQtStep::runImpl(QPromise<void> &promise)
reportWarningOrError(error, Task::Error); reportWarningOrError(error, Task::Error);
} }
runCommand({m_adbPath, runCommand({m_adbPath, {AndroidDeviceInfo::adbSelector(m_serialNumber), "pull", itr.key(),
AndroidDeviceInfo::adbSelector(m_serialNumber) itr.value().nativePath()}});
<< "pull" << itr.key() << itr.value().nativePath()});
if (!itr.value().exists()) { if (!itr.value().exists()) {
const QString error = Tr::tr("Package deploy: Failed to pull \"%1\" to \"%2\".") const QString error = Tr::tr("Package deploy: Failed to pull \"%1\" to \"%2\".")
.arg(itr.key()) .arg(itr.key())

View File

@@ -690,7 +690,7 @@ void AndroidDeviceManager::setupDevicesWatcher()
HandleDevicesListChange(output); HandleDevicesListChange(output);
}); });
const CommandLine command = CommandLine(androidConfig().adbToolPath(), {"track-devices"}); const CommandLine command{androidConfig().adbToolPath(), {"track-devices"}};
m_adbDeviceWatcherProcess->setCommand(command); m_adbDeviceWatcherProcess->setCommand(command);
m_adbDeviceWatcherProcess->setWorkingDirectory(command.executable().parentDir()); m_adbDeviceWatcherProcess->setWorkingDirectory(command.executable().parentDir());
m_adbDeviceWatcherProcess->setEnvironment(androidConfig().toolsEnvironment()); m_adbDeviceWatcherProcess->setEnvironment(androidConfig().toolsEnvironment());

View File

@@ -639,7 +639,7 @@ bool checkCertificateExists(const FilePath &keystorePath, const QString &keystor
const QString &alias) const QString &alias)
{ {
// assumes that the keystore password is correct // assumes that the keystore password is correct
QStringList arguments = { "-list", "-keystore", keystorePath.toUserOutput(), const QStringList arguments = {"-list", "-keystore", keystorePath.toUserOutput(),
"--storepass", keystorePasswd, "-alias", alias}; "--storepass", keystorePasswd, "-alias", alias};
Process proc; Process proc;

View File

@@ -733,7 +733,8 @@ void AndroidSettingsWidget::downloadOpenSslRepo(const bool silent)
const QString openSslRepo("https://github.com/KDAB/android_openssl.git"); const QString openSslRepo("https://github.com/KDAB/android_openssl.git");
Process *gitCloner = new Process(this); Process *gitCloner = new Process(this);
CommandLine gitCloneCommand("git", {"clone", "--depth=1", openSslRepo, openSslPath.toString()}); const CommandLine gitCloneCommand("git", {"clone", "--depth=1", openSslRepo,
openSslPath.toString()});
gitCloner->setCommand(gitCloneCommand); gitCloner->setCommand(gitCloneCommand);
qCDebug(androidsettingswidget) << "Cloning OpenSSL repo: " << gitCloneCommand.toUserOutput(); qCDebug(androidsettingswidget) << "Cloning OpenSSL repo: " << gitCloneCommand.toUserOutput();

View File

@@ -93,7 +93,7 @@ QList<ITestConfiguration *> CTestTreeItem::testConfigurationsFor(const QStringLi
<< QString::number(testSettings().timeout() / 1000); << QString::number(testSettings().timeout() / 1000);
} }
options << theCTestTool().activeSettingsAsOptions(); options << theCTestTool().activeSettingsAsOptions();
CommandLine command = buildSystem->commandLineForTests(selected, options); const CommandLine command = buildSystem->commandLineForTests(selected, options);
if (command.executable().isEmpty()) if (command.executable().isEmpty())
return {}; return {};

View File

@@ -210,10 +210,8 @@ ProjectExplorer::RunWorker *UvscServerProvider::targetRunner(RunControl *runCont
{ {
// Get uVision executable path. // Get uVision executable path.
const ProcessRunData uv = DebuggerKitAspect::runnable(runControl->kit()); const ProcessRunData uv = DebuggerKitAspect::runnable(runControl->kit());
CommandLine server(uv.command.executable()); const CommandLine server{uv.command.executable(),
server.addArg("-j0"); {"-j0", QStringLiteral("-s%1").arg(m_channel.port())}};
server.addArg(QStringLiteral("-s%1").arg(m_channel.port()));
ProcessRunData r; ProcessRunData r;
r.command = server; r.command = server;
return new UvscServerProviderRunner(runControl, r); return new UvscServerProviderRunner(runControl, r);

View File

@@ -246,11 +246,7 @@ static Macros dumpArmPredefinedMacros(const FilePath &compiler, const QStringLis
{ {
Process cpp; Process cpp;
cpp.setEnvironment(env); cpp.setEnvironment(env);
cpp.setCommand({compiler, {extraArgs, "-E", "--list-macros"}});
QStringList args = extraArgs;
args.push_back("-E");
args.push_back("--list-macros");
cpp.setCommand({compiler, args});
cpp.runBlocking(); cpp.runBlocking();
if (cpp.result() != ProcessResult::FinishedWithSuccess) { if (cpp.result() != ProcessResult::FinishedWithSuccess) {

View File

@@ -947,14 +947,11 @@ VcsCommand *BazaarPluginPrivate::createInitialCheckoutCommand(const QString &url
const QString &localName, const QString &localName,
const QStringList &extraArgs) const QStringList &extraArgs)
{ {
QStringList args;
args << m_client.vcsCommandString(BazaarClient::CloneCommand)
<< extraArgs << url << localName;
Environment env = m_client.processEnvironment(baseDirectory); Environment env = m_client.processEnvironment(baseDirectory);
env.set("BZR_PROGRESS_BAR", "text"); env.set("BZR_PROGRESS_BAR", "text");
auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, env); auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, env);
command->addJob({m_client.vcsBinary(baseDirectory), args}, -1); command->addJob({m_client.vcsBinary(baseDirectory),
{m_client.vcsCommandString(BazaarClient::CloneCommand), extraArgs, url, localName}}, -1);
return command; return command;
} }

View File

@@ -161,13 +161,9 @@ GroupItem clangToolTask(const AnalyzeUnits &units,
process.setWorkingDirectory(input.outputDirPath); // Current clang-cl puts log file into working dir. process.setWorkingDirectory(input.outputDirPath); // Current clang-cl puts log file into working dir.
const ClangToolStorage &data = *storage; const ClangToolStorage &data = *storage;
const CommandLine commandLine{data.executable, {checksArguments(unit, input),
const QStringList args = checksArguments(unit, input) mainToolArguments(data), "--",
+ mainToolArguments(data) clangArguments(unit, input)}};
+ QStringList{"--"}
+ clangArguments(unit, input);
const CommandLine commandLine = {data.executable, args};
qCDebug(LOG).noquote() << "Starting" << commandLine.toUserOutput(); qCDebug(LOG).noquote() << "Starting" << commandLine.toUserOutput();
process.setCommand(commandLine); process.setCommand(commandLine);
}; };

View File

@@ -106,15 +106,14 @@ static ClazyChecks querySupportedClazyChecks(const FilePath &executablePath)
}; };
static const QString queryFlag = "-supported-checks-json"; static const QString queryFlag = "-supported-checks-json";
DataFromProcess<ClazyChecks>::Parameters params(CommandLine(executablePath, {queryFlag}), DataFromProcess<ClazyChecks>::Parameters params({executablePath, {queryFlag}}, parser);
parser);
params.environment.setupEnglishOutput(); params.environment.setupEnglishOutput();
params.errorHandler = handleProcessError; params.errorHandler = handleProcessError;
auto checks = DataFromProcess<ClazyChecks>::getData(params); auto checks = DataFromProcess<ClazyChecks>::getData(params);
if (!checks) { if (!checks) {
// Some clazy 1.6.x versions have a bug where they expect an argument after the // Some clazy 1.6.x versions have a bug where they expect an argument after the
// option. // option.
params.commandLine = CommandLine(executablePath, {queryFlag, "dummy"}); params.commandLine = {executablePath, {queryFlag, "dummy"}};
checks = DataFromProcess<ClazyChecks>::getData(params); checks = DataFromProcess<ClazyChecks>::getData(params);
} }
if (checks) if (checks)

View File

@@ -2265,14 +2265,10 @@ void ClearCasePluginPrivate::diffGraphical(const QString &file1, const QString &
QString ClearCasePluginPrivate::runExtDiff(const FilePath &workingDir, const QStringList &arguments, QString ClearCasePluginPrivate::runExtDiff(const FilePath &workingDir, const QStringList &arguments,
int timeOutS, QTextCodec *outputCodec) int timeOutS, QTextCodec *outputCodec)
{ {
CommandLine diff("diff");
diff.addArgs(m_settings.diffArgs.split(' ', Qt::SkipEmptyParts));
diff.addArgs(arguments);
Process process; Process process;
process.setWorkingDirectory(workingDir); process.setWorkingDirectory(workingDir);
process.setCodec(outputCodec ? outputCodec : QTextCodec::codecForName("UTF-8")); process.setCodec(outputCodec ? outputCodec : QTextCodec::codecForName("UTF-8"));
process.setCommand(diff); process.setCommand({"diff", {m_settings.diffArgs.split(' ', Qt::SkipEmptyParts), arguments}});
process.runBlocking(seconds(timeOutS), EventLoopMode::On); process.runBlocking(seconds(timeOutS), EventLoopMode::On);
if (process.result() != ProcessResult::FinishedWithSuccess) if (process.result() != ProcessResult::FinishedWithSuccess)
return {}; return {};

View File

@@ -2056,19 +2056,17 @@ const QList<TestCaseInfo> CMakeBuildSystem::testcasesInfo() const
CommandLine CMakeBuildSystem::commandLineForTests(const QList<QString> &tests, CommandLine CMakeBuildSystem::commandLineForTests(const QList<QString> &tests,
const QStringList &options) const const QStringList &options) const
{ {
QStringList args = options;
const QSet<QString> testsSet = Utils::toSet(tests); const QSet<QString> testsSet = Utils::toSet(tests);
auto current = Utils::transform<QSet<QString>>(m_testNames, &TestCaseInfo::name); const auto current = Utils::transform<QSet<QString>>(m_testNames, &TestCaseInfo::name);
if (tests.isEmpty() || current == testsSet) if (tests.isEmpty() || current == testsSet)
return {m_ctestPath, args}; return {m_ctestPath, options};
QString testNumbers("0,0,0"); // start, end, stride QString testNumbers("0,0,0"); // start, end, stride
for (const TestCaseInfo &info : m_testNames) { for (const TestCaseInfo &info : m_testNames) {
if (testsSet.contains(info.name)) if (testsSet.contains(info.name))
testNumbers += QString(",%1").arg(info.number); testNumbers += QString(",%1").arg(info.number);
} }
args << "-I" << testNumbers; return {m_ctestPath, {options, "-I", testNumbers}};
return {m_ctestPath, args};
} }
DeploymentData CMakeBuildSystem::deploymentDataFromFile() const DeploymentData CMakeBuildSystem::deploymentDataFromFile() const

View File

@@ -131,7 +131,7 @@ void CppcheckRunner::checkQueued()
else else
m_queue.begin().value() = files; m_queue.begin().value() = files;
m_process.setCommand(CommandLine(m_binary, arguments, CommandLine::Raw)); m_process.setCommand({m_binary, arguments, CommandLine::Raw});
m_process.start(); m_process.start();
} }

View File

@@ -282,7 +282,7 @@ void CdbEngine::setupEngine()
DebuggerRunParameters sp = runParameters(); DebuggerRunParameters sp = runParameters();
if (terminal()) { if (terminal()) {
m_effectiveStartMode = AttachToLocalProcess; m_effectiveStartMode = AttachToLocalProcess;
sp.inferior.command = CommandLine(); sp.inferior.command = {};
sp.attachPID = ProcessHandle(terminal()->applicationPid()); sp.attachPID = ProcessHandle(terminal()->applicationPid());
sp.startMode = AttachToLocalProcess; sp.startMode = AttachToLocalProcess;
sp.useTerminal = false; // Force no terminal. sp.useTerminal = false; // Force no terminal.

View File

@@ -41,7 +41,7 @@ bool DockerApi::canConnect()
bool result = false; bool result = false;
process.setCommand(CommandLine(dockerExe, QStringList{"info"})); process.setCommand({dockerExe, {"info"}});
connect(&process, &Process::done, [&process, &result] { connect(&process, &Process::done, [&process, &result] {
qCInfo(dockerApiLog) << "'docker info' result:\n" << qPrintable(process.allOutput()); qCInfo(dockerApiLog) << "'docker info' result:\n" << qPrintable(process.allOutput());
if (process.result() == ProcessResult::FinishedWithSuccess) if (process.result() == ProcessResult::FinishedWithSuccess)
@@ -115,8 +115,7 @@ QFuture<Utils::expected_str<QList<Network>>> DockerApi::networks()
if (dockerExe.isEmpty() || !dockerExe.isExecutableFile()) if (dockerExe.isEmpty() || !dockerExe.isExecutableFile())
return make_unexpected(Tr::tr("Docker executable not found")); return make_unexpected(Tr::tr("Docker executable not found"));
process.setCommand( process.setCommand({dockerExe, {"network", "ls", "--format", "{{json .}}"}});
CommandLine(dockerExe, QStringList{"network", "ls", "--format", "{{json .}}"}));
process.runBlocking(); process.runBlocking();
if (process.result() != ProcessResult::FinishedWithSuccess) { if (process.result() != ProcessResult::FinishedWithSuccess) {

View File

@@ -958,12 +958,9 @@ VcsCommand *FossilPluginPrivate::createInitialCheckoutCommand(const QString &sou
// //
// So here we want Fossil to save the remote details when specified. // So here we want Fossil to save the remote details when specified.
QStringList args; command->addJob({fossilClient().vcsBinary(checkoutPath),
args << fossilClient().vcsCommandString(FossilClient::CloneCommand) {fossilClient().vcsCommandString(FossilClient::CloneCommand), extraOptions,
<< extraOptions sourceUrl, fossilFileNative}}, -1);
<< sourceUrl
<< fossilFileNative;
command->addJob({fossilClient().vcsBinary(checkoutPath), args}, -1);
} }
// check out the cloned repository file into the working copy directory; // check out the cloned repository file into the working copy directory;
@@ -977,15 +974,14 @@ VcsCommand *FossilPluginPrivate::createInitialCheckoutCommand(const QString &sou
// set user default to admin user if specified // set user default to admin user if specified
if (!isLocalRepository if (!isLocalRepository
&& !adminUser.isEmpty()) { && !adminUser.isEmpty()) {
const QStringList args({ "user", "default", adminUser, "--user", adminUser}); command->addJob({fossilClient().vcsBinary(checkoutPath),
command->addJob({fossilClient().vcsBinary(checkoutPath), args}, -1); {"user", "default", adminUser, "--user", adminUser}}, -1);
} }
// turn-off autosync if requested // turn-off autosync if requested
if (!isLocalRepository if (!isLocalRepository && disableAutosync) {
&& disableAutosync) { command->addJob({fossilClient().vcsBinary(checkoutPath), {"settings", "autosync", "off"}},
const QStringList args({"settings", "autosync", "off"}); -1);
command->addJob({fossilClient().vcsBinary(checkoutPath), args}, -1);
} }
return command; return command;

View File

@@ -1766,13 +1766,11 @@ VcsCommand *GitPluginPrivate::createInitialCheckoutCommand(const QString &url,
const QString &localName, const QString &localName,
const QStringList &extraArgs) const QStringList &extraArgs)
{ {
QStringList args = {"clone", "--progress"};
args << extraArgs << url << localName;
auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, auto command = VcsBaseClient::createVcsCommand(this, baseDirectory,
gitClient().processEnvironment(baseDirectory)); gitClient().processEnvironment(baseDirectory));
command->addFlags(RunFlags::SuppressStdErr); command->addFlags(RunFlags::SuppressStdErr);
command->addJob({gitClient().vcsBinary(baseDirectory), args}, -1); command->addJob({gitClient().vcsBinary(baseDirectory),
{"clone", "--progress", extraArgs, url, localName}}, -1);
return command; return command;
} }

View File

@@ -35,9 +35,7 @@ MergeTool::MergeTool(QObject *parent) : QObject(parent)
void MergeTool::start(const FilePath &workingDirectory, const QStringList &files) void MergeTool::start(const FilePath &workingDirectory, const QStringList &files)
{ {
QStringList arguments; const CommandLine cmd{gitClient().vcsBinary(workingDirectory), {"mergetool", "-y", files}};
arguments << "mergetool" << "-y" << files;
const CommandLine cmd = {gitClient().vcsBinary(workingDirectory), arguments};
VcsOutputWindow::appendCommand(workingDirectory, cmd); VcsOutputWindow::appendCommand(workingDirectory, cmd);
m_process.setCommand(cmd); m_process.setCommand(cmd);
m_process.setWorkingDirectory(workingDirectory); m_process.setWorkingDirectory(workingDirectory);

View File

@@ -237,7 +237,7 @@ GroupItem DeviceCtlRunner::launchTask(const QString &bundleIdentifier)
return SetupResult::StopWithError; return SetupResult::StopWithError;
} }
process.setCommand({FilePath::fromString("/usr/bin/xcrun"), process.setCommand({FilePath::fromString("/usr/bin/xcrun"),
QStringList{"devicectl", {"devicectl",
"device", "device",
"process", "process",
"launch", "launch",
@@ -246,8 +246,8 @@ GroupItem DeviceCtlRunner::launchTask(const QString &bundleIdentifier)
"--quiet", "--quiet",
"--json-output", "--json-output",
"-", "-",
bundleIdentifier} bundleIdentifier,
+ m_arguments}); m_arguments}});
return SetupResult::Continue; return SetupResult::Continue;
}; };
const auto onDone = [this](const Process &process, DoneWith result) { const auto onDone = [this](const Process &process, DoneWith result) {

View File

@@ -86,20 +86,18 @@ static expected_str<void> runCommand(
} }
static expected_str<void> runSimCtlCommand( static expected_str<void> runSimCtlCommand(
QStringList args, const QStringList &args,
QString *output, QString *output,
QString *allOutput = nullptr, QString *allOutput = nullptr,
std::function<bool()> shouldStop = [] { return false; }) std::function<bool()> shouldStop = [] { return false; })
{ {
args.prepend("simctl");
// Cache xcrun's path, as this function will be called often. // Cache xcrun's path, as this function will be called often.
static FilePath xcrun = FilePath::fromString("xcrun").searchInPath(); static FilePath xcrun = FilePath::fromString("xcrun").searchInPath();
if (xcrun.isEmpty()) if (xcrun.isEmpty())
return make_unexpected(Tr::tr("Cannot find xcrun.")); return make_unexpected(Tr::tr("Cannot find xcrun."));
else if (!xcrun.isExecutableFile()) else if (!xcrun.isExecutableFile())
return make_unexpected(Tr::tr("xcrun is not executable.")); return make_unexpected(Tr::tr("xcrun is not executable."));
return runCommand({xcrun, args}, output, allOutput, shouldStop); return runCommand({xcrun, {"simctl", args}}, output, allOutput, shouldStop);
} }
static expected_str<void> launchSimulator(const QString &simUdid, std::function<bool()> shouldStop) static expected_str<void> launchSimulator(const QString &simUdid, std::function<bool()> shouldStop)

View File

@@ -734,11 +734,9 @@ VcsCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString &
const QString &localName, const QString &localName,
const QStringList &extraArgs) const QStringList &extraArgs)
{ {
QStringList args;
args << QLatin1String("clone") << extraArgs << url << localName;
auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, auto command = VcsBaseClient::createVcsCommand(this, baseDirectory,
mercurialClient().processEnvironment(baseDirectory)); mercurialClient().processEnvironment(baseDirectory));
command->addJob({settings().binaryPath(), args}, -1); command->addJob({settings().binaryPath(), {"clone", extraArgs, url, localName}}, -1);
return command; return command;
} }

View File

@@ -52,8 +52,7 @@ void PerforceChecker::resetOverrideCursor()
} }
void PerforceChecker::start(const FilePath &binary, const FilePath &workingDirectory, void PerforceChecker::start(const FilePath &binary, const FilePath &workingDirectory,
const QStringList &basicArgs, const QStringList &basicArgs, int timeoutMS)
int timeoutMS)
{ {
if (isRunning()) { if (isRunning()) {
emitFailed(QLatin1String("Internal error: process still running")); emitFailed(QLatin1String("Internal error: process still running"));
@@ -64,13 +63,10 @@ void PerforceChecker::start(const FilePath &binary, const FilePath &workingDirec
return; return;
} }
m_binary = binary; m_binary = binary;
QStringList args = basicArgs;
args << QLatin1String("client") << QLatin1String("-o");
if (!workingDirectory.isEmpty()) if (!workingDirectory.isEmpty())
m_process.setWorkingDirectory(workingDirectory); m_process.setWorkingDirectory(workingDirectory);
m_process.setCommand({m_binary, args}); m_process.setCommand({m_binary, {basicArgs, "client", "-o"}});
m_process.start(); m_process.start();
// Timeout handling // Timeout handling
m_timeOutMS = timeoutMS; m_timeOutMS = timeoutMS;

View File

@@ -1793,11 +1793,7 @@ Macros ClangClToolchain::msvcPredefinedMacros(const QStringList &cxxflags,
Process cpp; Process cpp;
cpp.setEnvironment(env); cpp.setEnvironment(env);
cpp.setWorkingDirectory(Utils::TemporaryDirectory::masterDirectoryFilePath()); cpp.setWorkingDirectory(Utils::TemporaryDirectory::masterDirectoryFilePath());
cpp.setCommand({compilerCommand(), {cxxflags, gccPredefinedMacrosOptions(language()), "-"}});
QStringList arguments = cxxflags;
arguments.append(gccPredefinedMacrosOptions(language()));
arguments.append("-");
cpp.setCommand({compilerCommand(), arguments});
cpp.runBlocking(); cpp.runBlocking();
if (cpp.result() != ProcessResult::FinishedWithSuccess) { if (cpp.result() != ProcessResult::FinishedWithSuccess) {
// Show the warning but still parse the output. // Show the warning but still parse the output.

View File

@@ -121,11 +121,9 @@ void openPythonRepl(QObject *parent, const FilePath &file, ReplType type)
return file.absolutePath(); return file.absolutePath();
}; };
const auto args = QStringList{"-i"} + replImportArgs(file, type);
const FilePath pythonCommand = detectPython(file); const FilePath pythonCommand = detectPython(file);
Process process; Process process;
process.setCommand({pythonCommand, args}); process.setCommand({pythonCommand, {"-i", replImportArgs(file, type)}});
process.setWorkingDirectory(workingDir(file)); process.setWorkingDirectory(workingDir(file));
process.setTerminalMode(TerminalMode::Detached); process.setTerminalMode(TerminalMode::Detached);
process.start(); process.start();
@@ -201,7 +199,7 @@ static bool isUsableHelper(QHash<FilePath, bool> *cache, const QString &keyStrin
if (it == cache->end()) { if (it == cache->end()) {
const Key key = keyFromString(keyString); const Key key = keyFromString(keyString);
Process process; Process process;
process.setCommand({python, QStringList{"-m", commandArg, "-h"}}); process.setCommand({python, {"-m", commandArg, "-h"}});
process.runBlocking(); process.runBlocking();
const bool usable = process.result() == ProcessResult::FinishedWithSuccess; const bool usable = process.result() == ProcessResult::FinishedWithSuccess;
it = cache->insert(python, usable); it = cache->insert(python, usable);

View File

@@ -188,7 +188,7 @@ bool QMakeStep::init()
else else
workingDirectory = qmakeBc->buildDirectory(); workingDirectory = qmakeBc->buildDirectory();
m_qmakeCommand = CommandLine{qtVersion->qmakeFilePath(), allArguments(qtVersion), CommandLine::Raw}; m_qmakeCommand = {qtVersion->qmakeFilePath(), allArguments(qtVersion), CommandLine::Raw};
m_runMakeQmake = (qtVersion->qtVersion() >= QVersionNumber(5, 0 ,0)); m_runMakeQmake = (qtVersion->qtVersion() >= QVersionNumber(5, 0 ,0));
// The Makefile is used by qmake and make on the build device, from that // The Makefile is used by qmake and make on the build device, from that
@@ -216,7 +216,7 @@ bool QMakeStep::init()
OutputFormat::ErrorMessage); OutputFormat::ErrorMessage);
return false; return false;
} }
m_makeCommand = CommandLine{make, makeArguments(makeFile.path()), CommandLine::Raw}; m_makeCommand = {make, makeArguments(makeFile.path()), CommandLine::Raw};
} else { } else {
m_makeCommand = {}; m_makeCommand = {};
} }

View File

@@ -470,12 +470,10 @@ qint64 SshProcessInterface::processId() const
ProcessResult SshProcessInterface::runInShell(const CommandLine &command, const QByteArray &data) ProcessResult SshProcessInterface::runInShell(const CommandLine &command, const QByteArray &data)
{ {
Process process; Process process;
CommandLine cmd = {d->m_device->filePath("/bin/sh"), {"-c"}};
QString tmp; QString tmp;
ProcessArgs::addArg(&tmp, command.executable().path()); ProcessArgs::addArg(&tmp, command.executable().path());
ProcessArgs::addArgs(&tmp, command.arguments()); ProcessArgs::addArgs(&tmp, command.arguments());
cmd.addArg(tmp); process.setCommand({d->m_device->filePath("/bin/sh"), {"-c", tmp}});
process.setCommand(cmd);
process.setWriteData(data); process.setWriteData(data);
using namespace std::chrono_literals; using namespace std::chrono_literals;
process.runBlocking(2s); process.runBlocking(2s);
@@ -524,7 +522,7 @@ void SshProcessInterface::handleSendControlSignal(ControlSignal controlSignal)
QTC_ASSERT(pid, return); // TODO: try sending a signal based on process name QTC_ASSERT(pid, return); // TODO: try sending a signal based on process name
const QString args = QString::fromLatin1("-%1 -%2") const QString args = QString::fromLatin1("-%1 -%2")
.arg(controlSignalToInt(controlSignal)).arg(pid); .arg(controlSignalToInt(controlSignal)).arg(pid);
const CommandLine command = { "kill", args, CommandLine::Raw }; const CommandLine command{"kill", args, CommandLine::Raw};
// Killing by using the pid as process group didn't work // Killing by using the pid as process group didn't work
// Fallback to killing the pid directly // Fallback to killing the pid directly
@@ -532,7 +530,7 @@ void SshProcessInterface::handleSendControlSignal(ControlSignal controlSignal)
if (runInShell(command, {}) != ProcessResult::FinishedWithSuccess) { if (runInShell(command, {}) != ProcessResult::FinishedWithSuccess) {
const QString args = QString::fromLatin1("-%1 %2") const QString args = QString::fromLatin1("-%1 %2")
.arg(controlSignalToInt(controlSignal)).arg(pid); .arg(controlSignalToInt(controlSignal)).arg(pid);
const CommandLine command = { "kill" , args, CommandLine::Raw }; const CommandLine command{"kill" , args, CommandLine::Raw};
runInShell(command, {}); runInShell(command, {});
} }
} }
@@ -1487,7 +1485,7 @@ private:
if (file.m_targetPermissions == FilePermissions::ForceExecutable) if (file.m_targetPermissions == FilePermissions::ForceExecutable)
batchData += "chmod 1775 " + target + '\n'; batchData += "chmod 1775 " + target + '\n';
} }
process().setCommand({sftpBinary, fullConnectionOptions() << "-b" << "-" << host()}); process().setCommand({sftpBinary, {fullConnectionOptions(), "-b", "-", host()}});
process().setWriteData(batchData); process().setWriteData(batchData);
process().start(); process().start();
} }

View File

@@ -245,7 +245,7 @@ void MakeInstallStep::updateArgsFromAspect()
void MakeInstallStep::updateFullCommandLine() void MakeInstallStep::updateFullCommandLine()
{ {
CommandLine cmd{makeExecutable(), userArguments(), CommandLine::Raw}; const CommandLine cmd{makeExecutable(), userArguments(), CommandLine::Raw};
m_fullCommand.setValue(cmd.toUserOutput()); m_fullCommand.setValue(cmd.toUserOutput());
} }

View File

@@ -110,11 +110,11 @@ void SshKeyCreationDialog::generateKeys()
const QString keyTypeString = QLatin1String(m_rsa->isChecked() ? "rsa": "ecdsa"); const QString keyTypeString = QLatin1String(m_rsa->isChecked() ? "rsa": "ecdsa");
QApplication::setOverrideCursor(Qt::BusyCursor); QApplication::setOverrideCursor(Qt::BusyCursor);
Process keygen; Process keygen;
const QStringList args{"-t", keyTypeString, "-b", m_comboBox->currentText(), keygen.setCommand({SshSettings::keygenFilePath(),
"-N", QString(), "-f", privateKeyFilePath().path()}; {"-t", keyTypeString, "-b", m_comboBox->currentText(), "-N", QString(), "-f",
QString errorMsg; privateKeyFilePath().path()}});
keygen.setCommand({SshSettings::keygenFilePath(), args});
keygen.start(); keygen.start();
QString errorMsg;
if (!keygen.waitForFinished()) if (!keygen.waitForFinished())
errorMsg = keygen.errorString(); errorMsg = keygen.errorString();
else if (keygen.exitCode() != 0) else if (keygen.exitCode() != 0)

View File

@@ -698,7 +698,7 @@ void CropAndTrimDialog::startFrameFetch()
if (m_nextFetchFrame == -1) if (m_nextFetchFrame == -1)
return; return;
const CommandLine cl = { const CommandLine cl{
Internal::settings().ffmpegTool(), Internal::settings().ffmpegTool(),
{ {
"-v", "error", "-v", "error",

View File

@@ -152,7 +152,7 @@ static QVersionNumber parseVersionNumber(const QByteArray &toolOutput)
QVersionNumber toolVersion() QVersionNumber toolVersion()
{ {
Process proc; Process proc;
const CommandLine cl = { const CommandLine cl{
Internal::settings().ffprobeTool(), Internal::settings().ffprobeTool(),
{ {
"-v", "quiet", "-v", "quiet",
@@ -201,7 +201,7 @@ static ClipInfo parseClipInfo(const QByteArray &toolOutput)
ClipInfo clipInfo(const FilePath &path) ClipInfo clipInfo(const FilePath &path)
{ {
Process proc; Process proc;
const CommandLine cl = { const CommandLine cl{
Internal::settings().ffprobeTool(), Internal::settings().ffprobeTool(),
{ {
"-v", "quiet", "-v", "quiet",

View File

@@ -26,9 +26,8 @@ void SquishServerProcess::stop()
{ {
if (m_process.state() != QProcess::NotRunning && m_serverPort > 0) { if (m_process.state() != QProcess::NotRunning && m_serverPort > 0) {
Utils::Process serverKiller; Utils::Process serverKiller;
QStringList args; serverKiller.setCommand({m_process.commandLine().executable(),
args << "--stop" << "--port" << QString::number(m_serverPort); {"--stop", "--port", QString::number(m_serverPort)}});
serverKiller.setCommand({m_process.commandLine().executable(), args});
serverKiller.setEnvironment(m_process.environment()); serverKiller.setEnvironment(m_process.environment());
serverKiller.start(); serverKiller.start();
if (!serverKiller.waitForFinished()) { if (!serverKiller.waitForFinished()) {

View File

@@ -554,8 +554,8 @@ void SquishTools::startSquishServer(Request request)
m_perspective.updateStatus(Tr::tr("Running test case")); m_perspective.updateStatus(Tr::tr("Running test case"));
} }
const QStringList arguments = serverArgumentsFromSettings(); m_serverProcess.start({toolsSettings.serverPath, serverArgumentsFromSettings()},
m_serverProcess.start({toolsSettings.serverPath, arguments}, squishEnvironment()); squishEnvironment());
} }
void SquishTools::stopSquishServer() void SquishTools::stopSquishServer()
@@ -569,13 +569,10 @@ void SquishTools::startSquishRunner()
if (!isValidToStartRunner() || !setupRunnerPath()) if (!isValidToStartRunner() || !setupRunnerPath())
return; return;
const QStringList args = runnerArgumentsFromSettings();
if (m_request == RecordTestRequested) if (m_request == RecordTestRequested)
m_closeRunnerOnEndRecord = true; m_closeRunnerOnEndRecord = true;
Utils::CommandLine cmdLine = {toolsSettings.runnerPath, args}; setupAndStartSquishRunnerProcess({toolsSettings.runnerPath, runnerArgumentsFromSettings()});
setupAndStartSquishRunnerProcess(cmdLine);
} }
void SquishTools::setupAndStartRecorder() void SquishTools::setupAndStartRecorder()
@@ -604,7 +601,7 @@ void SquishTools::setupAndStartRecorder()
m_secondaryRunner = new SquishRunnerProcess(this); m_secondaryRunner = new SquishRunnerProcess(this);
m_secondaryRunner->setupProcess(SquishRunnerProcess::Record); m_secondaryRunner->setupProcess(SquishRunnerProcess::Record);
const CommandLine cmd = {toolsSettings.runnerPath, args}; const CommandLine cmd{toolsSettings.runnerPath, args};
connect(m_secondaryRunner, &SquishRunnerProcess::recorderDone, connect(m_secondaryRunner, &SquishRunnerProcess::recorderDone,
this, &SquishTools::onRecorderFinished); this, &SquishTools::onRecorderFinished);
qCDebug(LOG) << "Recorder starting:" << cmd.toUserOutput(); qCDebug(LOG) << "Recorder starting:" << cmd.toUserOutput();
@@ -629,7 +626,7 @@ void SquishTools::setupAndStartInspector()
m_secondaryRunner = new SquishRunnerProcess(this); m_secondaryRunner = new SquishRunnerProcess(this);
m_secondaryRunner->setupProcess(SquishRunnerProcess::Inspect); m_secondaryRunner->setupProcess(SquishRunnerProcess::Inspect);
const CommandLine cmd = {toolsSettings.runnerPath, args}; const CommandLine cmd{toolsSettings.runnerPath, args};
connect(m_secondaryRunner, &SquishRunnerProcess::logOutputReceived, connect(m_secondaryRunner, &SquishRunnerProcess::logOutputReceived,
this, &SquishTools::logOutputReceived); this, &SquishTools::logOutputReceived);
connect(m_secondaryRunner, &SquishRunnerProcess::objectPicked, connect(m_secondaryRunner, &SquishRunnerProcess::objectPicked,
@@ -676,8 +673,8 @@ void SquishTools::executeRunnerQuery()
if (!isValidToStartRunner() || !setupRunnerPath()) if (!isValidToStartRunner() || !setupRunnerPath())
return; return;
QStringList arguments = { "--port", QString::number(m_serverProcess.port()) }; CommandLine cmdLine{toolsSettings.runnerPath,
Utils::CommandLine cmdLine = {toolsSettings.runnerPath, arguments}; {"--port", QString::number(m_serverProcess.port())}};
switch (m_query) { switch (m_query) {
case ServerInfo: case ServerInfo:
cmdLine.addArg("--info"); cmdLine.addArg("--info");
@@ -690,7 +687,7 @@ void SquishTools::executeRunnerQuery()
case SetGlobalScriptDirs: case SetGlobalScriptDirs:
cmdLine.addArg("--config"); cmdLine.addArg("--config");
cmdLine.addArg("setGlobalScriptDirs"); cmdLine.addArg("setGlobalScriptDirs");
cmdLine.addArgs(m_queryParameter, Utils::CommandLine::Raw); cmdLine.addArgs(m_queryParameter, CommandLine::Raw);
break; break;
default: default:
QTC_ASSERT(false, return); QTC_ASSERT(false, return);
@@ -1106,10 +1103,9 @@ void SquishTools::interruptRunner()
{ {
qCDebug(LOG) << "Interrupting runner"; qCDebug(LOG) << "Interrupting runner";
QTC_ASSERT(m_primaryRunner, return); QTC_ASSERT(m_primaryRunner, return);
qint64 processId = m_primaryRunner->processId(); const qint64 processId = m_primaryRunner->processId();
const CommandLine cmd(toolsSettings.processComPath, {QString::number(processId), "break"});
Process process; Process process;
process.setCommand(cmd); process.setCommand({toolsSettings.processComPath, {QString::number(processId), "break"}});
process.start(); process.start();
process.waitForFinished(); process.waitForFinished();
} }
@@ -1122,10 +1118,9 @@ void SquishTools::terminateRunner()
m_perspective.updateStatus(Tr::tr("User stop initiated.")); m_perspective.updateStatus(Tr::tr("User stop initiated."));
// should we terminate the AUT instead of the runner?!? // should we terminate the AUT instead of the runner?!?
QTC_ASSERT(m_primaryRunner, return); QTC_ASSERT(m_primaryRunner, return);
qint64 processId = m_primaryRunner->processId(); const qint64 processId = m_primaryRunner->processId();
const CommandLine cmd(toolsSettings.processComPath, {QString::number(processId), "terminate"});
Process process; Process process;
process.setCommand(cmd); process.setCommand({toolsSettings.processComPath, {QString::number(processId), "terminate"}});
process.start(); process.start();
process.waitForFinished(); process.waitForFinished();
} }
@@ -1263,7 +1258,7 @@ bool SquishTools::setupRunnerPath()
return true; return true;
} }
void SquishTools::setupAndStartSquishRunnerProcess(const Utils::CommandLine &cmdLine) void SquishTools::setupAndStartSquishRunnerProcess(const CommandLine &cmdLine)
{ {
QTC_ASSERT(m_primaryRunner, return); QTC_ASSERT(m_primaryRunner, return);
// avoid crashes on fast re-usage of Process // avoid crashes on fast re-usage of Process

View File

@@ -115,6 +115,7 @@ CommandLine &operator<<(Utils::CommandLine &command, SubversionClient::AddAuthOp
QString SubversionClient::synchronousTopic(const FilePath &repository) const QString SubversionClient::synchronousTopic(const FilePath &repository) const
{ {
// TODO: Looks unused
QStringList args; QStringList args;
QString svnVersionBinary = vcsBinary(repository).toString(); QString svnVersionBinary = vcsBinary(repository).toString();

View File

@@ -133,7 +133,7 @@ void ShellIntegration::onOsc(int cmd, std::string_view str, bool initial, bool f
qCDebug(integrationLog) << "OSC 133:" << data; qCDebug(integrationLog) << "OSC 133:" << data;
} else if (cmd == 633 && command.length() == 1) { } else if (cmd == 633 && command.length() == 1) {
if (command[0] == 'E') { if (command[0] == 'E') {
CommandLine cmdLine = CommandLine::fromUserInput(data.toString()); const CommandLine cmdLine = CommandLine::fromUserInput(data.toString());
emit commandChanged(cmdLine); emit commandChanged(cmdLine);
} else if (command[0] == 'D') { } else if (command[0] == 'D') {
emit commandChanged({}); emit commandChanged({});
@@ -174,12 +174,10 @@ void ShellIntegration::prepareProcess(Utils::Process &process)
m_tempDir.filePath(filesToCopy.bash.rcFile.fileName())); m_tempDir.filePath(filesToCopy.bash.rcFile.fileName()));
rcPath.copyFile(tmpRc); rcPath.copyFile(tmpRc);
CommandLine newCmd = {cmd.executable(), {"--init-file", tmpRc.nativePath()}};
if (cmd.arguments() == "-l") if (cmd.arguments() == "-l")
env.set("VSCODE_SHELL_LOGIN", "1"); env.set("VSCODE_SHELL_LOGIN", "1");
cmd = newCmd; cmd = {cmd.executable(), {"--init-file", tmpRc.nativePath()}};
} else if (cmd.executable().baseName() == "zsh") { } else if (cmd.executable().baseName() == "zsh") {
for (const FileToCopy &file : filesToCopy.zsh.files) { for (const FileToCopy &file : filesToCopy.zsh.files) {
const auto copyResult = file.source.copyFile( const auto copyResult = file.source.copyFile(

View File

@@ -83,7 +83,7 @@ void TerminalWidget::setupPty()
{ {
m_process = std::make_unique<Process>(); m_process = std::make_unique<Process>();
CommandLine shellCommand = m_openParameters.shellCommand.value_or( const CommandLine shellCommand = m_openParameters.shellCommand.value_or(
CommandLine{settings().shell(), settings().shellArguments(), CommandLine::Raw}); CommandLine{settings().shell(), settings().shellArguments(), CommandLine::Raw});
if (shellCommand.executable().isRootPath()) { if (shellCommand.executable().isRootPath()) {

View File

@@ -187,9 +187,9 @@ void ValgrindMemcheckParserTest::initTest(const QString &testfile, const QString
QVERIFY2(fileInfo.isExecutable(), qPrintable(fakeValgrind)); QVERIFY2(fileInfo.isExecutable(), qPrintable(fakeValgrind));
QVERIFY2(!fileInfo.isDir(), qPrintable(fakeValgrind)); QVERIFY2(!fileInfo.isDir(), qPrintable(fakeValgrind));
const QStringList args = {QString("--xml-socket=127.0.0.1:%1").arg(m_server->serverPort()), m_process->setCommand({FilePath::fromString(fakeValgrind),
"-i", testfile}; {QString("--xml-socket=127.0.0.1:%1").arg(m_server->serverPort()),
m_process->setCommand({FilePath::fromString(fakeValgrind), args + otherArgs}); "-i", testfile, otherArgs}});
m_process->start(); m_process->start();
using namespace std::chrono_literals; using namespace std::chrono_literals;

View File

@@ -93,11 +93,8 @@ QString ValgrindTestRunnerTest::runTestBinary(const QString &binary, const QStri
debuggee.command.setExecutable(Utils::FilePath::fromString(binPath)); debuggee.command.setExecutable(Utils::FilePath::fromString(binPath));
debuggee.environment = Utils::Environment::systemEnvironment(); debuggee.environment = Utils::Environment::systemEnvironment();
CommandLine valgrind{"valgrind", {"--num-callers=50", "--track-origins=yes"}};
valgrind.addArgs(vArgs);
m_runner->setLocalServerAddress(QHostAddress::LocalHost); m_runner->setLocalServerAddress(QHostAddress::LocalHost);
m_runner->setValgrindCommand(valgrind); m_runner->setValgrindCommand({"valgrind", {"--num-callers=50", "--track-origins=yes", vArgs}});
m_runner->setDebuggee(debuggee); m_runner->setDebuggee(debuggee);
m_runner->runBlocking(); m_runner->runBlocking();
return binPath; return binPath;