From 41d39eee1272a00d2bdbe525aff8d99ec2a4d7f8 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 21 Feb 2020 18:21:06 +0100 Subject: Artifact Scanning: Prefer scan results from product dependencies If scanning finds an artifact in more than one product, we so far randomly used one of them. We now prefer artifacts from product dependencies, because the other ones might get lost during change tracking, as we don't keep an "is scan result of" type of information in our RescuableArtifactData. This should fix the linked bug in the vast majority of actual projects. It's also conceptually the right thing to do, because the artifact in the product dependency is much more likely to be the one that was intended to be found. Task-number: QBS-1532 Change-Id: Idd8662bb00570bc57f5861ce83517f0adb845b49 Reviewed-by: Joerg Bornemann --- .../scan-result-in-non-dependency/app/app.h | 1 + .../scan-result-in-non-dependency/app/app.qbs | 4 ++++ .../scan-result-in-non-dependency/app/main.cpp | 3 +++ .../scan-result-in-non-dependency/lib/lib.h | 3 +++ .../scan-result-in-non-dependency/other/other.qbs | 24 ++++++++++++++++++++++ .../testdata/scan-result-in-non-dependency/p.qbs | 6 ++++++ tests/auto/blackbox/tst_blackbox.cpp | 22 ++++++++++++++++++++ tests/auto/blackbox/tst_blackbox.h | 1 + 8 files changed, 64 insertions(+) create mode 100644 tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/app.h create mode 100644 tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/app.qbs create mode 100644 tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/main.cpp create mode 100644 tests/auto/blackbox/testdata/scan-result-in-non-dependency/lib/lib.h create mode 100644 tests/auto/blackbox/testdata/scan-result-in-non-dependency/other/other.qbs create mode 100644 tests/auto/blackbox/testdata/scan-result-in-non-dependency/p.qbs (limited to 'tests/auto') diff --git a/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/app.h b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/app.h new file mode 100644 index 000000000..a82b12fbd --- /dev/null +++ b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/app.h @@ -0,0 +1 @@ +#include "lib.h" diff --git a/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/app.qbs b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/app.qbs new file mode 100644 index 000000000..e931b853c --- /dev/null +++ b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/app.qbs @@ -0,0 +1,4 @@ +CppApplication { + cpp.includePaths: project.sourceDirectory + "/lib" + files: "main.cpp" +} diff --git a/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/main.cpp b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/main.cpp new file mode 100644 index 000000000..2e7bedac8 --- /dev/null +++ b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/app/main.cpp @@ -0,0 +1,3 @@ +#include "app.h" + +int main() { } diff --git a/tests/auto/blackbox/testdata/scan-result-in-non-dependency/lib/lib.h b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/lib/lib.h new file mode 100644 index 000000000..af6f627b7 --- /dev/null +++ b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/lib/lib.h @@ -0,0 +1,3 @@ +#pragma once + +void lib1_foo(); \ No newline at end of file diff --git a/tests/auto/blackbox/testdata/scan-result-in-non-dependency/other/other.qbs b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/other/other.qbs new file mode 100644 index 000000000..29682da1c --- /dev/null +++ b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/other/other.qbs @@ -0,0 +1,24 @@ +import qbs.TextFile + +Product { + type: "testproduct" + files: "../lib/lib.h" + + Rule { + multiplex: true + Artifact { + fileTags: ["testproduct"] + filePath: "fubar" + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating text file"; + cmd.sourceCode = function() { + var tf = new TextFile(output.filePath, TextFile.WriteOnly); + tf.writeLine("blubb"); + tf.close(); + } + return cmd; + } + } +} diff --git a/tests/auto/blackbox/testdata/scan-result-in-non-dependency/p.qbs b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/p.qbs new file mode 100644 index 000000000..bcbd5ebce --- /dev/null +++ b/tests/auto/blackbox/testdata/scan-result-in-non-dependency/p.qbs @@ -0,0 +1,6 @@ +Project { + references: [ + "app/app.qbs", + "other/other.qbs", + ] +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 39f89855d..324723ce3 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -2522,9 +2522,31 @@ void TestBlackbox::scannerItem() void TestBlackbox::scanResultInOtherProduct() { QDir::setCurrent(testDataDir + "/scan-result-in-other-product"); + QCOMPARE(runQbs(QStringList("-vv")), 0); + QVERIFY2(m_qbsStdout.contains("compiling main.cpp"), m_qbsStdout.constData()); + QVERIFY2(m_qbsStdout.contains("generating text file"), m_qbsStdout.constData()); + QVERIFY2(!m_qbsStderr.contains("The file dependency might get lost during change tracking"), + m_qbsStderr.constData()); + WAIT_FOR_NEW_TIMESTAMP(); + REPLACE_IN_FILE("other/other.qbs", "blubb", "blubb2"); + QCOMPARE(runQbs(), 0); + QVERIFY2(!m_qbsStdout.contains("compiling main.cpp"), m_qbsStdout.constData()); + QVERIFY2(m_qbsStdout.contains("generating text file"), m_qbsStdout.constData()); + WAIT_FOR_NEW_TIMESTAMP(); + touch("lib/lib.h"); QCOMPARE(runQbs(), 0); QVERIFY2(m_qbsStdout.contains("compiling main.cpp"), m_qbsStdout.constData()); + QVERIFY2(!m_qbsStdout.contains("generating text file"), m_qbsStdout.constData()); +} + +void TestBlackbox::scanResultInNonDependency() +{ + QDir::setCurrent(testDataDir + "/scan-result-in-non-dependency"); + QCOMPARE(runQbs(QStringList("-vv")), 0); + QVERIFY2(m_qbsStdout.contains("compiling main.cpp"), m_qbsStdout.constData()); QVERIFY2(m_qbsStdout.contains("generating text file"), m_qbsStdout.constData()); + QVERIFY2(m_qbsStderr.contains("The file dependency might get lost during change tracking"), + m_qbsStderr.constData()); WAIT_FOR_NEW_TIMESTAMP(); REPLACE_IN_FILE("other/other.qbs", "blubb", "blubb2"); QCOMPARE(runQbs(), 0); diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 54fa9c90e..ec6b9f7e4 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -273,6 +273,7 @@ private slots: void sanitizer(); void scannerItem(); void scanResultInOtherProduct(); + void scanResultInNonDependency(); void setupBuildEnvironment(); void setupRunEnvironment(); void smartRelinking(); -- cgit v1.2.3