ProjectExplorer: Introduce a IDevice::filePath

Same function as mapToGlobalPath, but operating on a QString specifying
the local path part. It's the majority use case and arguably the 'right
thing' to use instead of a full FilePath that can refer to arbitrary
devices.

Change-Id: Ifc8bd340e2e8859fe549f5724eb94269f587c418
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-05-10 15:33:33 +02:00
parent 42e072f159
commit 1ffaf0139a
22 changed files with 33 additions and 39 deletions

View File

@@ -88,7 +88,7 @@ public:
Runnable r = runnable(); Runnable r = runnable();
CommandLine cmd; CommandLine cmd;
cmd.setExecutable(device()->mapToGlobalPath(FilePath::fromString(Constants::AppcontrollerFilepath))); cmd.setExecutable(device()->filePath(Constants::AppcontrollerFilepath));
if (m_useGdbServer) { if (m_useGdbServer) {
cmd.addArg("--debug-gdb"); cmd.addArg("--debug-gdb");

View File

@@ -87,7 +87,7 @@ private:
? QStringLiteral("--make-default ") + remoteExe ? QStringLiteral("--make-default ") + remoteExe
: QStringLiteral("--remove-default"); : QStringLiteral("--remove-default");
m_process.setCommand( m_process.setCommand(
{deviceConfiguration()->mapToGlobalPath(Constants::AppcontrollerFilepath), {args}}); {deviceConfiguration()->filePath(Constants::AppcontrollerFilepath), {args}});
m_process.start(); m_process.start();
} }

View File

@@ -109,7 +109,7 @@ void QdbStopApplicationService::doDeploy()
emit stdOutData(QString::fromUtf8(m_process.readAllStandardOutput())); emit stdOutData(QString::fromUtf8(m_process.readAllStandardOutput()));
}); });
m_process.setCommand({device->mapToGlobalPath(Constants::AppcontrollerFilepath), {"--stop"}}); m_process.setCommand({device->filePath(Constants::AppcontrollerFilepath), {"--stop"}});
m_process.setWorkingDirectory("/usr/bin"); m_process.setWorkingDirectory("/usr/bin");
m_process.start(); m_process.start();
} }

View File

@@ -145,7 +145,7 @@ void PerfConfigWidget::setTarget(ProjectExplorer::Target *target)
QTC_CHECK(!m_process || m_process->state() == QProcess::NotRunning); QTC_CHECK(!m_process || m_process->state() == QProcess::NotRunning);
m_process.reset(new QtcProcess); m_process.reset(new QtcProcess);
m_process->setCommand({device->mapToGlobalPath("perf"), {"probe", "-l"}}); m_process->setCommand({device->filePath("perf"), {"probe", "-l"}});
connect(m_process.get(), &QtcProcess::done, connect(m_process.get(), &QtcProcess::done,
this, &PerfConfigWidget::handleProcessDone); this, &PerfConfigWidget::handleProcessDone);

View File

@@ -147,7 +147,7 @@ public:
Runnable perfRunnable = runnable(); Runnable perfRunnable = runnable();
CommandLine cmd({device()->mapToGlobalPath("perf"), {"record"}}); CommandLine cmd({device()->filePath("perf"), {"record"}});
cmd.addArgs(m_perfRecordArguments); cmd.addArgs(m_perfRecordArguments);
cmd.addArgs({"-o", "-", "--"}); cmd.addArgs({"-o", "-", "--"});
cmd.addCommandLineAsArgs(perfRunnable.command, CommandLine::Raw); cmd.addCommandLineAsArgs(perfRunnable.command, CommandLine::Raw);

View File

@@ -95,9 +95,9 @@ void PerfTracePointDialog::runScript()
const QString elevate = m_ui->privilegesChooser->currentText(); const QString elevate = m_ui->privilegesChooser->currentText();
if (elevate != QLatin1String("n.a.")) if (elevate != QLatin1String("n.a."))
m_process->setCommand({m_device->mapToGlobalPath(FilePath::fromString(elevate)), {"sh"}}); m_process->setCommand({m_device->filePath(elevate), {"sh"}});
else else
m_process->setCommand({m_device->mapToGlobalPath("sh"), {}}); m_process->setCommand({m_device->filePath("sh"), {}});
connect(m_process.get(), &QtcProcess::done, this, &PerfTracePointDialog::handleProcessDone); connect(m_process.get(), &QtcProcess::done, this, &PerfTracePointDialog::handleProcessDone);
m_process->start(); m_process->start();

