diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2017-05-08 17:33:34 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2017-05-09 08:35:12 +0000 |
commit | 0eb78ba6c43288a85d056fd6264bfb23c6202cfc (patch) | |
tree | bf791072c941a3b2e09e3b9ce0c506da6a291da4 | |
parent | 82e7af13a45575b42f5cf4dda1e16c35dfee972b (diff) |
Fix JSSourceValue::clone()
For objects of type JSSourceValue::Alternative, we were mistakenly doing
shallow copies, which meant that modules using Properties items could
end up sharing the respective values between products, rather than each
of them getting their own copy.
Task-number: QBS-1121
Change-Id: I7b2b4b776772ac89fe6f08db0dba63b0c277d7ec
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r-- | src/lib/corelib/language/tst_language.cpp | 21 | ||||
-rw-r--r-- | src/lib/corelib/language/tst_language.h | 1 | ||||
-rw-r--r-- | src/lib/corelib/language/value.cpp | 13 | ||||
-rw-r--r-- | src/lib/corelib/language/value.h | 10 | ||||
-rw-r--r-- | tests/auto/language/testdata/modules/dummyqt/core/dummycore.qbs | 5 | ||||
-rw-r--r-- | tests/auto/language/testdata/properties-item-in-module.qbs | 6 |
6 files changed, 56 insertions, 0 deletions
diff --git a/src/lib/corelib/language/tst_language.cpp b/src/lib/corelib/language/tst_language.cpp index 151457872..f2ea5ab33 100644 --- a/src/lib/corelib/language/tst_language.cpp +++ b/src/lib/corelib/language/tst_language.cpp @@ -1861,6 +1861,27 @@ void TestLanguage::propertiesBlockInGroup() QCOMPARE(exceptionCaught, false); } +void TestLanguage::propertiesItemInModule() +{ + bool exceptionCaught = false; + try { + defaultParameters.setProjectFilePath( + testProject("properties-item-in-module.qbs")); + const TopLevelProjectPtr project = loader->loadProject(defaultParameters); + QVERIFY(project); + const QHash<QString, ResolvedProductPtr> products = productsFromProject(project); + QCOMPARE(products.count(), 2); + for (const ResolvedProductConstPtr &p : products) { + QCOMPARE(p->moduleProperties->moduleProperty("dummy", "productName").toString(), + p->name); + } + } catch (const ErrorInfo &e) { + exceptionCaught = true; + qDebug() << e.toString(); + } + QCOMPARE(exceptionCaught, false); +} + void TestLanguage::qbsPropertiesInProjectCondition() { bool exceptionCaught = false; diff --git a/src/lib/corelib/language/tst_language.h b/src/lib/corelib/language/tst_language.h index 9070b921b..de5d8f474 100644 --- a/src/lib/corelib/language/tst_language.h +++ b/src/lib/corelib/language/tst_language.h @@ -125,6 +125,7 @@ private slots: void propertiesBlocks_data(); void propertiesBlocks(); void propertiesBlockInGroup(); + void propertiesItemInModule(); void qbsPropertiesInProjectCondition(); void relaxedErrorMode(); void relaxedErrorMode_data(); diff --git a/src/lib/corelib/language/value.cpp b/src/lib/corelib/language/value.cpp index ab8d2af21..f1ddd770a 100644 --- a/src/lib/corelib/language/value.cpp +++ b/src/lib/corelib/language/value.cpp @@ -94,6 +94,19 @@ JSSourceValue::JSSourceValue(bool createdByPropertiesBlock) { } +JSSourceValue::JSSourceValue(const JSSourceValue &other) : Value(other) +{ + m_sourceCode = other.m_sourceCode; + m_line = other.m_line; + m_column = other.m_column; + m_file = other.m_file; + m_flags = other.m_flags; + m_baseValue = other.m_baseValue ? other.m_baseValue->clone().staticCast<JSSourceValue>() + : JSSourceValuePtr(); + for (const Alternative &otherAlt : qAsConst(other.m_alternatives)) + m_alternatives << otherAlt.clone(); +} + JSSourceValuePtr JSSourceValue::create(bool createdByPropertiesBlock) { return JSSourceValuePtr(new JSSourceValue(createdByPropertiesBlock)); diff --git a/src/lib/corelib/language/value.h b/src/lib/corelib/language/value.h index eb62f13ca..c38095697 100644 --- a/src/lib/corelib/language/value.h +++ b/src/lib/corelib/language/value.h @@ -95,6 +95,7 @@ class JSSourceValue : public Value { friend class ItemReaderASTVisitor; JSSourceValue(bool createdByPropertiesBlock); + JSSourceValue(const JSSourceValue &other); enum Flag { @@ -140,6 +141,15 @@ public: struct Alternative { + Alternative() { } + Alternative(const QString &c, const QString &o, const JSSourceValuePtr &v) + : condition(c), overrideListProperties(o), value(v) {} + Alternative clone() const + { + return Alternative(condition, overrideListProperties, + value->clone().staticCast<JSSourceValue>()); + } + QString condition; QString overrideListProperties; JSSourceValuePtr value; diff --git a/tests/auto/language/testdata/modules/dummyqt/core/dummycore.qbs b/tests/auto/language/testdata/modules/dummyqt/core/dummycore.qbs index e87bb27ff..995396202 100644 --- a/tests/auto/language/testdata/modules/dummyqt/core/dummycore.qbs +++ b/tests/auto/language/testdata/modules/dummyqt/core/dummycore.qbs @@ -14,4 +14,9 @@ Module { dummy.defines: ["QT_CORE"] dummy.rpaths: ["/opt/qt/lib"] dummy.cFlags: [zort] + + Properties { + condition: true + dummy.productName: product.name + } } diff --git a/tests/auto/language/testdata/properties-item-in-module.qbs b/tests/auto/language/testdata/properties-item-in-module.qbs new file mode 100644 index 000000000..53c765d49 --- /dev/null +++ b/tests/auto/language/testdata/properties-item-in-module.qbs @@ -0,0 +1,6 @@ +import qbs + +Project { + Product { name: "a"; Depends { name: "dummyqt.core" } } + Product { name: "b"; Depends { name: "dummyqt.core" } } +} |