2017-02-06 16:59:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cppprojectinfogenerator.h"
|
|
|
|
|
|
|
|
|
|
#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-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) {
|
2021-08-30 10:58:08 +02:00
|
|
|
showWarning(QCoreApplication::translate("CppEditor",
|
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) {
|
2021-08-30 10:58:08 +02:00
|
|
|
showWarning(QCoreApplication::translate("CppEditor",
|
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-05-07 16:10:07 +02:00
|
|
|
const RawProjectPart &rawProjectPart, const Utils::FilePath &projectFilePath)
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
2019-01-09 18:31:20 +01:00
|
|
|
using Utils::LanguageExtension;
|
2018-10-08 09:49:02 +02: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,
|
2019-08-28 12:23:37 +02:00
|
|
|
rawProjectPart.fileIsActive);
|
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-05-07 16:10:07 +02:00
|
|
|
const Utils::FilePath &projectFilePath,
|
|
|
|
|
const RawProjectPart &rawProjectPart,
|
|
|
|
|
const ProjectFiles &projectFiles,
|
|
|
|
|
const QString &partName,
|
|
|
|
|
Language language,
|
|
|
|
|
Utils::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
|
|
|
|
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
|