From aa31e2dced97062552934271d186a43c3fd8e457 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 4 Dec 2013 13:44:48 +0100 Subject: Fix "clean" operation. We were missing some artifacts, and we also left some empty directories behind. Change-Id: Ib93fb7a6a644e09526c8d4e177d580fe2d870c54 Reviewed-by: Joerg Bornemann --- src/lib/buildgraph/artifactcleaner.cpp | 12 +++++++-- tests/auto/blackbox/testdata/clean/clean.qbs | 6 ++--- tests/auto/blackbox/tst_blackbox.cpp | 39 +++++++++++++++++++++------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/lib/buildgraph/artifactcleaner.cpp b/src/lib/buildgraph/artifactcleaner.cpp index f4c5b47b0..7e9a449d4 100644 --- a/src/lib/buildgraph/artifactcleaner.cpp +++ b/src/lib/buildgraph/artifactcleaner.cpp @@ -30,6 +30,7 @@ #include "artifact.h" #include "artifactvisitor.h" +#include "productbuilddata.h" #include "projectbuilddata.h" #include @@ -107,7 +108,7 @@ private: { if (artifact->product != m_product) return; - if (artifact->parents.isEmpty() + if (artifact->product->buildData->targetArtifacts.contains(artifact) && m_options.cleanType() == CleanOptions::CleanupTemporaries) { return; } @@ -154,9 +155,16 @@ void ArtifactCleaner::cleanup(const TopLevelProjectPtr &project, // Directories created during the build are not artifacts (TODO: should they be?), // so we have to clean them up manually. - foreach (const QString &dir, directories) { + QList dirList = directories.toList(); + for (int i = 0; i < dirList.count(); ++i) { + const QString &dir = dirList.at(i); if (dir.startsWith(project->buildDirectory) && FileInfo(dir).exists()) removeEmptyDirectories(dir, options); + if (dir != project->buildDirectory) { + const QString parentDir = QDir::cleanPath(dir + "/.."); + if (parentDir != project->buildDirectory && !dirList.contains(parentDir)) + dirList << parentDir; + } } m_observer->incrementProgressValue(); diff --git a/tests/auto/blackbox/testdata/clean/clean.qbs b/tests/auto/blackbox/testdata/clean/clean.qbs index 11e3a2c21..3bc56b8fe 100644 --- a/tests/auto/blackbox/testdata/clean/clean.qbs +++ b/tests/auto/blackbox/testdata/clean/clean.qbs @@ -1,9 +1,9 @@ import qbs 1.0 Project { - // Explicit type needed to prevent bundle generation on Darwin platforms. - CppApplication { - type: "application" + DynamicLibrary { + Depends { name: "cpp" } + version: "1.1.0" name: "dep" files: "dep.cpp" } diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index c796d3e61..90b8a6c88 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -368,7 +368,16 @@ void TestBlackbox::clean() const QString appObjectFilePath = buildDir + "/.obj/app/main.cpp" + QTC_HOST_OBJECT_SUFFIX; const QString appExeFilePath = buildDir + "/app" + QTC_HOST_EXE_SUFFIX; const QString depObjectFilePath = buildDir + "/.obj/dep/dep.cpp" + QTC_HOST_OBJECT_SUFFIX; - const QString depExeFilePath = buildDir + "/dep" + QTC_HOST_EXE_SUFFIX; + const QString depLibBase = buildDir + '/' + QTC_HOST_DYNAMICLIB_PREFIX + "dep" + + QTC_HOST_DYNAMICLIB_SUFFIX; + QString depLibFilePath; + QStringList symlinks; + if (qbs::Internal::HostOsInfo::isAnyUnixHost()) { + depLibFilePath = depLibBase + ".1.1.0"; + symlinks << depLibBase + ".1.1" << depLibBase + ".1" << depLibBase; + } else { + depLibFilePath = depLibBase; + } QDir::setCurrent(testDataDir + "/clean"); @@ -377,12 +386,16 @@ void TestBlackbox::clean() QVERIFY(QFile(appObjectFilePath).exists()); QVERIFY(QFile(appExeFilePath).exists()); QVERIFY(QFile(depObjectFilePath).exists()); - QVERIFY(QFile(depExeFilePath).exists()); + QVERIFY(QFile(depLibFilePath).exists()); + foreach (const QString &symLink, symlinks) + QVERIFY2(QFile(symLink).exists(), qPrintable(symLink)); QCOMPARE(runQbs(QbsRunParameters("clean")), 0); QVERIFY(!QFile(appObjectFilePath).exists()); QVERIFY(QFile(appExeFilePath).exists()); QVERIFY(!QFile(depObjectFilePath).exists()); - QVERIFY(QFile(depExeFilePath).exists()); + QVERIFY(QFile(depLibFilePath).exists()); + foreach (const QString &symLink, symlinks) + QVERIFY2(!QFile(symLink).exists(), qPrintable(symLink)); // Remove all. QCOMPARE(runQbs(), 0); @@ -392,7 +405,9 @@ void TestBlackbox::clean() QVERIFY(!QFile(appObjectFilePath).exists()); QVERIFY(!QFile(appExeFilePath).exists()); QVERIFY(!QFile(depObjectFilePath).exists()); - QVERIFY(!QFile(depExeFilePath).exists()); + QVERIFY(!QFile(depLibFilePath).exists()); + foreach (const QString &symLink, symlinks) + QVERIFY2(!QFile(symLink).exists(), qPrintable(symLink)); // Dry run. QCOMPARE(runQbs(), 0); @@ -402,33 +417,39 @@ void TestBlackbox::clean() QVERIFY(QFile(appObjectFilePath).exists()); QVERIFY(QFile(appExeFilePath).exists()); QVERIFY(QFile(depObjectFilePath).exists()); - QVERIFY(QFile(depExeFilePath).exists()); + QVERIFY(QFile(depLibFilePath).exists()); + foreach (const QString &symLink, symlinks) + QVERIFY2(QFile(symLink).exists(), qPrintable(symLink)); // Product-wise, dependency only. QCOMPARE(runQbs(), 0); QVERIFY(QFile(appObjectFilePath).exists()); QVERIFY(QFile(appExeFilePath).exists()); QVERIFY(QFile(depObjectFilePath).exists()); - QVERIFY(QFile(depExeFilePath).exists()); + QVERIFY(QFile(depLibFilePath).exists()); QCOMPARE(runQbs(QbsRunParameters(QStringList("clean") << "--all-artifacts" << "-p" << "dep")), 0); QVERIFY(QFile(appObjectFilePath).exists()); QVERIFY(QFile(appExeFilePath).exists()); QVERIFY(!QFile(depObjectFilePath).exists()); - QVERIFY(!QFile(depExeFilePath).exists()); + QVERIFY(!QFile(depLibFilePath).exists()); + foreach (const QString &symLink, symlinks) + QVERIFY2(!QFile(symLink).exists(), qPrintable(symLink)); // Product-wise, dependent product only. QCOMPARE(runQbs(), 0); QVERIFY(QFile(appObjectFilePath).exists()); QVERIFY(QFile(appExeFilePath).exists()); QVERIFY(QFile(depObjectFilePath).exists()); - QVERIFY(QFile(depExeFilePath).exists()); + QVERIFY(QFile(depLibFilePath).exists()); QCOMPARE(runQbs(QbsRunParameters(QStringList("clean") << "--all-artifacts" << "-p" << "app")), 0); QVERIFY(!QFile(appObjectFilePath).exists()); QVERIFY(!QFile(appExeFilePath).exists()); QVERIFY(QFile(depObjectFilePath).exists()); - QVERIFY(QFile(depExeFilePath).exists()); + QVERIFY(QFile(depLibFilePath).exists()); + foreach (const QString &symLink, symlinks) + QVERIFY2(QFile(symLink).exists(), qPrintable(symLink)); } void TestBlackbox::exportSimple() -- cgit v1.2.3