From fb09fa02fc5323e931f314f873fea78853b15939 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 6 Dec 2012 10:54:37 +0100 Subject: Fix renaming files to be installed that are matched by a wildcard. The problem is that files matched by an "install" rule are currently not added to the target artifacts if a build graph already exists and they are "implicitly added" by adding or renaming a file in a group matched by a wildcard (i.e. the change happens without touching the project file). Task-number: QBS-146 Change-Id: Iec499de8dd88e3ac599b7435ec441aad7689f55a Reviewed-by: Joerg Bornemann --- src/lib/buildgraph/buildproject.cpp | 31 +++++++++++++--------- .../testdata/wildcard_renaming/pioniere.txt | 0 .../wildcard_renaming/wildcard_renaming.qbs | 9 +++++++ tests/auto/blackbox/tst_blackbox.cpp | 11 ++++++++ tests/auto/blackbox/tst_blackbox.h | 1 + 5 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 tests/auto/blackbox/testdata/wildcard_renaming/pioniere.txt create mode 100644 tests/auto/blackbox/testdata/wildcard_renaming/wildcard_renaming.qbs diff --git a/src/lib/buildgraph/buildproject.cpp b/src/lib/buildgraph/buildproject.cpp index 40c3ebe7e..4b7434e29 100644 --- a/src/lib/buildgraph/buildproject.cpp +++ b/src/lib/buildgraph/buildproject.cpp @@ -294,6 +294,21 @@ BuildProjectPtr BuildProjectResolver::resolveProject(const ResolvedProjectPtr &r return m_project; } +static void addTargetArtifacts(const BuildProductPtr &product, + ArtifactsPerFileTagMap &artifactsPerFileTag) +{ + foreach (const QString &fileTag, product->rProduct->fileTags) { + foreach (Artifact * const artifact, artifactsPerFileTag.value(fileTag)) { + if (artifact->artifactType == Artifact::Generated) + product->targetArtifacts += artifact; + } + } + if (product->targetArtifacts.isEmpty()) { + QString msg = Tr::tr("No artifacts generated for product '%1'."); + throw Error(msg.arg(product->rProduct->name)); + } +} + BuildProductPtr BuildProjectResolver::resolveProduct(const ResolvedProductPtr &rProduct) { BuildProductPtr product = m_productCache.value(rProduct); @@ -384,19 +399,7 @@ BuildProductPtr BuildProjectResolver::resolveProduct(const ResolvedProductPtr &r } RulesApplicator(product.data(), artifactsPerFileTag).applyAllRules(); - - QSet productArtifactCandidates; - for (int i = 0; i < product->rProduct->fileTags.count(); ++i) - foreach (Artifact *artifact, artifactsPerFileTag.value(product->rProduct->fileTags.at(i))) - if (artifact->artifactType == Artifact::Generated) - productArtifactCandidates += artifact; - - if (productArtifactCandidates.isEmpty()) { - QString msg = QLatin1String("No artifacts generated for product '%1'."); - throw Error(msg.arg(product->rProduct->name)); - } - - product->targetArtifacts += productArtifactCandidates; + addTargetArtifacts(product, artifactsPerFileTag); m_project->addBuildProduct(product); return product; } @@ -628,6 +631,8 @@ void BuildProjectLoader::onProductChanged(const BuildProductPtr &product, artifactsPerFileTag[ft] += artifact; RulesApplicator(product.data(), artifactsPerFileTag).applyAllRules(); + addTargetArtifacts(product, artifactsPerFileTag); + // parents of removed artifacts must update their transformers foreach (Artifact *removedArtifact, artifactsToRemove) foreach (Artifact *parent, removedArtifact->parents) diff --git a/tests/auto/blackbox/testdata/wildcard_renaming/pioniere.txt b/tests/auto/blackbox/testdata/wildcard_renaming/pioniere.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/auto/blackbox/testdata/wildcard_renaming/wildcard_renaming.qbs b/tests/auto/blackbox/testdata/wildcard_renaming/wildcard_renaming.qbs new file mode 100644 index 000000000..fafe77ae5 --- /dev/null +++ b/tests/auto/blackbox/testdata/wildcard_renaming/wildcard_renaming.qbs @@ -0,0 +1,9 @@ +import qbs.base 1.0 + +Product { + type: "installed_content" + Group { + fileTags: "install" + files: "*" + } +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index ec2a95fa9..05f28e55c 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -449,4 +449,15 @@ void TestBlackbox::trackAddMocInclude() QCOMPARE(runQbs(), 0); } +void TestBlackbox::wildcardRenaming() +{ + QDir::setCurrent(testDataDir + "/wildcard_renaming"); + QCOMPARE(runQbs(QStringList()), 0); + QVERIFY(QFileInfo(buildDir + "/pioniere.txt").exists()); + QFile::rename(QDir::currentPath() + "/pioniere.txt", QDir::currentPath() + "/fdj.txt"); + QCOMPARE(runQbs(QStringList()), 0); + QVERIFY(!QFileInfo(buildDir + "/pioniere.txt").exists()); + QVERIFY(QFileInfo(buildDir + "/fdj.txt").exists()); +} + QTEST_MAIN(TestBlackbox) diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 5b91dcd62..8671ef302 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -71,6 +71,7 @@ private slots: void trackAddFileTag(); void trackRemoveFileTag(); void trackAddMocInclude(); + void wildcardRenaming(); }; #endif // TST_BLACKBOX_H -- cgit v1.2.3