forked from qt-creator/qt-creator
CppTools: Give early warning if kit has no compilers
We keep getting bug reports from users who forgot to set a compiler in their kit and then get confused by (misleading) warnings from the code model. Improve the situation by detecting the condition that a C/C++ project's current kit does not have a C/C++ compiler and showing a warning for that in the issues pane. Task-number: QTCREATORBUG-23247 Change-Id: I10164e85ad595f3a386340e7813d1f3e40fbecb5 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -29,15 +29,20 @@
|
|||||||
|
|
||||||
#include <projectexplorer/headerpath.h>
|
#include <projectexplorer/headerpath.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
|
#include <projectexplorer/taskhub.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
ProjectInfoGenerator::ProjectInfoGenerator(
|
ProjectInfoGenerator::ProjectInfoGenerator(
|
||||||
const QFutureInterface<void> &futureInterface,
|
const QFutureInterface<void> &futureInterface,
|
||||||
const ProjectExplorer::ProjectUpdateInfo &projectUpdateInfo)
|
const ProjectUpdateInfo &projectUpdateInfo)
|
||||||
: m_futureInterface(futureInterface)
|
: m_futureInterface(futureInterface)
|
||||||
, m_projectUpdateInfo(projectUpdateInfo)
|
, m_projectUpdateInfo(projectUpdateInfo)
|
||||||
{
|
{
|
||||||
@@ -47,7 +52,7 @@ ProjectInfo ProjectInfoGenerator::generate()
|
|||||||
{
|
{
|
||||||
ProjectInfo projectInfo(m_projectUpdateInfo.project);
|
ProjectInfo projectInfo(m_projectUpdateInfo.project);
|
||||||
|
|
||||||
for (const ProjectExplorer::RawProjectPart &rpp : m_projectUpdateInfo.rawProjectParts) {
|
for (const RawProjectPart &rpp : m_projectUpdateInfo.rawProjectParts) {
|
||||||
if (m_futureInterface.isCanceled())
|
if (m_futureInterface.isCanceled())
|
||||||
return ProjectInfo();
|
return ProjectInfo();
|
||||||
|
|
||||||
@@ -55,11 +60,26 @@ ProjectInfo ProjectInfoGenerator::generate()
|
|||||||
projectInfo.appendProjectPart(part);
|
projectInfo.appendProjectPart(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const auto showWarning = [](const QString &message) {
|
||||||
|
QTimer::singleShot(0, TaskHub::instance(), [message] {
|
||||||
|
TaskHub::addTask(BuildSystemTask(Task::Warning, message));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (m_cToolchainMissing) {
|
||||||
|
showWarning(QCoreApplication::translate("CppTools",
|
||||||
|
"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) {
|
||||||
|
showWarning(QCoreApplication::translate("CppTools",
|
||||||
|
"The project contains C++ source files, but the currently active kit "
|
||||||
|
"has no C++ compiler. The code model will not be fully functional."));
|
||||||
|
}
|
||||||
return projectInfo;
|
return projectInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ProjectPart::Ptr projectPartFromRawProjectPart(
|
static ProjectPart::Ptr projectPartFromRawProjectPart(
|
||||||
const ProjectExplorer::RawProjectPart &rawProjectPart, ProjectExplorer::Project *project)
|
const RawProjectPart &rawProjectPart, Project *project)
|
||||||
{
|
{
|
||||||
ProjectPart::Ptr part(new ProjectPart);
|
ProjectPart::Ptr part(new ProjectPart);
|
||||||
part->project = project;
|
part->project = project;
|
||||||
@@ -73,7 +93,7 @@ static ProjectPart::Ptr projectPartFromRawProjectPart(
|
|||||||
part->qtVersion = rawProjectPart.qtVersion;
|
part->qtVersion = rawProjectPart.qtVersion;
|
||||||
part->projectMacros = rawProjectPart.projectMacros;
|
part->projectMacros = rawProjectPart.projectMacros;
|
||||||
if (!part->projectConfigFile.isEmpty())
|
if (!part->projectConfigFile.isEmpty())
|
||||||
part->projectMacros += ProjectExplorer::Macro::toMacros(ProjectPart::readProjectConfigFile(part));
|
part->projectMacros += Macro::toMacros(ProjectPart::readProjectConfigFile(part));
|
||||||
part->headerPaths = rawProjectPart.headerPaths;
|
part->headerPaths = rawProjectPart.headerPaths;
|
||||||
part->precompiledHeaders = rawProjectPart.precompiledHeaders;
|
part->precompiledHeaders = rawProjectPart.precompiledHeaders;
|
||||||
part->selectedForBuilding = rawProjectPart.selectedForBuilding;
|
part->selectedForBuilding = rawProjectPart.selectedForBuilding;
|
||||||
@@ -82,7 +102,7 @@ static ProjectPart::Ptr projectPartFromRawProjectPart(
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts(
|
QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts(
|
||||||
const ProjectExplorer::RawProjectPart &rawProjectPart)
|
const RawProjectPart &rawProjectPart)
|
||||||
{
|
{
|
||||||
using Utils::LanguageExtension;
|
using Utils::LanguageExtension;
|
||||||
|
|
||||||
@@ -114,6 +134,8 @@ QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts(
|
|||||||
Language::Cxx,
|
Language::Cxx,
|
||||||
LanguageExtension::ObjectiveC);
|
LanguageExtension::ObjectiveC);
|
||||||
}
|
}
|
||||||
|
} else if (cat.hasCxxSources() || cat.hasObjcxxSources()) {
|
||||||
|
m_cxxToolchainMissing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_projectUpdateInfo.cToolChain) {
|
if (m_projectUpdateInfo.cToolChain) {
|
||||||
@@ -134,21 +156,23 @@ QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts(
|
|||||||
Language::C,
|
Language::C,
|
||||||
LanguageExtension::ObjectiveC);
|
LanguageExtension::ObjectiveC);
|
||||||
}
|
}
|
||||||
|
} else if (cat.hasCSources() || cat.hasObjcSources()) {
|
||||||
|
m_cToolchainMissing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectPart::Ptr ProjectInfoGenerator::createProjectPart(
|
ProjectPart::Ptr ProjectInfoGenerator::createProjectPart(
|
||||||
const ProjectExplorer::RawProjectPart &rawProjectPart,
|
const RawProjectPart &rawProjectPart,
|
||||||
const ProjectPart::Ptr &templateProjectPart,
|
const ProjectPart::Ptr &templateProjectPart,
|
||||||
const ProjectFiles &projectFiles,
|
const ProjectFiles &projectFiles,
|
||||||
const QString &partName,
|
const QString &partName,
|
||||||
Language language,
|
Language language,
|
||||||
Utils::LanguageExtensions languageExtensions)
|
Utils::LanguageExtensions languageExtensions)
|
||||||
{
|
{
|
||||||
ProjectExplorer::RawProjectPartFlags flags;
|
RawProjectPartFlags flags;
|
||||||
ProjectExplorer::ToolChainInfo tcInfo;
|
ToolChainInfo tcInfo;
|
||||||
if (language == Language::C) {
|
if (language == Language::C) {
|
||||||
flags = rawProjectPart.flagsForC;
|
flags = rawProjectPart.flagsForC;
|
||||||
tcInfo = m_projectUpdateInfo.cToolChainInfo;
|
tcInfo = m_projectUpdateInfo.cToolChainInfo;
|
||||||
@@ -158,7 +182,6 @@ ProjectPart::Ptr ProjectInfoGenerator::createProjectPart(
|
|||||||
flags = rawProjectPart.flagsForCxx;
|
flags = rawProjectPart.flagsForCxx;
|
||||||
tcInfo = m_projectUpdateInfo.cxxToolChainInfo;
|
tcInfo = m_projectUpdateInfo.cxxToolChainInfo;
|
||||||
}
|
}
|
||||||
// TODO: If no toolchain is set, show a warning
|
|
||||||
|
|
||||||
ProjectPart::Ptr part(templateProjectPart->copy());
|
ProjectPart::Ptr part(templateProjectPart->copy());
|
||||||
part->displayName = partName;
|
part->displayName = partName;
|
||||||
@@ -189,14 +212,14 @@ ProjectPart::Ptr ProjectInfoGenerator::createProjectPart(
|
|||||||
|
|
||||||
// Header paths
|
// Header paths
|
||||||
if (tcInfo.headerPathsRunner) {
|
if (tcInfo.headerPathsRunner) {
|
||||||
const ProjectExplorer::HeaderPaths builtInHeaderPaths
|
const HeaderPaths builtInHeaderPaths
|
||||||
= tcInfo.headerPathsRunner(flags.commandLineFlags,
|
= tcInfo.headerPathsRunner(flags.commandLineFlags,
|
||||||
tcInfo.sysRootPath,
|
tcInfo.sysRootPath,
|
||||||
tcInfo.targetTriple);
|
tcInfo.targetTriple);
|
||||||
|
|
||||||
ProjectExplorer::HeaderPaths &headerPaths = part->headerPaths;
|
HeaderPaths &headerPaths = part->headerPaths;
|
||||||
for (const ProjectExplorer::HeaderPath &header : builtInHeaderPaths) {
|
for (const HeaderPath &header : builtInHeaderPaths) {
|
||||||
const ProjectExplorer::HeaderPath headerPath{header.path, header.type};
|
const HeaderPath headerPath{header.path, header.type};
|
||||||
if (!headerPaths.contains(headerPath))
|
if (!headerPaths.contains(headerPath))
|
||||||
headerPaths.push_back(headerPath);
|
headerPaths.push_back(headerPath);
|
||||||
}
|
}
|
||||||
|
@@ -54,6 +54,8 @@ private:
|
|||||||
private:
|
private:
|
||||||
const QFutureInterface<void> m_futureInterface;
|
const QFutureInterface<void> m_futureInterface;
|
||||||
const ProjectExplorer::ProjectUpdateInfo &m_projectUpdateInfo;
|
const ProjectExplorer::ProjectUpdateInfo &m_projectUpdateInfo;
|
||||||
|
bool m_cToolchainMissing = false;
|
||||||
|
bool m_cxxToolchainMissing = false;
|
||||||
};
|
};
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
Reference in New Issue
Block a user