summaryrefslogtreecommitdiff
path: root/src/lib/buildgraph/buildgraph.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@digia.com>2013-03-30 12:31:05 +0100
committerJoerg Bornemann <joerg.bornemann@digia.com>2013-04-03 15:18:32 +0200
commit9f71bd40503001cb593ec113d16f9212263d4723 (patch)
tree34bd763e314a02f8c07cb717c537853e76b41f50 /src/lib/buildgraph/buildgraph.cpp
parenta44efdd72349a5d2fcb1bb77cf729a84e712f74e (diff)
downloadqbs-9f71bd40503001cb593ec113d16f9212263d4723.tar.gz
introduce product.dependencies property
It is now possible to access the dependencies of a product or module. Entry point for the tree of dependencies is product.dependencies which returns a list of objects that represent products/modules the product depends on. Blackbox test added. Change-Id: I0c2728da479e8cc45ca3994d7e4a9e7a41802aa1 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Diffstat (limited to 'src/lib/buildgraph/buildgraph.cpp')
-rw-r--r--src/lib/buildgraph/buildgraph.cpp123
1 files changed, 114 insertions, 9 deletions
diff --git a/src/lib/buildgraph/buildgraph.cpp b/src/lib/buildgraph/buildgraph.cpp
index 3ec381e0e..81e01cc51 100644
--- a/src/lib/buildgraph/buildgraph.cpp
+++ b/src/lib/buildgraph/buildgraph.cpp
@@ -44,6 +44,119 @@
namespace qbs {
namespace Internal {
+static void setupProductScriptValue(ScriptEngine *engine, QScriptValue &productScriptValue,
+ const ResolvedProductConstPtr &product,
+ ScriptPropertyObserver *observer);
+
+class DependenciesFunction
+{
+public:
+ DependenciesFunction(ScriptEngine *engine)
+ : m_engine(engine)
+ {
+ }
+
+ void init(QScriptValue &productScriptValue, const ResolvedProductConstPtr &product)
+ {
+ QScriptValue depfunc = m_engine->newFunction(&js_productDependencies);
+ setProduct(depfunc, product.data());
+ QScriptValue descriptor = m_engine->newObject();
+ descriptor.setProperty(QLatin1String("get"), depfunc);
+ descriptor.setProperty(QLatin1String("set"), m_engine->evaluate("(function(){})"));
+ descriptor.setProperty(QLatin1String("enumerable"), true);
+ m_engine->defineProperty(productScriptValue, QLatin1String("dependencies"), descriptor);
+ }
+
+private:
+ static QScriptValue js_productDependencies(QScriptContext *context, QScriptEngine *engine)
+ {
+ QScriptValue callee = context->callee();
+ const ResolvedProduct * const product = getProduct(callee);
+ QScriptValue result = engine->newArray();
+ quint32 idx = 0;
+ foreach (const ResolvedProductPtr &dependency, product->dependencies) {
+ QScriptValue obj = engine->newObject();
+ setupProductScriptValue(static_cast<ScriptEngine *>(engine), obj, dependency, 0);
+ result.setProperty(idx++, obj);
+ }
+ foreach (const ResolvedModuleConstPtr &dependency, product->modules) {
+ QScriptValue obj = engine->newObject();
+ setupModuleScriptValue(static_cast<ScriptEngine *>(engine), obj,
+ product->properties->value(), dependency->name);
+ result.setProperty(idx++, obj);
+ }
+ return result;
+ }
+
+ static QScriptValue js_moduleDependencies(QScriptContext *context, QScriptEngine *engine)
+ {
+ QScriptValue callee = context->callee();
+ const QVariantMap modulesMap = callee.data().toVariant().toMap();
+ QScriptValue result = engine->newArray();
+ quint32 idx = 0;
+ for (QVariantMap::const_iterator it = modulesMap.begin(); it != modulesMap.end(); ++it) {
+ QScriptValue obj = engine->newObject();
+ obj.setProperty(QLatin1String("name"), it.key());
+ setupModuleScriptValue(static_cast<ScriptEngine *>(engine), obj, it.value().toMap(),
+ it.key());
+ result.setProperty(idx++, obj);
+ }
+ return result;
+ }
+
+ static void setupModuleScriptValue(ScriptEngine *engine, QScriptValue &moduleScriptValue,
+ const QVariantMap &propertyMap,
+ const QString &moduleName)
+ {
+ const QVariantMap propMap
+ = propertyMap.value(QLatin1String("modules")).toMap().value(moduleName).toMap();
+ for (QVariantMap::ConstIterator it = propMap.constBegin(); it != propMap.constEnd(); ++it) {
+ const QVariant &value = it.value();
+ if (value.isValid() && !value.canConvert<QVariantMap>())
+ moduleScriptValue.setProperty(it.key(), engine->toScriptValue(value));
+ }
+ QScriptValue depfunc = engine->newFunction(&js_moduleDependencies);
+ depfunc.setData(engine->toScriptValue(propMap.value(QLatin1String("modules"))));
+ QScriptValue descriptor = engine->newObject();
+ descriptor.setProperty(QLatin1String("get"), depfunc);
+ descriptor.setProperty(QLatin1String("set"), engine->evaluate("(function(){})"));
+ descriptor.setProperty(QLatin1String("enumerable"), true);
+ engine->defineProperty(moduleScriptValue, QLatin1String("dependencies"), descriptor);
+ moduleScriptValue.setProperty(QLatin1String("dependencies"), depfunc);
+ moduleScriptValue.setProperty(QLatin1String("type"), QLatin1String("module"));
+ }
+
+ static void setProduct(QScriptValue scriptValue, const ResolvedProduct *product)
+ {
+ QVariant v;
+ v.setValue<quintptr>(reinterpret_cast<quintptr>(product));
+ scriptValue.setData(scriptValue.engine()->newVariant(v));
+ }
+
+ static const ResolvedProduct *getProduct(const QScriptValue &scriptValue)
+ {
+ const quintptr ptr = scriptValue.data().toVariant().value<quintptr>();
+ return reinterpret_cast<const ResolvedProduct *>(ptr);
+ }
+
+ ScriptEngine *m_engine;
+};
+
+static void setupProductScriptValue(ScriptEngine *engine, QScriptValue &productScriptValue,
+ const ResolvedProductConstPtr &product,
+ ScriptPropertyObserver *observer)
+{
+ ModuleProperties::init(productScriptValue, product);
+ DependenciesFunction(engine).init(productScriptValue, product);
+ const QVariantMap &propMap = product->properties->value();
+ for (QVariantMap::ConstIterator it = propMap.constBegin(); it != propMap.constEnd(); ++it) {
+ const QVariant &value = it.value();
+ if (value.isValid() && !value.canConvert<QVariantMap>())
+ engine->setObservedProperty(productScriptValue, it.key(),
+ engine->toScriptValue(value), observer);
+ }
+}
+
void setupScriptEngineForProduct(ScriptEngine *engine, const ResolvedProductConstPtr &product,
const RuleConstPtr &rule, QScriptValue targetObject,
ScriptPropertyObserver *observer)
@@ -81,15 +194,7 @@ void setupScriptEngineForProduct(ScriptEngine *engine, const ResolvedProductCons
engine->setProperty("_qbs_procenv", v);
}
productScriptValue = engine->newObject();
- ModuleProperties::init(productScriptValue, product);
- const QVariantMap &propMap = product->properties->value();
- for (QVariantMap::ConstIterator it = propMap.constBegin(); it != propMap.constEnd(); ++it) {
- const QVariant &value = it.value();
- if (value.isValid() && !value.canConvert<QVariantMap>())
- engine->setObservedProperty(productScriptValue, it.key(),
- engine->toScriptValue(value), observer);
- }
-
+ setupProductScriptValue(engine, productScriptValue, product, observer);
targetObject.setProperty("product", productScriptValue);
} else {
productScriptValue = targetObject.property("product");