summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@digia.com>2013-04-03 11:40:30 +0200
committerChristian Kandeler <christian.kandeler@digia.com>2013-04-05 10:59:40 +0200
commitffb6be9612e270372d3fa9887d74cdaa1d9306cc (patch)
tree9692d91f2163a9a78e3732100a0c856ffcc12bb8
parentb29a80aee8a9adaca5ffd2c172670158458c5614 (diff)
downloadqbs-ffb6be9612e270372d3fa9887d74cdaa1d9306cc.tar.gz
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 <christian.kandeler@digia.com>
-rw-r--r--src/lib/language/builtindeclarations.cpp1
-rw-r--r--src/lib/language/projectresolver.cpp6
-rw-r--r--tests/auto/blackbox/testdata/ruleConditions/foo.narf0
-rw-r--r--tests/auto/blackbox/testdata/ruleConditions/main.cpp1
-rw-r--r--tests/auto/blackbox/testdata/ruleConditions/modules/narfzort/narfzort.qbs26
-rw-r--r--tests/auto/blackbox/testdata/ruleConditions/ruleConditions.qbs12
-rw-r--r--tests/auto/blackbox/testdata/ruleConditions/templates/zorduct.qbs11
-rw-r--r--tests/auto/blackbox/tst_blackbox.cpp10
-rw-r--r--tests/auto/blackbox/tst_blackbox.h1
9 files changed, 68 insertions, 0 deletions
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<PropertyDeclaration> 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 <jsextensions/moduleproperties.h>
#include <logging/translator.h>
#include <tools/error.h>
#include <tools/fileinfo.h>
@@ -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<ItemPtr> 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
--- /dev/null
+++ b/tests/auto/blackbox/testdata/ruleConditions/foo.narf
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();