aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/api
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2017-06-09 13:07:25 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2017-06-14 09:47:11 +0000
commit4a3a382ea2f7ed6f55b0655acbf780f28ba25159 (patch)
treee9f6c5a50a0637fd74d3fabc348c7ff73fdac988 /src/lib/corelib/api
parent002542825419d63291e69569f82aa6857ec16117 (diff)
API: Allow synchronous retrieval of build graph data
This is needed to import builds into Qt Creator. Task-number: QBS-1059 Change-Id: I8a1b226d3f0044c7e90a61d195796a1e8be9a9de Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/lib/corelib/api')
-rw-r--r--src/lib/corelib/api/project.cpp41
-rw-r--r--src/lib/corelib/api/project.h16
2 files changed, 56 insertions, 1 deletions
diff --git a/src/lib/corelib/api/project.cpp b/src/lib/corelib/api/project.cpp
index f06a0126e..88f2c689e 100644
--- a/src/lib/corelib/api/project.cpp
+++ b/src/lib/corelib/api/project.cpp
@@ -51,6 +51,7 @@
#include "runenvironment.h"
#include <buildgraph/artifact.h>
#include <buildgraph/buildgraph.h>
+#include <buildgraph/buildgraphloader.h>
#include <buildgraph/emptydirectoriesremover.h>
#include <buildgraph/nodetreedumper.h>
#include <buildgraph/productbuilddata.h>
@@ -82,6 +83,8 @@
#include <QtCore/qshareddata.h>
#include <mutex>
+#include <utility>
+#include <vector>
namespace qbs {
namespace Internal {
@@ -1132,6 +1135,44 @@ ErrorInfo Project::dumpNodesTree(QIODevice &outDevice, const QList<ProductData>
return ErrorInfo();
}
+Project::BuildGraphInfo Project::getBuildGraphInfo(const QString &bgFilePath,
+ const QStringList &requestedProperties)
+{
+ BuildGraphInfo info;
+ try {
+ const Internal::TopLevelProjectConstPtr project = BuildGraphLoader::loadProject(bgFilePath);
+ info.bgFilePath = bgFilePath;
+ info.overriddenProperties = project->overriddenValues;
+ info.profileData = project->profileConfigs;
+ std::vector<std::pair<QString, QString>> props;
+ for (const QString &prop : requestedProperties) {
+ QStringList components = prop.split(QLatin1Char('.'));
+ const QString propName = components.takeLast();
+ props.push_back(std::make_pair(components.join(QLatin1Char('.')), propName));
+ }
+ for (const ResolvedProductConstPtr &product : project->allProducts()) {
+ if (props.empty())
+ break;
+ if (product->profile != project->profile())
+ continue;
+ for (auto it = props.begin(); it != props.end();) {
+ const QVariant value
+ = product->moduleProperties->moduleProperty(it->first, it->second);
+ if (value.isValid()) {
+ info.requestedProperties.insert(it->first + QLatin1Char('.') + it->second,
+ value);
+ it = props.erase(it);
+ } else {
+ ++it;
+ }
+ }
+ }
+ } catch (const ErrorInfo &e) {
+ info.error = e;
+ }
+ return info;
+}
+
#ifdef QBS_ENABLE_PROJECT_FILE_UPDATES
/*!
* \brief Adds a new empty group to the given product.
diff --git a/src/lib/corelib/api/project.h b/src/lib/corelib/api/project.h
index 5456da335..034db2625 100644
--- a/src/lib/corelib/api/project.h
+++ b/src/lib/corelib/api/project.h
@@ -41,6 +41,7 @@
#include "rulecommand.h"
#include "../language/forward_decls.h"
+#include "../tools/error.h"
#include "../tools/qbs_export.h"
#include <QtCore/qshareddata.h>
@@ -62,7 +63,6 @@ class BuildJob;
class BuildOptions;
class CleanJob;
class CleanOptions;
-class ErrorInfo;
class GroupData;
class ILogSink;
class InstallJob;
@@ -139,6 +139,20 @@ public:
ErrorInfo dumpNodesTree(QIODevice &outDevice, const QList<ProductData> &products);
+
+ class BuildGraphInfo
+ {
+ public:
+ QString bgFilePath;
+ QVariantMap overriddenProperties;
+ QVariantMap profileData;
+ QVariantMap requestedProperties;
+ ErrorInfo error;
+ };
+ static BuildGraphInfo getBuildGraphInfo(const QString &bgFilePath,
+ const QStringList &requestedProperties);
+
+
#ifdef QBS_ENABLE_PROJECT_FILE_UPDATES
ErrorInfo addGroup(const ProductData &product, const QString &groupName);
ErrorInfo addFiles(const ProductData &product, const GroupData &group,