aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-06-03 10:32:42 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-06-12 09:14:31 +0000
commit1d2af6b4cc5e67498a2c26645186eb3ea7e45093 (patch)
treee6fb82c73211b8259092544e6e215c52dcaac530 /src
parente115e9b9702170637444b50888260b095ccf8edc (diff)
clang-tidy: Consider context when encountering duplicate files
Prefer source files from contexts where we know that they actually get built and thus should have includes and compiler flags properly set up. Also fix the qmake and qbs project managers to not mislabel any non- application products as libraries. Fixes: QTCREATORBUG-23394 Change-Id: I0d122c7b58e12d14d68a1ca7337df83074299cd7 Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/clangtools/clangtool.cpp11
-rw-r--r--src/plugins/qbsprojectmanager/qbsproject.cpp14
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeproject.cpp16
3 files changed, 33 insertions, 8 deletions
diff --git a/src/plugins/clangtools/clangtool.cpp b/src/plugins/clangtools/clangtool.cpp
index 6cc636dd87..bbebc3560f 100644
--- a/src/plugins/clangtools/clangtool.cpp
+++ b/src/plugins/clangtools/clangtool.cpp
@@ -351,7 +351,16 @@ static FileInfos sortedFileInfos(const QVector<CppTools::ProjectPart::Ptr> &proj
}
}
- Utils::sort(fileInfos, &FileInfo::file);
+ Utils::sort(fileInfos, [](const FileInfo &fi1, const FileInfo &fi2) {
+ if (fi1.file == fi2.file) {
+ // If the same file appears more than once, prefer contexts where the file is
+ // built as part of an application or library to those where it may not be,
+ // e.g. because it is just listed as some sort of resource.
+ return fi1.projectPart->buildTargetType != BuildTargetType::Unknown
+ && fi2.projectPart->buildTargetType == BuildTargetType::Unknown;
+ }
+ return fi1.file < fi2.file;
+ });
fileInfos.erase(std::unique(fileInfos.begin(), fileInfos.end()), fileInfos.end());
return fileInfos;
diff --git a/src/plugins/qbsprojectmanager/qbsproject.cpp b/src/plugins/qbsprojectmanager/qbsproject.cpp
index 4e46e43c68..db8404f178 100644
--- a/src/plugins/qbsprojectmanager/qbsproject.cpp
+++ b/src/plugins/qbsprojectmanager/qbsproject.cpp
@@ -916,9 +916,17 @@ static RawProjectParts generateProjectParts(
location.value("line").toInt(),
location.value("column").toInt());
rpp.setBuildSystemTarget(QbsProductNode::getBuildKey(prd));
- rpp.setBuildTargetType(prd.value("is-runnable").toBool()
- ? BuildTargetType::Executable
- : BuildTargetType::Library);
+ if (prd.value("is-runnable").toBool()) {
+ rpp.setBuildTargetType(BuildTargetType::Executable);
+ } else {
+ const QJsonArray pType = prd.value("type").toArray();
+ if (pType.contains("staticlibrary") || pType.contains("dynamiclibrary")
+ || pType.contains("loadablemodule")) {
+ rpp.setBuildTargetType(BuildTargetType::Library);
+ } else {
+ rpp.setBuildTargetType(BuildTargetType::Unknown);
+ }
+ }
rpp.setSelectedForBuilding(grp.value("is-enabled").toBool());
QHash<QString, QJsonObject> filePathToSourceArtifact;
diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
index 90eeeb8f9b..8afb8c33b5 100644
--- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
@@ -290,10 +290,18 @@ void QmakeBuildSystem::updateCppCodeModel()
rpp.setDisplayName(pro->displayName());
rpp.setProjectFileLocation(pro->filePath().toString());
rpp.setBuildSystemTarget(pro->filePath().toString());
- const bool isExecutable = pro->projectType() == ProjectType::ApplicationTemplate;
- rpp.setBuildTargetType(isExecutable ? ProjectExplorer::BuildTargetType::Executable
- : ProjectExplorer::BuildTargetType::Library);
-
+ switch (pro->projectType()) {
+ case ProjectType::ApplicationTemplate:
+ rpp.setBuildTargetType(BuildTargetType::Executable);
+ break;
+ case ProjectType::SharedLibraryTemplate:
+ case ProjectType::StaticLibraryTemplate:
+ rpp.setBuildTargetType(BuildTargetType::Library);
+ break;
+ default:
+ rpp.setBuildTargetType(BuildTargetType::Unknown);
+ break;
+ }
rpp.setFlagsForCxx({kitInfo.cxxToolChain, pro->variableValue(Variable::CppFlags)});
rpp.setFlagsForC({kitInfo.cToolChain, pro->variableValue(Variable::CFlags)});
rpp.setMacros(ProjectExplorer::Macro::toMacros(pro->cxxDefines()));