aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2018-12-11 15:59:24 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2018-12-13 13:36:22 +0000
commit7b5349d182bcb4c9d7a3d1501768b91c9fa93fe9 (patch)
tree7625e9568275056dccac058b283871296366e132
parent85cf0b14b7c07334989f74edd1902c3fe200dda8 (diff)
Fix bogus error about duplicate source files
There is no conflict if the same file is pulled in both as a target artifact of a module and a normal source file. Fixes: QBS-1416 Change-Id: Ic7467af5a8728ebb1540381c845ffc0f40e06a9c Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r--src/lib/corelib/language/projectresolver.cpp6
-rw-r--r--src/lib/corelib/language/projectresolver.h3
-rw-r--r--tests/auto/language/testdata/file-in-product-and-module.qbs9
-rw-r--r--tests/auto/language/testdata/modules/module_with_file/module-with-file.qbs14
-rw-r--r--tests/auto/language/tst_language.cpp48
-rw-r--r--tests/auto/language/tst_language.h2
6 files changed, 78 insertions, 4 deletions
diff --git a/src/lib/corelib/language/projectresolver.cpp b/src/lib/corelib/language/projectresolver.cpp
index 59b4efc34..cf0e6b706 100644
--- a/src/lib/corelib/language/projectresolver.cpp
+++ b/src/lib/corelib/language/projectresolver.cpp
@@ -99,7 +99,7 @@ struct ProjectResolver::ProductContext
Item *item;
typedef std::pair<ArtifactPropertiesPtr, CodeLocation> ArtifactPropertiesInfo;
QHash<QStringList, ArtifactPropertiesInfo> artifactPropertiesPerFilter;
- QHash<QString, CodeLocation> sourceArtifactLocations;
+ ProjectResolver::FileLocations sourceArtifactLocations;
GroupConstPtr currentGroup;
};
@@ -578,7 +578,7 @@ void ProjectResolver::gatherProductTypes(ResolvedProduct *product, Item *item)
SourceArtifactPtr ProjectResolver::createSourceArtifact(const ResolvedProductPtr &rproduct,
const QString &fileName, const GroupPtr &group, bool wildcard,
- const CodeLocation &filesLocation, QHash<QString, CodeLocation> *fileLocations,
+ const CodeLocation &filesLocation, FileLocations *fileLocations,
ErrorInfo *errorInfo)
{
const QString &baseDir = FileInfo::path(group->location.filePath());
@@ -590,7 +590,7 @@ SourceArtifactPtr ProjectResolver::createSourceArtifact(const ResolvedProductPtr
return SourceArtifactPtr();
}
if (group->enabled && fileLocations) {
- CodeLocation &loc = (*fileLocations)[absFilePath];
+ CodeLocation &loc = (*fileLocations)[std::make_pair(group->targetOfModule, absFilePath)];
if (loc.isValid()) {
if (errorInfo) {
errorInfo->append(Tr::tr("Duplicate source file '%1'.").arg(absFilePath));
diff --git a/src/lib/corelib/language/projectresolver.h b/src/lib/corelib/language/projectresolver.h
index 660bf6259..e81034b5a 100644
--- a/src/lib/corelib/language/projectresolver.h
+++ b/src/lib/corelib/language/projectresolver.h
@@ -76,10 +76,11 @@ public:
static void applyFileTaggers(const SourceArtifactPtr &artifact,
const ResolvedProductConstPtr &product);
+ using FileLocations = QHash<std::pair<QString, QString>, CodeLocation>;
static SourceArtifactPtr createSourceArtifact(const ResolvedProductPtr &rproduct,
const QString &fileName, const GroupPtr &group, bool wildcard,
const CodeLocation &filesLocation = CodeLocation(),
- QHash<QString, CodeLocation> *fileLocations = nullptr, ErrorInfo *errorInfo = nullptr);
+ FileLocations *fileLocations = nullptr, ErrorInfo *errorInfo = nullptr);
private:
struct ProjectContext;
diff --git a/tests/auto/language/testdata/file-in-product-and-module.qbs b/tests/auto/language/testdata/file-in-product-and-module.qbs
new file mode 100644
index 000000000..1cb2fa866
--- /dev/null
+++ b/tests/auto/language/testdata/file-in-product-and-module.qbs
@@ -0,0 +1,9 @@
+Product {
+ name: "p"
+ Depends { name: "module_with_file" }
+ property bool addFileToProduct
+ Group {
+ files: "zort"
+ condition: addFileToProduct
+ }
+}
diff --git a/tests/auto/language/testdata/modules/module_with_file/module-with-file.qbs b/tests/auto/language/testdata/modules/module_with_file/module-with-file.qbs
new file mode 100644
index 000000000..ded81e046
--- /dev/null
+++ b/tests/auto/language/testdata/modules/module_with_file/module-with-file.qbs
@@ -0,0 +1,14 @@
+Module {
+ property bool file1IsTarget
+ property bool file2IsTarget
+ Group {
+ prefix: product.sourceDirectory + '/'
+ files: "zort"
+ filesAreTargets: product.module_with_file.file1IsTarget
+ }
+ Group {
+ prefix: product.sourceDirectory + '/'
+ files: "zort"
+ filesAreTargets: product.module_with_file.file2IsTarget
+ }
+}
diff --git a/tests/auto/language/tst_language.cpp b/tests/auto/language/tst_language.cpp
index ab5aaf759..fc16ca582 100644
--- a/tests/auto/language/tst_language.cpp
+++ b/tests/auto/language/tst_language.cpp
@@ -1100,6 +1100,54 @@ void TestLanguage::fileContextProperties()
QCOMPARE(exceptionCaught, false);
}
+void TestLanguage::fileInProductAndModule_data()
+{
+ QTest::addColumn<bool>("file1IsTarget");
+ QTest::addColumn<bool>("file2IsTarget");
+ QTest::addColumn<bool>("addFileToProduct");
+ QTest::addColumn<bool>("successExpected");
+ QTest::newRow("file occurs twice in module as non-target") << false << false << false << false;
+ QTest::newRow("file occurs twice in module as non-target, and in product as well")
+ << false << false << true << false;
+ QTest::newRow("file occurs in module as non-target and target")
+ << false << true << false << true;
+ QTest::newRow("file occurs in module as non-target and target, and in product as well")
+ << false << true << true << false;
+ QTest::newRow("file occurs in module as target and non-target")
+ << true << false << false << true;
+ QTest::newRow("file occurs in module as target and non-target, and in product as well")
+ << true << false << true << false;
+ QTest::newRow("file occurs twice in module as target") << true << true << false << false;
+ QTest::newRow("file occurs twice in module as target, and in product as well")
+ << true << true << true << false;
+}
+
+void TestLanguage::fileInProductAndModule()
+{
+ bool exceptionCaught = false;
+ QFETCH(bool, file1IsTarget);
+ QFETCH(bool, file2IsTarget);
+ QFETCH(bool, addFileToProduct);
+ QFETCH(bool, successExpected);
+ try {
+ SetupProjectParameters params = defaultParameters;
+ params.setProjectFilePath(testProject("file-in-product-and-module.qbs"));
+ params.setOverriddenValues(QVariantMap{
+ std::make_pair("modules.module_with_file.file1IsTarget", file1IsTarget),
+ std::make_pair("modules.module_with_file.file2IsTarget", file2IsTarget),
+ std::make_pair("products.p.addFileToProduct", addFileToProduct),
+ });
+ project = loader->loadProject(params);
+ QVERIFY(!!project);
+ QHash<QString, ResolvedProductPtr> products = productsFromProject(project);
+ QCOMPARE(products.size(), 1);
+ } catch (const ErrorInfo &e) {
+ exceptionCaught = true;
+ QVERIFY2(e.toString().contains("Duplicate"), qPrintable(e.toString()));
+ }
+ QCOMPARE(exceptionCaught, !successExpected);
+}
+
void TestLanguage::getNativeSetting()
{
bool exceptionCaught = false;
diff --git a/tests/auto/language/tst_language.h b/tests/auto/language/tst_language.h
index 660c1b9b6..b2d242bfb 100644
--- a/tests/auto/language/tst_language.h
+++ b/tests/auto/language/tst_language.h
@@ -103,6 +103,8 @@ private slots:
void erroneousFiles();
void exports();
void fileContextProperties();
+ void fileInProductAndModule_data();
+ void fileInProductAndModule();
void fileTags_data();
void fileTags();
void groupConditions_data();