View File

@@ -53,8 +53,7 @@ SshDeviceProcessList::~SshDeviceProcessList() = default;
void SshDeviceProcessList::doUpdate() void SshDeviceProcessList::doUpdate()
{ {
d->m_process.close(); d->m_process.close();
d->m_process.setCommand({device()->mapToGlobalPath("/bin/sh"), d->m_process.setCommand({device()->filePath("/bin/sh"), {"-c", listProcessesCommandLine()}});
{"-c", listProcessesCommandLine()}});
d->m_process.start(); d->m_process.start();
} }

View File

@@ -262,7 +262,7 @@ void QnxDeployQtLibrariesDialog::startCheckDirProcess()
m_state = CheckingRemoteDirectory; m_state = CheckingRemoteDirectory;
m_ui->deployLogWindow->appendPlainText(tr("Checking existence of \"%1\"") m_ui->deployLogWindow->appendPlainText(tr("Checking existence of \"%1\"")
.arg(fullRemoteDirectory())); .arg(fullRemoteDirectory()));
m_checkDirProcess.setCommand({m_device->mapToGlobalPath("test"), m_checkDirProcess.setCommand({m_device->filePath("test"),
{"-d", fullRemoteDirectory()}}); {"-d", fullRemoteDirectory()}});
m_checkDirProcess.start(); m_checkDirProcess.start();
} }
@@ -272,7 +272,7 @@ void QnxDeployQtLibrariesDialog::startRemoveDirProcess()
QTC_CHECK(m_state == CheckingRemoteDirectory); QTC_CHECK(m_state == CheckingRemoteDirectory);
m_state = RemovingRemoteDirectory; m_state = RemovingRemoteDirectory;
m_ui->deployLogWindow->appendPlainText(tr("Removing \"%1\"").arg(fullRemoteDirectory())); m_ui->deployLogWindow->appendPlainText(tr("Removing \"%1\"").arg(fullRemoteDirectory()));
m_removeDirProcess.setCommand({m_device->mapToGlobalPath("rm"), m_removeDirProcess.setCommand({m_device->filePath("rm"),
{"-rf", fullRemoteDirectory()}}); {"-rf", fullRemoteDirectory()}});
m_removeDirProcess.start(); m_removeDirProcess.start();
} }

View File

@@ -153,7 +153,7 @@ void QnxDevice::updateVersionNumber() const
{ {
QtcProcess versionNumberProcess; QtcProcess versionNumberProcess;
versionNumberProcess.setCommand({mapToGlobalPath("uname"), {"-r"}}); versionNumberProcess.setCommand({filePath("uname"), {"-r"}});
versionNumberProcess.runBlocking(EventLoopMode::On); versionNumberProcess.runBlocking(EventLoopMode::On);
QByteArray output = versionNumberProcess.readAllStandardOutput(); QByteArray output = versionNumberProcess.readAllStandardOutput();

View File

@@ -94,7 +94,7 @@ void QnxDeviceTester::handleGenericTestFinished(TestResult result)
m_state = VarRunTest; m_state = VarRunTest;
emit progressMessage(tr("Checking that files can be created in /var/run...")); emit progressMessage(tr("Checking that files can be created in /var/run..."));
const CommandLine cmd {m_deviceConfiguration->mapToGlobalPath("/bin/sh"), const CommandLine cmd {m_deviceConfiguration->filePath("/bin/sh"),
{"-c", QLatin1String("rm %1 > /dev/null 2>&1; echo ABC > %1 && rm %1") {"-c", QLatin1String("rm %1 > /dev/null 2>&1; echo ABC > %1 && rm %1")
.arg("/var/run/qtc_xxxx.pid")}}; .arg("/var/run/qtc_xxxx.pid")}};
m_process.setCommand(cmd); m_process.setCommand(cmd);
@@ -159,8 +159,7 @@ void QnxDeviceTester::testNextCommand()
const QString command = m_commandsToTest[m_currentCommandIndex]; const QString command = m_commandsToTest[m_currentCommandIndex];
emit progressMessage(tr("Checking for %1...").arg(command)); emit progressMessage(tr("Checking for %1...").arg(command));
const CommandLine cmd {m_deviceConfiguration->mapToGlobalPath("command"), {"-v", command}}; m_process.setCommand({m_deviceConfiguration->filePath("command"), {"-v", command}});
m_process.setCommand(cmd);
m_process.start(); m_process.start();
} }

