aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2018-06-20 15:43:59 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2018-06-25 09:15:34 +0000
commitfbbd436bf1aea9522456f0a99196fa724b7c951c (patch)
tree08dc269cd8fefef60051dc837da4ff3483e608c4
parent10c7da071f1dcf2f3fcc7b1c970b3cff7f376a65 (diff)
Properly diagnose invalid module property assignments
... if the non-existing module name has more than one component. We inadvertantly skipped the check in that case. Task-number: QBS-1362 Change-Id: I1fcababee1ea70c3133bd1b1c8f8f32f8450a0e8 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r--src/lib/corelib/language/moduleloader.cpp6
-rw-r--r--src/lib/qtprofilesetup/templates/qml.qbs8
-rw-r--r--tests/auto/language/testdata/dotted-names/dotted-names.qbs24
-rw-r--r--tests/auto/language/testdata/dotted-names/modules/x/y/xy.qbs5
-rw-r--r--tests/auto/language/tst_language.cpp44
-rw-r--r--tests/auto/language/tst_language.h2
6 files changed, 84 insertions, 5 deletions
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index 41781cb7d..567cf0aa0 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -430,12 +430,12 @@ private:
if (!itemIsModuleInstance
&& value->item()->type() != ItemType::ModulePrefix
- && m_parentItem->file()
- && (!m_parentItem->file()->idScope()
+ && (!m_parentItem->file() || !m_parentItem->file()->idScope()
|| !m_parentItem->file()->idScope()->hasProperty(m_currentName))
&& !value->createdByPropertiesBlock()) {
const ErrorInfo error(Tr::tr("Item '%1' is not declared. "
- "Did you forget to add a Depends item?").arg(m_currentName),
+ "Did you forget to add a Depends item?")
+ .arg(m_currentModuleName.toString()),
value->location().isValid() ? value->location()
: m_parentItem->location());
handlePropertyError(error, m_params, m_logger);
diff --git a/src/lib/qtprofilesetup/templates/qml.qbs b/src/lib/qtprofilesetup/templates/qml.qbs
index 95b5d2790..3047873af 100644
--- a/src/lib/qtprofilesetup/templates/qml.qbs
+++ b/src/lib/qtprofilesetup/templates/qml.qbs
@@ -15,9 +15,13 @@ QtModule {
Depends { name: "Qt.qmlcache"; condition: generateCacheFiles; required: false }
readonly property bool cachingEnabled: generateCacheFiles && Qt.qmlcache.present
property string qmlCacheGenPath
- Qt.qmlcache.qmlCacheGenPath: qmlCacheGenPath || original
+ Properties {
+ condition: cachingEnabled
+ Qt.qmlcache.qmlCacheGenPath: qmlCacheGenPath || original
+ Qt.qmlcache.installDir: cacheFilesInstallDir || original
+ }
+
property string cacheFilesInstallDir
- Qt.qmlcache.installDir: cacheFilesInstallDir || original
readonly property string pluginListFilePathDebug: product.buildDirectory + "/plugins.list.d"
readonly property string pluginListFilePathRelease: product.buildDirectory + "/plugins.list"
diff --git a/tests/auto/language/testdata/dotted-names/dotted-names.qbs b/tests/auto/language/testdata/dotted-names/dotted-names.qbs
new file mode 100644
index 000000000..cf5658384
--- /dev/null
+++ b/tests/auto/language/testdata/dotted-names/dotted-names.qbs
@@ -0,0 +1,24 @@
+import qbs
+
+Project {
+ name: "theProject"
+ property bool includeDottedProduct
+ property bool includeDottedModule
+
+ Project {
+ condition: project.includeDottedProduct
+ Product {
+ name: "a.b"
+ Export { property string c: "default" }
+ }
+ }
+
+ Product {
+ name: "p"
+ Depends { name: "a.b"; condition: project.includeDottedProduct }
+ Depends { name: "x.y"; condition: project.includeDottedModule }
+ a.b.c: "p"
+ x.y.z: "p"
+ }
+}
+
diff --git a/tests/auto/language/testdata/dotted-names/modules/x/y/xy.qbs b/tests/auto/language/testdata/dotted-names/modules/x/y/xy.qbs
new file mode 100644
index 000000000..71cfac9cb
--- /dev/null
+++ b/tests/auto/language/testdata/dotted-names/modules/x/y/xy.qbs
@@ -0,0 +1,5 @@
+import qbs
+
+Module {
+ property string z: "default"
+}
diff --git a/tests/auto/language/tst_language.cpp b/tests/auto/language/tst_language.cpp
index 4d24e773b..3c4637018 100644
--- a/tests/auto/language/tst_language.cpp
+++ b/tests/auto/language/tst_language.cpp
@@ -581,6 +581,50 @@ void TestLanguage::disabledSubProject()
QCOMPARE(exceptionCaught, false);
}
+void TestLanguage::dottedNames_data()
+{
+ QTest::addColumn<bool>("useProduct");
+ QTest::addColumn<bool>("useModule");
+ QTest::addColumn<bool>("expectSuccess");
+ QTest::addColumn<QString>("expectedErrorMessage");
+ QTest::newRow("missing product dependency") << false << true << false
+ << QString("Item 'a.b' is not declared. Did you forget to add a Depends item");
+ QTest::newRow("missing module dependency") << true << false << false
+ << QString("Item 'x.y' is not declared. Did you forget to add a Depends item");
+ QTest::newRow("missing both dependencies") << false << false << false << QString();
+ QTest::newRow("ok") << true << true << true << QString();
+}
+
+void TestLanguage::dottedNames()
+{
+ QFETCH(bool, expectSuccess);
+ try {
+ SetupProjectParameters params = defaultParameters;
+ params.setProjectFilePath(testProject("dotted-names/dotted-names.qbs"));
+ QFETCH(bool, useProduct);
+ QFETCH(bool, useModule);
+ const QVariantMap overridden{
+ std::make_pair("projects.theProject.includeDottedProduct", useProduct),
+ std::make_pair("projects.theProject.includeDottedModule", useModule)
+ };
+ params.setOverriddenValues(overridden);
+ TopLevelProjectPtr project = loader->loadProject(params);
+ QVERIFY(expectSuccess);
+ QVERIFY(!!project);
+ QHash<QString, ResolvedProductPtr> products = productsFromProject(project);
+ QCOMPARE(products.size(), useProduct ? 2 : 1);
+ const ResolvedProductPtr product = products.value("p");
+ QVERIFY(!!product);
+ QCOMPARE(product->moduleProperties->moduleProperty("a.b", "c").toString(), QString("p"));
+ QCOMPARE(product->moduleProperties->moduleProperty("x.y", "z").toString(), QString("p"));
+ } catch (const ErrorInfo &e) {
+ QVERIFY(!expectSuccess);
+ QFETCH(QString, expectedErrorMessage);
+ if (!expectedErrorMessage.isEmpty())
+ QVERIFY2(e.toString().contains(expectedErrorMessage), qPrintable(e.toString()));
+ }
+}
+
void TestLanguage::emptyJsFile()
{
bool exceptionCaught = false;
diff --git a/tests/auto/language/tst_language.h b/tests/auto/language/tst_language.h
index aab04ca29..18027ab45 100644
--- a/tests/auto/language/tst_language.h
+++ b/tests/auto/language/tst_language.h
@@ -91,6 +91,8 @@ private slots:
void dependencyOnAllProfiles();
void derivedSubProject();
void disabledSubProject();
+ void dottedNames_data();
+ void dottedNames();
void emptyJsFile();
void enumerateProjectProperties();
void environmentVariable();