From ffb6be9612e270372d3fa9887d74cdaa1d9306cc Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 3 Apr 2013 11:40:30 +0200 Subject: implement Rule.condition property Now it's possible to turn rules on/off dependent on module properties set by the product. Change-Id: Ie11b31f416bd95a8a764ce99d7d8ca190eff08b5 Reviewed-by: Christian Kandeler --- src/lib/language/builtindeclarations.cpp | 1 + src/lib/language/projectresolver.cpp | 6 +++++ .../auto/blackbox/testdata/ruleConditions/foo.narf | 0 .../auto/blackbox/testdata/ruleConditions/main.cpp | 1 + .../ruleConditions/modules/narfzort/narfzort.qbs | 26 ++++++++++++++++++++++ .../testdata/ruleConditions/ruleConditions.qbs | 12 ++++++++++ .../testdata/ruleConditions/templates/zorduct.qbs | 11 +++++++++ tests/auto/blackbox/tst_blackbox.cpp | 10 +++++++++ tests/auto/blackbox/tst_blackbox.h | 1 + 9 files changed, 68 insertions(+) create mode 100644 tests/auto/blackbox/testdata/ruleConditions/foo.narf create mode 100644 tests/auto/blackbox/testdata/ruleConditions/main.cpp create mode 100644 tests/auto/blackbox/testdata/ruleConditions/modules/narfzort/narfzort.qbs create mode 100644 tests/auto/blackbox/testdata/ruleConditions/ruleConditions.qbs create mode 100644 tests/auto/blackbox/testdata/ruleConditions/templates/zorduct.qbs diff --git a/src/lib/language/builtindeclarations.cpp b/src/lib/language/builtindeclarations.cpp index 8d17c0f61..9ff81f2fe 100644 --- a/src/lib/language/builtindeclarations.cpp +++ b/src/lib/language/builtindeclarations.cpp @@ -104,6 +104,7 @@ BuiltinDeclarations::BuiltinDeclarations() rule += PropertyDeclaration("usings", PropertyDeclaration::Variant); rule += PropertyDeclaration("explicitlyDependsOn", PropertyDeclaration::Variant); rule += PropertyDeclaration("prepare", PropertyDeclaration::Verbatim); + rule += conditionProperty; m_builtins["Rule"] = rule; QList transformer; diff --git a/src/lib/language/projectresolver.cpp b/src/lib/language/projectresolver.cpp index 43bfa9bd0..7039719d5 100644 --- a/src/lib/language/projectresolver.cpp +++ b/src/lib/language/projectresolver.cpp @@ -37,6 +37,7 @@ #include "moduleloader.h" #include "propertymapinternal.h" #include "scriptengine.h" +#include #include #include #include @@ -223,6 +224,7 @@ void ProjectResolver::resolveProduct(const ItemPtr &item) product->project = m_projectContext->project; product->properties = PropertyMapInternal::create(); product->properties->setValue(createProductConfig()); + ModuleProperties::init(m_evaluator->scriptValue(item), product); QList subItems = item->children(); const ValuePtr filesProperty = item->property(QLatin1String("files")); @@ -412,6 +414,10 @@ static QString sourceCodeAsFunction(const JSSourceValueConstPtr &value) void ProjectResolver::resolveRule(const ItemPtr &item) { checkCancelation(); + + if (!boolValue(item, QLatin1String("condition"), true)) + return; + RulePtr rule = Rule::create(); // read artifacts diff --git a/tests/auto/blackbox/testdata/ruleConditions/foo.narf b/tests/auto/blackbox/testdata/ruleConditions/foo.narf new file mode 100644 index 000000000..e69de29bb diff --git a/tests/auto/blackbox/testdata/ruleConditions/main.cpp b/tests/auto/blackbox/testdata/ruleConditions/main.cpp new file mode 100644 index 000000000..76e819701 --- /dev/null +++ b/tests/auto/blackbox/testdata/ruleConditions/main.cpp @@ -0,0 +1 @@ +int main() { return 0; } diff --git a/tests/auto/blackbox/testdata/ruleConditions/modules/narfzort/narfzort.qbs b/tests/auto/blackbox/testdata/ruleConditions/modules/narfzort/narfzort.qbs new file mode 100644 index 000000000..a35b6ee05 --- /dev/null +++ b/tests/auto/blackbox/testdata/ruleConditions/modules/narfzort/narfzort.qbs @@ -0,0 +1,26 @@ +import qbs 1.0 + +Module { + property bool buildZort: true + FileTagger { + pattern: "*.narf" + fileTags: ["narf"] + } + Rule { + condition: product.moduleProperty("narfzort", "buildZort"); + inputs: ["narf"] + Artifact { + fileName: product.name + "." + input.fileName + ".zort" + fileTags: ["zort"] + } + prepare: { + var cmd = JavaScriptCommand(); + cmd.sourceCode = function() { + var f = new TextFile(output.fileName, TextFile.WriteOnly); + f.write("NARF! ZORT!"); + f.close(); + } + return cmd; + } + } +} diff --git a/tests/auto/blackbox/testdata/ruleConditions/ruleConditions.qbs b/tests/auto/blackbox/testdata/ruleConditions/ruleConditions.qbs new file mode 100644 index 000000000..766bf3c5d --- /dev/null +++ b/tests/auto/blackbox/testdata/ruleConditions/ruleConditions.qbs @@ -0,0 +1,12 @@ +import qbs 1.0 +import "templates/zorduct.qbs" as Zorduct + +Project { + Zorduct { + narfzort.buildZort: false + name: "unzorted" + } + Zorduct { + name: "zorted" + } +} diff --git a/tests/auto/blackbox/testdata/ruleConditions/templates/zorduct.qbs b/tests/auto/blackbox/testdata/ruleConditions/templates/zorduct.qbs new file mode 100644 index 000000000..c36e00850 --- /dev/null +++ b/tests/auto/blackbox/testdata/ruleConditions/templates/zorduct.qbs @@ -0,0 +1,11 @@ +import qbs 1.0 + +Product { + type: ["application", "zort"] + Depends { name: "cpp" } + Depends { name: "narfzort" } + files: [ + "main.cpp", + "foo.narf" + ] +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 2540cdfd6..f651677df 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -721,6 +721,16 @@ void TestBlackbox::recursiveWildcards() QVERIFY(QFileInfo(defaultInstallRoot + "/dir/file2.txt").exists()); } +void TestBlackbox::ruleConditions() +{ + QDir::setCurrent(testDataDir + "/ruleConditions"); + QCOMPARE(runQbs(), 0); + QVERIFY(QFileInfo(buildDir + HostOsInfo::appendExecutableSuffix("/zorted")).exists()); + QVERIFY(QFileInfo(buildDir + HostOsInfo::appendExecutableSuffix("/unzorted")).exists()); + QVERIFY(QFileInfo(buildDir + "/zorted.foo.narf.zort").exists()); + QVERIFY(!QFileInfo(buildDir + "/unzorted.foo.narf.zort").exists()); +} + void TestBlackbox::codegen() { QDir::setCurrent(testDataDir + "/codegen"); diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index c67aad5ab..f2ca762ef 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -83,6 +83,7 @@ private slots: void wildcardRenaming(); void recursiveRenaming(); void recursiveWildcards(); + void ruleConditions(); void codegen(); void missingQObjectHeader(); void productProperties(); -- cgit v1.2.1