View File

@@ -70,7 +70,7 @@ void Slog2InfoRunner::printMissingWarning()
void Slog2InfoRunner::start() void Slog2InfoRunner::start()
{ {
m_testProcess->setCommand({device()->mapToGlobalPath("slog2info"), {}}); m_testProcess->setCommand({device()->filePath("slog2info"), {}});
m_testProcess->start(); m_testProcess->start();
reportStarted(); reportStarted();
} }
@@ -107,7 +107,7 @@ void Slog2InfoRunner::handleTestProcessCompleted()
void Slog2InfoRunner::readLaunchTime() void Slog2InfoRunner::readLaunchTime()
{ {
m_launchDateTimeProcess->setCommand({device()->mapToGlobalPath("date"), m_launchDateTimeProcess->setCommand({device()->filePath("date"),
"+\"%d %H:%M:%S\"", CommandLine::Raw}); "+\"%d %H:%M:%S\"", CommandLine::Raw});
m_launchDateTimeProcess->start(); m_launchDateTimeProcess->start();
} }
@@ -126,7 +126,7 @@ void Slog2InfoRunner::launchSlog2Info()
m_launchDateTime = QDateTime::fromString(QString::fromLatin1(m_launchDateTimeProcess->readAllStandardOutput()).trimmed(), m_launchDateTime = QDateTime::fromString(QString::fromLatin1(m_launchDateTimeProcess->readAllStandardOutput()).trimmed(),
QString::fromLatin1("dd HH:mm:ss")); QString::fromLatin1("dd HH:mm:ss"));
m_logProcess->setCommand({device()->mapToGlobalPath("slog2info"), {"-w"}}); m_logProcess->setCommand({device()->filePath("slog2info"), {"-w"}});
m_logProcess->start(); m_logProcess->start();
} }

View File

