aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2017-03-22 16:01:19 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2017-03-29 12:53:51 +0000
commit89bd4b0e8578cf636aef8f3171327824f3c67984 (patch)
tree1a5e5193ffc9e80b75f0199dfd4f5f006f6dd961 /src/lib/corelib
parent688552ac738ccf406a9f3c2b673e70ae5bf6b8ca (diff)
Support readonly properties
[ChangeLog] The attempt of setting a read-only property within a qbs file now yields an error. It is still possible to override read-only properties from the command line. Task-number: QBS-1064 Change-Id: I0afe4272ac2fc14e51d5797da0bf1e2d7f3a3438 Reviewed-by: Jake Petroules <jake.petroules@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/lib/corelib')
-rw-r--r--src/lib/corelib/language/itemreaderastvisitor.cpp16
-rw-r--r--src/lib/corelib/language/moduleloader.cpp10
-rw-r--r--src/lib/corelib/language/propertydeclaration.h1
-rw-r--r--src/lib/corelib/language/tst_language.cpp6
4 files changed, 28 insertions, 5 deletions
diff --git a/src/lib/corelib/language/itemreaderastvisitor.cpp b/src/lib/corelib/language/itemreaderastvisitor.cpp
index 1c14534ff..f748119d2 100644
--- a/src/lib/corelib/language/itemreaderastvisitor.cpp
+++ b/src/lib/corelib/language/itemreaderastvisitor.cpp
@@ -171,6 +171,8 @@ bool ItemReaderASTVisitor::visit(AST::UiPublicMember *ast)
throw ErrorInfo(Tr::tr("public member with type modifier '%1' not supported").arg(
ast->typeModifier.toString()));
}
+ if (ast->isReadonlyMember)
+ p.setFlags(PropertyDeclaration::ReadOnlyFlag);
m_item->m_propertyDeclarations.insert(p.name(), p);
@@ -287,6 +289,15 @@ void ItemReaderASTVisitor::inheritItem(Item *dst, const Item *src)
child->m_parent = dst;
}
+ for (const PropertyDeclaration &pd : src->propertyDeclarations()) {
+ if (pd.flags().testFlag(PropertyDeclaration::ReadOnlyFlag)
+ && dst->hasOwnProperty(pd.name())) {
+ throw ErrorInfo(Tr::tr("Cannot set read-only property '%1'.").arg(pd.name()),
+ dst->property(pd.name())->location());
+ }
+ dst->setPropertyDeclaration(pd.name(), pd);
+ }
+
for (auto it = src->properties().constBegin(); it != src->properties().constEnd(); ++it) {
ValuePtr &v = dst->m_properties[it.key()];
if (!v) {
@@ -315,11 +326,6 @@ void ItemReaderASTVisitor::inheritItem(Item *dst, const Item *src)
QBS_CHECK(!"unexpected value type");
}
}
-
- for (auto it = src->propertyDeclarations().constBegin();
- it != src->propertyDeclarations().constEnd(); ++it) {
- dst->setPropertyDeclaration(it.key(), it.value());
- }
}
void ItemReaderASTVisitor::checkDeprecationStatus(ItemType itemType, const QString &itemName,
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index 01273c4e8..fa4a3e25f 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -2176,6 +2176,16 @@ void ModuleLoader::instantiateModule(ProductContext *productContext, Item *expor
moduleInstance->addModule(m);
}
+ // Check readonly properties.
+ const auto end = moduleInstance->properties().cend();
+ for (auto it = moduleInstance->properties().cbegin(); it != end; ++it) {
+ const PropertyDeclaration &pd = moduleInstance->propertyDeclaration(it.key());
+ if (!pd.flags().testFlag(PropertyDeclaration::ReadOnlyFlag))
+ continue;
+ throw ErrorInfo(Tr::tr("Cannot set read-only property '%1'.").arg(pd.name()),
+ moduleInstance->property(pd.name())->location());
+ }
+
// override module properties given on the command line
const QVariantMap userModuleProperties = m_parameters.overriddenValuesTree()
.value(QLatin1String("modules.") + fullName).toMap();
diff --git a/src/lib/corelib/language/propertydeclaration.h b/src/lib/corelib/language/propertydeclaration.h
index 7d5634b3c..6eaeb2259 100644
--- a/src/lib/corelib/language/propertydeclaration.h
+++ b/src/lib/corelib/language/propertydeclaration.h
@@ -70,6 +70,7 @@ public:
enum Flag
{
DefaultFlags = 0,
+ ReadOnlyFlag = 0x1,
PropertyNotAvailableInConfig = 0x2 // Is this property part of a project, product or file configuration?
};
Q_DECLARE_FLAGS(Flags, Flag)
diff --git a/src/lib/corelib/language/tst_language.cpp b/src/lib/corelib/language/tst_language.cpp
index 455961368..f004e4992 100644
--- a/src/lib/corelib/language/tst_language.cpp
+++ b/src/lib/corelib/language/tst_language.cpp
@@ -629,6 +629,12 @@ void TestLanguage::erroneousFiles_data()
"'Product', but it is of type 'Artifact'.";
QTest::newRow("module-depends-on-product")
<< "module-with-product-dependency.qbs:4:5.*Modules cannot depend on products.";
+ QTest::newRow("overwrite-inherited-readonly-property")
+ << "overwrite-inherited-readonly-property.qbs"
+ ":4:21.*Cannot set read-only property 'readOnlyString'.";
+ QTest::newRow("overwrite-readonly-module-property")
+ << "overwrite-readonly-module-property.qbs"
+ ":5:30.*Cannot set read-only property 'readOnlyString'.";
}
void TestLanguage::erroneousFiles()