diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2014-01-27 17:09:18 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2014-01-27 17:17:05 +0100 |
commit | 11212b4f40381e2a60a7339cfa0282b33e84e2d9 (patch) | |
tree | cb2013f5a2b469cbfb1e9e8d9f9bc7f02a0042be | |
parent | f98fb6e827d777dd0c5e7c52249aaa452e3bae8e (diff) |
Do not match files in build directories as source files.
This can currently happen if the user builds in the source dir and uses
recursive wildcards.
Change-Id: I5f3be03313640af046478ca55a381f14605176d4
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
7 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/corelib/language/language.cpp b/src/lib/corelib/language/language.cpp index 0debd2d5d..cad2a05f4 100644 --- a/src/lib/corelib/language/language.cpp +++ b/src/lib/corelib/language/language.cpp @@ -940,10 +940,21 @@ QSet<QString> SourceWildCards::expandPatterns(const GroupConstPtr &group, return files; } +static bool isQbsBuildDir(const QDir &dir) +{ + return dir.exists(dir.dirName() + QLatin1String(".bg")); +} + void SourceWildCards::expandPatterns(QSet<QString> &result, const GroupConstPtr &group, const QStringList &parts, const QString &baseDir) const { + // People might build directly in the project source directory. This is okay, since + // we keep the build data in a "container" directory. However, we must make sure we don't + // match any generated files therein as source files. + if (isQbsBuildDir(baseDir)) + return; + QStringList changed_parts = parts; bool recursive = false; QString part = changed_parts.takeFirst(); @@ -977,6 +988,8 @@ void SourceWildCards::expandPatterns(QSet<QString> &result, const GroupConstPtr QDirIterator it(baseDir, QStringList(filePattern), itFilters, itFlags); while (it.hasNext()) { const QString filePath = it.next(); + if (isQbsBuildDir(it.fileInfo().dir())) + continue; // See above. QBS_ASSERT(FileInfo(filePath).isDir() == isDir, break); if (isDir) expandPatterns(result, group, changed_parts, filePath); diff --git a/tests/auto/api/testdata/source-file-in-build-dir/file.cpp b/tests/auto/api/testdata/source-file-in-build-dir/file.cpp new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/source-file-in-build-dir/file.cpp diff --git a/tests/auto/api/testdata/source-file-in-build-dir/project.qbs b/tests/auto/api/testdata/source-file-in-build-dir/project.qbs new file mode 100644 index 000000000..47ae50a93 --- /dev/null +++ b/tests/auto/api/testdata/source-file-in-build-dir/project.qbs @@ -0,0 +1,5 @@ +import qbs + +CppApplication { + files: "**/*.cpp" +} diff --git a/tests/auto/api/testdata/source-file-in-build-dir/qt-debug/moc_blubb.cpp b/tests/auto/api/testdata/source-file-in-build-dir/qt-debug/moc_blubb.cpp new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/source-file-in-build-dir/qt-debug/moc_blubb.cpp diff --git a/tests/auto/api/testdata/source-file-in-build-dir/qt-debug/qt-debug.bg b/tests/auto/api/testdata/source-file-in-build-dir/qt-debug/qt-debug.bg new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/api/testdata/source-file-in-build-dir/qt-debug/qt-debug.bg diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp index c2b43980e..7536f4302 100644 --- a/tests/auto/api/tst_api.cpp +++ b/tests/auto/api/tst_api.cpp @@ -517,6 +517,23 @@ void TestApi::references() QCOMPARE(subProjectFileName, QString("p.qbs")); } +void TestApi::sourceFileInBuildDir() +{ + qbs::SetupProjectParameters setupParams = defaultSetupParameters(); + const QString projectDir = QDir::cleanPath(m_workingDataDir + "/source-file-in-build-dir"); + setupParams.setProjectFilePath(projectDir + QLatin1String("/project.qbs")); + QScopedPointer<qbs::SetupProjectJob> job(qbs::Project::setupProject(setupParams, + m_logSink, 0)); + waitForFinished(job.data()); + QVERIFY2(!job->error().hasError(), qPrintable(job->error().toString())); + const qbs::ProjectData projectData = job->project().projectData(); + QCOMPARE(projectData.allProducts().count(), 1); + const qbs::ProductData product = projectData.allProducts().first(); + QCOMPARE(product.groups().count(), 1); + const qbs::GroupData group = product.groups().first(); + QCOMPARE(group.allFilePaths().count(), 1); +} + QTEST_MAIN(TestApi) #include "tst_api.moc" diff --git a/tests/auto/api/tst_api.h b/tests/auto/api/tst_api.h index bc40ad0da..4f2ce62f9 100644 --- a/tests/auto/api/tst_api.h +++ b/tests/auto/api/tst_api.h @@ -55,6 +55,7 @@ private slots: void nonexistingProjectPropertyFromProduct(); void nonexistingProjectPropertyFromCommandLine(); void references(); + void sourceFileInBuildDir(); private: qbs::SetupProjectParameters defaultSetupParameters() const; |