2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2017 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2017-02-06 16:59:53 +01:00
|
|
|
|
|
|
|
|
#include "cppprojectinfogenerator.h"
|
|
|
|
|
|
2023-01-11 20:43:10 +01:00
|
|
|
#include "cppeditortr.h"
|
2017-02-06 16:59:53 +01:00
|
|
|
#include "cppprojectfilecategorizer.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/headerpath.h>
|
2018-08-13 11:15:27 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2020-01-30 13:40:16 +01:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2018-09-27 10:18:44 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2020-01-30 13:40:16 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
2020-09-07 13:56:12 +02:00
|
|
|
#include <set>
|
|
|
|
|
|
2020-01-30 13:40:16 +01:00
|
|
|
using namespace ProjectExplorer;
|
2021-09-02 13:31:08 +02:00
|
|
|
using namespace Utils;
|
2020-01-30 13:40:16 +01:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
namespace CppEditor::Internal {
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2021-08-20 11:21:06 +02:00
|
|
|
ProjectInfoGenerator::ProjectInfoGenerator(
|
|
|
|
|
const QFutureInterface<ProjectInfo::ConstPtr> &futureInterface,
|
|
|
|
|
const ProjectUpdateInfo &projectUpdateInfo)
|
2017-02-06 16:59:53 +01:00
|
|
|
: m_futureInterface(futureInterface)
|
|
|
|
|
, m_projectUpdateInfo(projectUpdateInfo)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 11:21:06 +02:00
|
|
|
ProjectInfo::ConstPtr ProjectInfoGenerator::generate()
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
2021-08-20 11:21:06 +02:00
|
|
|
QVector<ProjectPart::ConstPtr> projectParts;
|
2020-01-30 13:40:16 +01:00
|
|
|
for (const RawProjectPart &rpp : m_projectUpdateInfo.rawProjectParts) {
|
2017-02-06 16:59:53 +01:00
|
|
|
if (m_futureInterface.isCanceled())
|
2021-05-07 16:10:07 +02:00
|
|
|
return {};
|
2021-08-20 11:21:06 +02:00
|
|
|
for (const ProjectPart::ConstPtr &part : createProjectParts(
|
|
|
|
|
rpp, m_projectUpdateInfo.projectFilePath)) {
|
2021-05-07 16:10:07 +02:00
|
|
|
projectParts << part;
|
2021-08-20 11:21:06 +02:00
|
|
|
}
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
2021-05-07 16:10:07 +02:00
|
|
|
const auto projectInfo = ProjectInfo::create(m_projectUpdateInfo, projectParts);
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2020-01-30 13:40:16 +01:00
|
|
|
static const auto showWarning = [](const QString &message) {
|
|
|
|
|
QTimer::singleShot(0, TaskHub::instance(), [message] {
|
|
|
|
|
TaskHub::addTask(BuildSystemTask(Task::Warning, message));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
if (m_cToolchainMissing) {
|
2023-01-11 20:43:10 +01:00
|
|
|
showWarning(Tr::tr(
|
2020-01-30 13:40:16 +01:00
|
|
|
"The project contains C source files, but the currently active kit "
|
|
|
|
|
"has no C compiler. The code model will not be fully functional."));
|
|
|
|
|
}
|
|
|
|
|
if (m_cxxToolchainMissing) {
|
2023-01-11 20:43:10 +01:00
|
|
|
showWarning(Tr::tr(
|
2020-01-30 13:40:16 +01:00
|
|
|
"The project contains C++ source files, but the currently active kit "
|
|
|
|
|
"has no C++ compiler. The code model will not be fully functional."));
|
|
|
|
|
}
|
2017-10-27 13:31:11 +02:00
|
|
|
return projectInfo;
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-20 11:21:06 +02:00
|
|
|
const QVector<ProjectPart::ConstPtr> ProjectInfoGenerator::createProjectParts(
|
2021-09-02 13:31:08 +02:00
|
|
|
const RawProjectPart &rawProjectPart, const FilePath &projectFilePath)
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
2021-08-20 11:21:06 +02:00
|
|
|
QVector<ProjectPart::ConstPtr> result;
|
2017-02-06 16:59:53 +01:00
|
|
|
ProjectFileCategorizer cat(rawProjectPart.displayName,
|
|
|
|
|
rawProjectPart.files,
|
2022-06-16 20:20:54 +02:00
|
|
|
rawProjectPart.fileIsActive,
|
|
|
|
|
rawProjectPart.getMimeType);
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2019-05-09 10:24:57 +02:00
|
|
|
if (!cat.hasParts())
|
|
|
|
|
return result;
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2021-05-07 16:10:07 +02:00
|
|
|
if (m_projectUpdateInfo.cxxToolChainInfo.isValid()) {
|
2017-02-06 16:59:53 +01:00
|
|
|
if (cat.hasCxxSources()) {
|
2021-05-07 16:10:07 +02:00
|
|
|
result << createProjectPart(projectFilePath,
|
|
|
|
|
rawProjectPart,
|
2017-10-27 13:31:11 +02:00
|
|
|
cat.cxxSources(),
|
|
|
|
|
cat.partName("C++"),
|
2018-10-08 10:54:27 +02:00
|
|
|
Language::Cxx,
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtension::None);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
if (cat.hasObjcxxSources()) {
|
2021-05-07 16:10:07 +02:00
|
|
|
result << createProjectPart(projectFilePath,
|
|
|
|
|
rawProjectPart,
|
2017-10-27 13:31:11 +02:00
|
|
|
cat.objcxxSources(),
|
|
|
|
|
cat.partName("Obj-C++"),
|
2018-10-08 10:54:27 +02:00
|
|
|
Language::Cxx,
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtension::ObjectiveC);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
2020-01-30 13:40:16 +01:00
|
|
|
} else if (cat.hasCxxSources() || cat.hasObjcxxSources()) {
|
|
|
|
|
m_cxxToolchainMissing = true;
|
2019-05-09 10:24:57 +02:00
|
|
|
}
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2021-05-07 16:10:07 +02:00
|
|
|
if (m_projectUpdateInfo.cToolChainInfo.isValid()) {
|
2017-02-06 16:59:53 +01:00
|
|
|
if (cat.hasCSources()) {
|
2021-05-07 16:10:07 +02:00
|
|
|
result << createProjectPart(projectFilePath,
|
|
|
|
|
rawProjectPart,
|
2017-10-27 13:31:11 +02:00
|
|
|
cat.cSources(),
|
|
|
|
|
cat.partName("C"),
|
2018-09-27 10:18:44 +02:00
|
|
|
Language::C,
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtension::None);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cat.hasObjcSources()) {
|
2021-05-07 16:10:07 +02:00
|
|
|
result << createProjectPart(projectFilePath,
|
|
|
|
|
rawProjectPart,
|
2017-10-27 13:31:11 +02:00
|
|
|
cat.objcSources(),
|
|
|
|
|
cat.partName("Obj-C"),
|
2018-09-27 10:18:44 +02:00
|
|
|
Language::C,
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtension::ObjectiveC);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
2020-01-30 13:40:16 +01:00
|
|
|
} else if (cat.hasCSources() || cat.hasObjcSources()) {
|
|
|
|
|
m_cToolchainMissing = true;
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
2019-05-09 10:24:57 +02:00
|
|
|
|
2017-10-27 13:31:11 +02:00
|
|
|
return result;
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-20 11:21:06 +02:00
|
|
|
ProjectPart::ConstPtr ProjectInfoGenerator::createProjectPart(
|
2021-09-02 13:31:08 +02:00
|
|
|
const FilePath &projectFilePath,
|
2021-05-07 16:10:07 +02:00
|
|
|
const RawProjectPart &rawProjectPart,
|
|
|
|
|
const ProjectFiles &projectFiles,
|
|
|
|
|
const QString &partName,
|
|
|
|
|
Language language,
|
2021-09-02 13:31:08 +02:00
|
|
|
LanguageExtensions languageExtensions)
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
2020-01-30 13:40:16 +01:00
|
|
|
RawProjectPartFlags flags;
|
|
|
|
|
ToolChainInfo tcInfo;
|
2018-09-27 10:18:44 +02:00
|
|
|
if (language == Language::C) {
|
2017-02-06 16:59:53 +01:00
|
|
|
flags = rawProjectPart.flagsForC;
|
|
|
|
|
tcInfo = m_projectUpdateInfo.cToolChainInfo;
|
|
|
|
|
}
|
|
|
|
|
// Use Cxx toolchain for C projects without C compiler in kit and for C++ code
|
|
|
|
|
if (!tcInfo.isValid()) {
|
|
|
|
|
flags = rawProjectPart.flagsForCxx;
|
|
|
|
|
tcInfo = m_projectUpdateInfo.cxxToolChainInfo;
|
|
|
|
|
}
|
2018-10-08 11:04:03 +02:00
|
|
|
|
2022-10-07 18:00:36 +02:00
|
|
|
QString explicitTarget;
|
|
|
|
|
if (!tcInfo.targetTripleIsAuthoritative) {
|
|
|
|
|
for (int i = 0; i < flags.commandLineFlags.size(); ++i) {
|
|
|
|
|
const QString &flag = flags.commandLineFlags.at(i);
|
|
|
|
|
if (flag == "-target") {
|
|
|
|
|
if (i + 1 < flags.commandLineFlags.size())
|
|
|
|
|
explicitTarget = flags.commandLineFlags.at(i + 1);
|
|
|
|
|
break;
|
|
|
|
|
} else if (flag.startsWith("--target=")) {
|
|
|
|
|
explicitTarget = flag.mid(9);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!explicitTarget.isEmpty()) {
|
|
|
|
|
tcInfo.targetTriple = explicitTarget;
|
|
|
|
|
tcInfo.targetTripleIsAuthoritative = true;
|
|
|
|
|
if (const Abi abi = Abi::fromString(tcInfo.targetTriple); abi.isValid())
|
|
|
|
|
tcInfo.abi = abi;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 16:10:07 +02:00
|
|
|
return ProjectPart::create(projectFilePath, rawProjectPart, partName, projectFiles,
|
|
|
|
|
language, languageExtensions, flags, tcInfo);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
} // namespace CppEditor::Internal
|