Utils: Introduce QtcProcess::toStandaloneCommandLine()

The goal is to make a QtcProcess incl. environment, working directory,
executable and arguments testable, e.g. in a terminal. The new
toStandaloneCommandLine() returns a string containing the command line
for a call of "env" the data of the QtcProcess instance as parameters.

To be used like:
  qDebug().noquote() << qtcProc.toStandaloneCommandLine();

..and the debug output can be pasted into a terminal.

Change-Id: Ib6cbea290e1eff3279d6e0a67076a624312af879
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Alessandro Portale
2021-09-09 23:03:39 +02:00
parent 8b5192cf75
commit 2fc0ce4843
2 changed files with 21 additions and 0 deletions

View File

@@ -832,6 +832,25 @@ void QtcProcess::setStandardInputFile(const QString &inputFile)
d->m_process->setStandardInputFile(inputFile);
}
QString QtcProcess::toStandaloneCommandLine() const
{
QStringList parts;
parts.append("/usr/bin/env");
if (!d->m_workingDirectory.isEmpty()) {
parts.append("-C");
d->m_workingDirectory.path();
}
parts.append("-i");
if (d->m_environment.size() > 0) {
const QStringList envVars = d->m_environment.toStringList();
std::transform(envVars.cbegin(), envVars.cend(),
std::back_inserter(parts), ProcessArgs::quoteArgUnix);
}
parts.append(d->m_commandLine.executable().path());
parts.append(d->m_commandLine.splitArguments());
return parts.join(" ");
}
void QtcProcess::setRemoteProcessHooks(const DeviceProcessHooks &hooks)
{
s_deviceHooks = hooks;

View File

@@ -193,6 +193,8 @@ public:
void setStandardInputFile(const QString &inputFile);
QString toStandaloneCommandLine() const;
signals:
void started();
void finished();