summaryrefslogtreecommitdiff
path: root/src/libs
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@qt.io>2021-09-09 23:03:39 +0200
committerAlessandro Portale <alessandro.portale@qt.io>2021-09-10 11:49:07 +0000
commit2fc0ce4843299ea1587b167184c397ad0a99446d (patch)
tree64cb8bb67256abb675641828e4241e1bcb1fc7e9 /src/libs
parent8b5192cf751e57490cc6338aa2fc7a604a25471d (diff)
downloadqt-creator-2fc0ce4843299ea1587b167184c397ad0a99446d.tar.gz
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>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/utils/qtcprocess.cpp19
-rw-r--r--src/libs/utils/qtcprocess.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp
index bd44b2d823..f4b715eece 100644
--- a/src/libs/utils/qtcprocess.cpp
+++ b/src/libs/utils/qtcprocess.cpp
@@ -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;
diff --git a/src/libs/utils/qtcprocess.h b/src/libs/utils/qtcprocess.h
index 2fc610d8f8..8e12c0cc97 100644
--- a/src/libs/utils/qtcprocess.h
+++ b/src/libs/utils/qtcprocess.h
@@ -193,6 +193,8 @@ public:
void setStandardInputFile(const QString &inputFile);
+ QString toStandaloneCommandLine() const;
+
signals:
void started();
void finished();