aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/tools/processresult.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2019-03-18 15:02:53 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2019-09-18 15:07:54 +0000
commit9f3a9830162f379d6f856c84668c3664df6d6477 (patch)
treeb32a126840ca81a0881e71051f5c09443ede5a05 /src/lib/corelib/tools/processresult.cpp
parent41d8b09239ce0ace2fd8674aaecae1528b1985e4 (diff)
Introduce the session command
Offers a JSON-based API for interaction with other tools via stdin/ stdout. This allows for proper qbs support in IDEs that do not use Qt or even C++. Change-Id: Ib051a40b7ebe1c6e0c3147cca9bd96e7daec1fde Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/lib/corelib/tools/processresult.cpp')
-rw-r--r--src/lib/corelib/tools/processresult.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/corelib/tools/processresult.cpp b/src/lib/corelib/tools/processresult.cpp
index 12e45b251..3fb2f8dbc 100644
--- a/src/lib/corelib/tools/processresult.cpp
+++ b/src/lib/corelib/tools/processresult.cpp
@@ -39,6 +39,9 @@
#include "processresult.h"
#include "processresult_p.h"
+#include <QtCore/qjsonarray.h>
+#include <QtCore/qjsonobject.h>
+
/*!
* \class SetupProjectParameters
* \brief The \c ProcessResult class describes a finished qbs process command.
@@ -129,4 +132,31 @@ QStringList ProcessResult::stdErr() const
return d->stdErr;
}
+static QJsonValue processErrorToJson(QProcess::ProcessError error)
+{
+ switch (error) {
+ case QProcess::FailedToStart: return QLatin1String("failed-to-start");
+ case QProcess::Crashed: return QLatin1String("crashed");
+ case QProcess::Timedout: return QLatin1String("timed-out");
+ case QProcess::WriteError: return QLatin1String("write-error");
+ case QProcess::ReadError: return QLatin1String("read-error");
+ case QProcess::UnknownError: return QStringLiteral("unknown-error");
+ }
+ return {}; // For dumb compilers.
+}
+
+QJsonObject qbs::ProcessResult::toJson() const
+{
+ return QJsonObject{
+ {QStringLiteral("success"), success()},
+ {QStringLiteral("executable-file-path"), executableFilePath()},
+ {QStringLiteral("arguments"), QJsonArray::fromStringList(arguments())},
+ {QStringLiteral("working-directory"), workingDirectory()},
+ {QStringLiteral("error"), processErrorToJson(error())},
+ {QStringLiteral("exit-code"), exitCode()},
+ {QStringLiteral("stdout"), QJsonArray::fromStringList(stdOut())},
+ {QStringLiteral("stderr"), QJsonArray::fromStringList(stdErr())}
+ };
+}
+
} // namespace qbs