diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2013-11-29 15:12:40 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2013-12-05 11:23:19 +0100 |
commit | abb499afaf5b3c2339980fefa5f82fd9239881f2 (patch) | |
tree | 8f1beff40674ba0282f409b8a743c32cd2f4ee05 | |
parent | a9ad6ffc6e6e51e9c3b398818a2376ae9ecf5bda (diff) |
Allow directories in "references" properties.
Such a construct will work if the given directory contains exactly
one project file, identified by the ".qbs" extension.
This saves annoying redundancies of the form
"references: 'mysubproject/mysubproject.qbs'".
Change-Id: Ief0f52f788189b7fb2e4764b692159b570fe444c
Task-number: QBS-454
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
13 files changed, 70 insertions, 2 deletions
diff --git a/src/lib/language/moduleloader.cpp b/src/lib/language/moduleloader.cpp index 384221cbf..de5b93e15 100644 --- a/src/lib/language/moduleloader.cpp +++ b/src/lib/language/moduleloader.cpp @@ -236,7 +236,25 @@ void ModuleLoader::handleProject(ModuleLoaderResult *loadResult, Item *item, const QString projectFileDirPath = FileInfo::path(item->file()->filePath()); const QStringList refs = m_evaluator->stringListValue(item, QLatin1String("references")); foreach (const QString &filePath, refs) { - const QString absReferencePath = FileInfo::resolvePath(projectFileDirPath, filePath); + QString absReferencePath = FileInfo::resolvePath(projectFileDirPath, filePath); + if (FileInfo(absReferencePath).isDir()) { + QString qbsFilePath; + QDirIterator dit(absReferencePath, QStringList(QLatin1String("*.qbs"))); + while (dit.hasNext()) { + if (!qbsFilePath.isEmpty()) { + throw ErrorInfo(Tr::tr("Referenced directory '%1' contains more than one " + "qbs file.").arg(absReferencePath), + item->property(QLatin1String("references"))->location()); + } + qbsFilePath = dit.next(); + } + if (qbsFilePath.isEmpty()) { + throw ErrorInfo(Tr::tr("Referenced directory '%1' does not contain a qbs file.") + .arg(absReferencePath), + item->property(QLatin1String("references"))->location()); + } + absReferencePath = qbsFilePath; + } if (referencedFilePaths.contains(absReferencePath)) throw ErrorInfo(Tr::tr("Cycle detected while referencing file '%1'.").arg(filePath), item->property(QLatin1String("references"))->location()); diff --git a/tests/auto/api/testdata/references/invalid1.qbs b/tests/auto/api/testdata/references/invalid1.qbs new file mode 100644 index 000000000..4bbb26d3a --- /dev/null +++ b/tests/auto/api/testdata/references/invalid1.qbs @@ -0,0 +1,5 @@ +import qbs + +Project { + references: "subdir-with-no-project" +}
\ No newline at end of file diff --git a/tests/auto/api/testdata/references/invalid2.qbs b/tests/auto/api/testdata/references/invalid2.qbs new file mode 100644 index 000000000..1946e2221 --- /dev/null +++ b/tests/auto/api/testdata/references/invalid2.qbs @@ -0,0 +1,5 @@ +import qbs + +Project { + references: "subdir-with-multiple-projects" +}
\ No newline at end of file diff --git a/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject1.qbs b/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject1.qbs new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject1.qbs diff --git a/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject2.qbs b/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject2.qbs new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject2.qbs diff --git a/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject3.qbs b/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject3.qbs new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/references/subdir-with-multiple-projects/subproject3.qbs diff --git a/tests/auto/api/testdata/references/subdir-with-no-project/test.txt b/tests/auto/api/testdata/references/subdir-with-no-project/test.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/references/subdir-with-no-project/test.txt diff --git a/tests/auto/api/testdata/references/subdir-with-one-project/p.qbs b/tests/auto/api/testdata/references/subdir-with-one-project/p.qbs new file mode 100644 index 000000000..7d453a671 --- /dev/null +++ b/tests/auto/api/testdata/references/subdir-with-one-project/p.qbs @@ -0,0 +1,3 @@ +import qbs + +Project { } diff --git a/tests/auto/api/testdata/references/subdir-with-one-project/test.txt b/tests/auto/api/testdata/references/subdir-with-one-project/test.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/references/subdir-with-one-project/test.txt diff --git a/tests/auto/api/testdata/references/valid.qbs b/tests/auto/api/testdata/references/valid.qbs new file mode 100644 index 000000000..43d728a4d --- /dev/null +++ b/tests/auto/api/testdata/references/valid.qbs @@ -0,0 +1,5 @@ +import qbs + +Project { + references: "subdir-with-one-project" +} diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp index 61b1ebc83..775ed6ec1 100644 --- a/tests/auto/api/tst_api.cpp +++ b/tests/auto/api/tst_api.cpp @@ -45,6 +45,7 @@ #include <QCoreApplication> #include <QDir> #include <QEventLoop> +#include <QFileInfo> #include <QScopedPointer> #include <QStringList> #include <QTest> @@ -480,6 +481,36 @@ qbs::SetupProjectParameters TestApi::defaultSetupParameters() const return setupParams; } +void TestApi::references() +{ + qbs::SetupProjectParameters setupParams = defaultSetupParameters(); + const QString projectDir = QDir::cleanPath(m_workingDataDir + "/references"); + setupParams.setProjectFilePath(projectDir + QLatin1String("/invalid1.qbs")); + QScopedPointer<qbs::SetupProjectJob> job(qbs::Project::setupProject(setupParams, + m_logSink, 0)); + waitForFinished(job.data()); + QVERIFY(job->error().hasError()); + QString errorString = job->error().toString(); + QVERIFY2(errorString.contains("does not contain"), qPrintable(errorString)); + + setupParams.setProjectFilePath(projectDir + QLatin1String("/invalid2.qbs")); + job.reset(qbs::Project::setupProject(setupParams, m_logSink, 0)); + waitForFinished(job.data()); + QVERIFY(job->error().hasError()); + errorString = job->error().toString(); + QVERIFY2(errorString.contains("contains more than one"), qPrintable(errorString)); + + setupParams.setProjectFilePath(projectDir + QLatin1String("/valid.qbs")); + job.reset(qbs::Project::setupProject(setupParams, m_logSink, 0)); + waitForFinished(job.data()); + QVERIFY2(!job->error().hasError(), qPrintable(job->error().toString())); + const qbs::ProjectData topLevelProject = job->project().projectData(); + QCOMPARE(topLevelProject.subProjects().count(), 1); + const QString subProjectFileName + = QFileInfo(topLevelProject.subProjects().first().location().fileName()).fileName(); + QCOMPARE(subProjectFileName, QString("p.qbs")); +} + QTEST_MAIN(TestApi) #include "tst_api.moc" diff --git a/tests/auto/api/tst_api.h b/tests/auto/api/tst_api.h index ffeff6922..f240dca2e 100644 --- a/tests/auto/api/tst_api.h +++ b/tests/auto/api/tst_api.h @@ -54,6 +54,7 @@ private slots: void listBuildSystemFiles(); void nonexistingProjectPropertyFromProduct(); void nonexistingProjectPropertyFromCommandLine(); + void references(); private: qbs::SetupProjectParameters defaultSetupParameters() const; diff --git a/tests/auto/blackbox/testdata/subprojects/toplevelproject.qbs b/tests/auto/blackbox/testdata/subprojects/toplevelproject.qbs index 84a2a211f..f167ccabc 100644 --- a/tests/auto/blackbox/testdata/subprojects/toplevelproject.qbs +++ b/tests/auto/blackbox/testdata/subprojects/toplevelproject.qbs @@ -2,7 +2,7 @@ import qbs Project { name: "top level project" - references: ["subproject2/subproject2.qbs"] + references: ["subproject2"] Project { condition: true |