diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2016-12-01 12:06:40 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2016-12-06 11:00:18 +0000 |
commit | 8e2d2afcd38c8e89b8e7c5329ee29e15f4e5d518 (patch) | |
tree | 2f4ab1c7b04d524da77381b03e01fec827b762cb | |
parent | d70a44607c142be32677fd8d2435c1e571c65b9f (diff) |
Emit deprecation warnings for relative paths in certain contexts
Namely, for those in groups not located in the same directory as the
product. We will change the base directory to a more sensible one in
1.8, and this patch gives users the chance to adapt in advance.
Change-Id: I3a470b7f0664dc399633292d3f026f9636ca7aad
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
20 files changed, 110 insertions, 0 deletions
diff --git a/src/lib/corelib/language/projectresolver.cpp b/src/lib/corelib/language/projectresolver.cpp index f2910787f..9d9d56a87 100644 --- a/src/lib/corelib/language/projectresolver.cpp +++ b/src/lib/corelib/language/projectresolver.cpp @@ -678,8 +678,36 @@ void ProjectResolver::resolveGroup(Item *item, ProjectContext *projectContext) } const CodeLocation filesLocation = item->property(QLatin1String("files"))->location(); + + // TODO: Remove in 1.8 + bool emittedRelPathWarning = false; + const auto relPathChecker = [this, group, &filesLocation, &emittedRelPathWarning] + (const QString &fileName) { + if (emittedRelPathWarning) + return; + if (FileInfo::isAbsolute(fileName)) + return; + if (FileInfo::isAbsolute(group->prefix)) + return; + if (FileInfo::path(filesLocation.filePath()) + == FileInfo::path(m_productContext->product->location.filePath())) { + return; + } + if (m_groupLocationWarnings.contains(filesLocation)) + return; + const QString warningMessage = Tr::tr("Deprecation warning: Group is not located in the " + "same directory as the associated product and references files using a " + "relative path. The base directory for resolving such paths will change " + "in Qbs 1.8 from the directory of the product to the directory of the group. " + "You should probably use an absolute path as the group prefix here."); + m_logger.printWarning(ErrorInfo(warningMessage, filesLocation)); + m_groupLocationWarnings << filesLocation; + emittedRelPathWarning = true; + }; + ErrorInfo fileError; if (!patterns.isEmpty()) { + std::for_each(patterns.cbegin(), patterns.cend(), relPathChecker); SourceWildCards::Ptr wildcards = SourceWildCards::create(); wildcards->excludePatterns = m_evaluator->stringListValue(item, QLatin1String("excludeFiles")); @@ -693,6 +721,7 @@ void ProjectResolver::resolveGroup(Item *item, ProjectContext *projectContext) } foreach (const QString &fileName, files) { + relPathChecker(fileName); createSourceArtifact(m_productContext->product, fileName, group, false, filesLocation, &m_productContext->sourceArtifactLocations, &fileError); } diff --git a/src/lib/corelib/language/projectresolver.h b/src/lib/corelib/language/projectresolver.h index 9bfdfd298..45e63eee4 100644 --- a/src/lib/corelib/language/projectresolver.h +++ b/src/lib/corelib/language/projectresolver.h @@ -133,6 +133,7 @@ private: mutable QHash<FileContextConstPtr, ResolvedFileContextPtr> m_fileContextMap; const SetupProjectParameters &m_setupParams; const ModuleLoaderResult &m_loadResult; + QSet<CodeLocation> m_groupLocationWarnings; qint64 m_elapsedTimeModPropEval; qint64 m_elapsedTimeAllPropEval; qint64 m_elapsedTimeGroups; diff --git a/tests/auto/blackbox/testdata/group-location-warning/GroupInSameDir.qbs b/tests/auto/blackbox/testdata/group-location-warning/GroupInSameDir.qbs new file mode 100644 index 000000000..bfcc47891 --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/GroupInSameDir.qbs @@ -0,0 +1,5 @@ +import qbs + +Group { + files: ["referenced-from-group-in-same-dir.txt"] +} diff --git a/tests/auto/blackbox/testdata/group-location-warning/group-location-warning.qbs b/tests/auto/blackbox/testdata/group-location-warning/group-location-warning.qbs new file mode 100644 index 000000000..3a43d54ab --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/group-location-warning.qbs @@ -0,0 +1,27 @@ +import qbs +import "subdir/ParentInOtherDir.qbs" as ParentInOtherDir +import "subdir/AGroupInOtherDir.qbs" as AGroupInOtherDir +import "subdir/OtherGroupInOtherDir.qbs" as OtherGroupInOtherDir +import "subdir/YetAnotherGroupInOtherDir.qbs" as YetAnotherGroupInOtherDir +import "subdir/AndAnotherGroupInOtherDir.qbs" as AndAnotherGroupInOtherDir + +Project { + ParentInOtherDir { + name: "p1" + Depends { name: "gm" } + + Group { + files: ["referenced-from-product.txt"] + } + GroupInSameDir { } + AGroupInOtherDir { } + OtherGroupInOtherDir { } + YetAnotherGroupInOtherDir { } + AndAnotherGroupInOtherDir { } + } + + Product { + name: "p2" + AGroupInOtherDir { } + } +} diff --git a/tests/auto/blackbox/testdata/group-location-warning/modules/gm/gm.qbs b/tests/auto/blackbox/testdata/group-location-warning/modules/gm/gm.qbs new file mode 100644 index 000000000..8bdbbaf5b --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/modules/gm/gm.qbs @@ -0,0 +1,7 @@ +import qbs + +Module { + Group { + files: ["referenced-from-module.txt"] + } +} diff --git a/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-other-dir-via-wildcard.wc b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-other-dir-via-wildcard.wc new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-other-dir-via-wildcard.wc diff --git a/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-other-dir.txt b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-other-dir.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-other-dir.txt diff --git a/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-same-dir.txt b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-same-dir.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-group-in-same-dir.txt diff --git a/tests/auto/blackbox/testdata/group-location-warning/referenced-from-module.txt b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-module.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-module.txt diff --git a/tests/auto/blackbox/testdata/group-location-warning/referenced-from-parent-in-other-dir.txt b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-parent-in-other-dir.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-parent-in-other-dir.txt diff --git a/tests/auto/blackbox/testdata/group-location-warning/referenced-from-product.txt b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-product.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/referenced-from-product.txt diff --git a/tests/auto/blackbox/testdata/group-location-warning/referenced-via-absolute-path.txt b/tests/auto/blackbox/testdata/group-location-warning/referenced-via-absolute-path.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/referenced-via-absolute-path.txt diff --git a/tests/auto/blackbox/testdata/group-location-warning/referenced-via-absolute-prefix.txt b/tests/auto/blackbox/testdata/group-location-warning/referenced-via-absolute-prefix.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/referenced-via-absolute-prefix.txt diff --git a/tests/auto/blackbox/testdata/group-location-warning/subdir/AGroupInOtherDir.qbs b/tests/auto/blackbox/testdata/group-location-warning/subdir/AGroupInOtherDir.qbs new file mode 100644 index 000000000..104b389bf --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/subdir/AGroupInOtherDir.qbs @@ -0,0 +1,5 @@ +import qbs + +Group { + files: ["referenced-from-group-in-other-dir.txt"] +} diff --git a/tests/auto/blackbox/testdata/group-location-warning/subdir/AndAnotherGroupInOtherDir.qbs b/tests/auto/blackbox/testdata/group-location-warning/subdir/AndAnotherGroupInOtherDir.qbs new file mode 100644 index 000000000..f122fc396 --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/subdir/AndAnotherGroupInOtherDir.qbs @@ -0,0 +1,6 @@ +import qbs + +Group { + prefix: "./" + files: ["*.wc"] +} diff --git a/tests/auto/blackbox/testdata/group-location-warning/subdir/OtherGroupInOtherDir.qbs b/tests/auto/blackbox/testdata/group-location-warning/subdir/OtherGroupInOtherDir.qbs new file mode 100644 index 000000000..8c51ef2f8 --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/subdir/OtherGroupInOtherDir.qbs @@ -0,0 +1,5 @@ +import qbs + +Group { + files: [product.sourceDirectory + "/referenced-via-absolute-path.txt"] +} diff --git a/tests/auto/blackbox/testdata/group-location-warning/subdir/ParentInOtherDir.qbs b/tests/auto/blackbox/testdata/group-location-warning/subdir/ParentInOtherDir.qbs new file mode 100644 index 000000000..c1458624a --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/subdir/ParentInOtherDir.qbs @@ -0,0 +1,7 @@ +import qbs + +Product { + Group { + files: ["referenced-from-parent-in-other-dir.txt"] + } +} diff --git a/tests/auto/blackbox/testdata/group-location-warning/subdir/YetAnotherGroupInOtherDir.qbs b/tests/auto/blackbox/testdata/group-location-warning/subdir/YetAnotherGroupInOtherDir.qbs new file mode 100644 index 000000000..a3e977682 --- /dev/null +++ b/tests/auto/blackbox/testdata/group-location-warning/subdir/YetAnotherGroupInOtherDir.qbs @@ -0,0 +1,6 @@ +import qbs + +Group { + prefix: product.sourceDirectory + '/' + files: ["referenced-via-absolute-prefix.txt"] +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index dbeb014ab..6577ebbc4 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -3830,6 +3830,17 @@ void TestBlackbox::generatedArtifactAsInputToDynamicRule() QVERIFY2(!m_qbsStdout.contains("generating"), m_qbsStdout.constData()); } +void TestBlackbox::groupLocationWarning() +{ + QDir::setCurrent(testDataDir + "/group-location-warning"); + QCOMPARE(runQbs(QStringList() << "-f" << "group-location-warning.qbs"), 0); + QCOMPARE(m_qbsStderr.count("base directory"), 4); + QCOMPARE(m_qbsStderr.count("ParentInOtherDir.qbs"), 1); + QCOMPARE(m_qbsStderr.count("AGroupInOtherDir.qbs"), 1); + QCOMPARE(m_qbsStderr.count("gm.qbs"), 1); + QCOMPARE(m_qbsStderr.count("AndAnotherGroupInOtherDir.qbs"), 1); +} + static bool haveWiX(const Profile &profile) { if (profile.value("wix.toolchainInstallPath").isValid() && diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 019fd1aae..b8d93b5cf 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -80,6 +80,7 @@ private slots: void fileDependencies(); void frameworkStructure(); void generatedArtifactAsInputToDynamicRule(); + void groupLocationWarning(); void groupsInModules(); void iconset(); void iconsetApp(); |