@@ -198,9 +198,8 @@ void GenericDirectUploadService::runStat(const DeployableFile &file)
{ {
// We'd like to use --format=%Y, but it's not supported by busybox. // We'd like to use --format=%Y, but it's not supported by busybox.
QtcProcess * const statProc = new QtcProcess(this); QtcProcess * const statProc = new QtcProcess(this);
const CommandLine statCmd {deviceConfiguration()->mapToGlobalPath("stat"), statProc->setCommand({deviceConfiguration()->filePath("stat"),
{"-t", Utils::ProcessArgs::quoteArgUnix(file.remoteFilePath())}}; {"-t", Utils::ProcessArgs::quoteArgUnix(file.remoteFilePath())}});
statProc->setCommand(statCmd);
connect(statProc, &QtcProcess::done, this, [this, statProc, state = d->state] { connect(statProc, &QtcProcess::done, this, [this, statProc, state = d->state] {
QTC_ASSERT(d->state == state, return); QTC_ASSERT(d->state == state, return);
const DeployableFile file = d->getFileForProcess(statProc); const DeployableFile file = d->getFileForProcess(statProc);
@@ -338,9 +337,8 @@ void GenericDirectUploadService::chmod()
if (!f.isExecutable()) if (!f.isExecutable())
continue; continue;
QtcProcess * const chmodProc = new QtcProcess(this); QtcProcess * const chmodProc = new QtcProcess(this);
const CommandLine chmodCmd {deviceConfiguration()->mapToGlobalPath("chmod"), chmodProc->setCommand({deviceConfiguration()->filePath("chmod"),
{"a+x", Utils::ProcessArgs::quoteArgUnix(f.remoteFilePath())}}; {"a+x", Utils::ProcessArgs::quoteArgUnix(f.remoteFilePath())}});
chmodProc->setCommand(chmodCmd);
connect(chmodProc, &QtcProcess::done, this, [this, chmodProc, state = d->state] { connect(chmodProc, &QtcProcess::done, this, [this, chmodProc, state = d->state] {
QTC_ASSERT(state == d->state, return); QTC_ASSERT(state == d->state, return);
const DeployableFile file = d->getFileForProcess(chmodProc); const DeployableFile file = d->getFileForProcess(chmodProc);

View File

@@ -129,7 +129,7 @@ void GenericLinuxDeviceTester::handleConnected()
{ {
QTC_ASSERT(d->state == Connecting, return); QTC_ASSERT(d->state == Connecting, return);
d->unameProcess.setCommand({d->deviceConfiguration->mapToGlobalPath("uname"), {"-rsm"}}); d->unameProcess.setCommand({d->deviceConfiguration->filePath("uname"), {"-rsm"}});
emit progressMessage(tr("Checking kernel version...")); emit progressMessage(tr("Checking kernel version..."));
d->state = RunningUname; d->state = RunningUname;

View File

@@ -97,7 +97,7 @@ PublicKeyDeploymentDialog::PublicKeyDeploymentDialog(const IDevice::ConstPtr &de
const QString command = "test -d .ssh || mkdir -p ~/.ssh && chmod 0700 .ssh && echo '" const QString command = "test -d .ssh || mkdir -p ~/.ssh && chmod 0700 .ssh && echo '"
+ QString::fromLocal8Bit(reader.data()) + QString::fromLocal8Bit(reader.data())
+ "' >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys"; + "' >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys";
d->m_process.setCommand({deviceConfig->mapToGlobalPath("/bin/sh"), {"-c", command}}); d->m_process.setCommand({deviceConfig->filePath("/bin/sh"), {"-c", command}});
d->m_process.start(); d->m_process.start();
} }

View File

@@ -98,7 +98,7 @@ CheckResult RemoteLinuxCustomCommandDeployService::isDeploymentPossible() const
void RemoteLinuxCustomCommandDeployService::doDeploy() void RemoteLinuxCustomCommandDeployService::doDeploy()
{ {
emit progressMessage(tr("Starting remote command \"%1\"...").arg(m_commandLine)); emit progressMessage(tr("Starting remote command \"%1\"...").arg(m_commandLine));
m_process.setCommand({deviceConfiguration()->mapToGlobalPath("/bin/sh"), m_process.setCommand({deviceConfiguration()->filePath("/bin/sh"),
{"-c", m_commandLine}}); {"-c", m_commandLine}});
m_process.start(); m_process.start();
} }

View File

@@ -55,7 +55,7 @@ void RemoteLinuxEnvironmentReader::start()
m_deviceProcess = new QtcProcess(this); m_deviceProcess = new QtcProcess(this);
connect(m_deviceProcess, &QtcProcess::done, connect(m_deviceProcess, &QtcProcess::done,
this, &RemoteLinuxEnvironmentReader::handleDone); this, &RemoteLinuxEnvironmentReader::handleDone);
m_deviceProcess->setCommand({m_device->mapToGlobalPath("env"), {}}); m_deviceProcess->setCommand({m_device->filePath("env"), {}});
m_deviceProcess->start(); m_deviceProcess->start();
} }

View File

@@ -76,7 +76,7 @@ void AbstractRemoteLinuxPackageInstaller::installPackage(const IDevice::ConstPtr
QString cmdLine = installCommandLine(packageFilePath); QString cmdLine = installCommandLine(packageFilePath);
if (removePackageFile) if (removePackageFile)
cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)"); cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)");
d->m_installer.setCommand({d->m_device->mapToGlobalPath("/bin/sh"), {"-c", cmdLine}}); d->m_installer.setCommand({d->m_device->filePath("/bin/sh"), {"-c", cmdLine}});
d->m_installer.start(); d->m_installer.start();
} }
@@ -84,7 +84,7 @@ void AbstractRemoteLinuxPackageInstaller::cancelInstallation()
{ {
QTC_ASSERT(d->m_installer.state() != QProcess::NotRunning, return); QTC_ASSERT(d->m_installer.state() != QProcess::NotRunning, return);
d->m_killer.setCommand({d->m_device->mapToGlobalPath("/bin/sh"), d->m_killer.setCommand({d->m_device->filePath("/bin/sh"),
{"-c", cancelInstallationCommandLine()}}); {"-c", cancelInstallationCommandLine()}});
d->m_killer.start(); d->m_killer.start();
d->m_installer.close(); d->m_installer.close();

View File

@@ -52,7 +52,7 @@ void RemoteLinuxSignalOperation::run(const QString &command)
m_process.reset(new QtcProcess); m_process.reset(new QtcProcess);
connect(m_process.get(), &QtcProcess::done, this, &RemoteLinuxSignalOperation::runnerDone); connect(m_process.get(), &QtcProcess::done, this, &RemoteLinuxSignalOperation::runnerDone);
m_process->setCommand({m_device->mapToGlobalPath("/bin/sh"), {"-c", command}}); m_process->setCommand({m_device->filePath("/bin/sh"), {"-c", command}});
m_process->start(); m_process->start();
} }

View File

@@ -102,9 +102,8 @@ void RsyncDeployService::createRemoteDirectories()
remoteDirs.sort(); remoteDirs.sort();
remoteDirs.removeDuplicates(); remoteDirs.removeDuplicates();
m_mkdir.reset(new QtcProcess); m_mkdir.reset(new QtcProcess);
const CommandLine command {deviceConfiguration()->mapToGlobalPath("mkdir"), m_mkdir->setCommand({deviceConfiguration()->filePath("mkdir"),
{"-p", ProcessArgs::createUnixArgs(remoteDirs).toString()}}; {"-p", ProcessArgs::createUnixArgs(remoteDirs).toString()}});
m_mkdir->setCommand(command);
connect(m_mkdir.get(), &QtcProcess::done, this, [this] { connect(m_mkdir.get(), &QtcProcess::done, this, [this] {
if (m_mkdir->result() != ProcessResult::FinishedWithSuccess) { if (m_mkdir->result() != ProcessResult::FinishedWithSuccess) {
emit errorMessage(tr("Failed to create remote directories: %1") emit errorMessage(tr("Failed to create remote directories: %1")

View File

@@ -114,12 +114,11 @@ void CallgrindController::run(Option option)
connect(m_controllerProcess.get(), &QtcProcess::finished, connect(m_controllerProcess.get(), &QtcProcess::finished,
this, &CallgrindController::controllerProcessDone); this, &CallgrindController::controllerProcessDone);
const FilePath cgcontrol = FilePath::fromString(CALLGRIND_CONTROL_BINARY);
CommandLine cmd; CommandLine cmd;
if (m_valgrindRunnable.device) if (m_valgrindRunnable.device)
cmd.setExecutable(m_valgrindRunnable.device->mapToGlobalPath(cgcontrol)); cmd.setExecutable(m_valgrindRunnable.device->filePath(CALLGRIND_CONTROL_BINARY));
else else
cmd.setExecutable(cgcontrol); cmd.setExecutable(CALLGRIND_CONTROL_BINARY);
cmd.setArguments(QString("%1 %2").arg(toOptionString(option)).arg(m_pid)); cmd.setArguments(QString("%1 %2").arg(toOptionString(option)).arg(m_pid));
m_controllerProcess->setCommand(cmd); m_controllerProcess->setCommand(cmd);
m_controllerProcess->setWorkingDirectory(m_valgrindRunnable.workingDirectory); m_controllerProcess->setWorkingDirectory(m_valgrindRunnable.workingDirectory);

View File

@@ -156,7 +156,7 @@ public:
{ {
QTC_ASSERT(!m_process, return); QTC_ASSERT(!m_process, return);
m_process.reset(new QtcProcess); m_process.reset(new QtcProcess);
m_process->setCommand({device()->mapToGlobalPath("echo"), "-n $SSH_CLIENT", CommandLine::Raw}); m_process->setCommand({device()->filePath("echo"), "-n $SSH_CLIENT", CommandLine::Raw});
connect(m_process.get(), &QtcProcess::done, this, [this] { connect(m_process.get(), &QtcProcess::done, this, [this] {
if (m_process->error() != QProcess::UnknownError) { if (m_process->error() != QProcess::UnknownError) {
reportFailure(); reportFailure();

View File

@@ -178,7 +178,7 @@ void ValgrindRunner::Private::remoteProcessStarted()
QString procEscaped = proc; QString procEscaped = proc;
procEscaped.replace("/", "\\\\/"); procEscaped.replace("/", "\\\\/");
CommandLine cmd(m_device->mapToGlobalPath(FilePath::fromString("/bin/sh")), {}); CommandLine cmd(m_device->filePath("/bin/sh"), {});
// sleep required since otherwise we might only match "bash -c..." and not the actual // sleep required since otherwise we might only match "bash -c..." and not the actual
// valgrind run // valgrind run
cmd.setArguments(QString("-c \"" cmd.setArguments(QString("-c \""