CppTools: Parse non-project sources with default kit

This makes more sense than using the clang defaults.

Task-number: QTCREATORBUG-25562
Change-Id: I796d29bb4e81e5e257efea998dcab037efd8a717
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2021-05-06 12:56:21 +02:00
parent 448446bd7e
commit 9c3420120e
4 changed files with 57 additions and 43 deletions

View File

@@ -61,6 +61,8 @@
#include <cplusplus/ASTPath.h>
#include <cplusplus/TypeOfExpression.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectmacro.h>
@@ -90,6 +92,7 @@ static const bool DumpProjectInfo = qgetenv("QTC_DUMP_PROJECT_INFO") == "1";
using namespace CppTools;
using namespace CppTools::Internal;
using namespace CPlusPlus;
using namespace ProjectExplorer;
#ifdef QTCREATOR_WITH_DUMP_AST
@@ -1276,6 +1279,19 @@ ProjectPart::Ptr CppModelManager::fallbackProjectPart()
Utils::LanguageExtension::ObjectiveC);
part->qtVersion = Utils::QtVersion::Qt5;
// TODO: Use different fallback toolchain for different kinds of files
const auto * const defaultKit = KitManager::defaultKit();
const ToolChain * const defaultTc = ToolChainKitAspect::cxxToolChain(defaultKit);
if (defaultKit && defaultTc) {
Utils::FilePath sysroot = SysRootKitAspect::sysRoot(defaultKit);
if (sysroot.isEmpty())
sysroot = Utils::FilePath::fromString(defaultTc->sysRoot());
Utils::Environment env = Utils::Environment::systemEnvironment();
defaultKit->addToEnvironment(env);
ToolChainInfo tcInfo(defaultTc, sysroot.toString(), env);
part->setupToolchainProperties(tcInfo, {});
}
part->updateLanguageFeatures();
return part;

View File

@@ -196,51 +196,10 @@ ProjectPart::Ptr ProjectInfoGenerator::createProjectPart(
ProjectPart::Ptr part(templateProjectPart->copy());
part->displayName = partName;
part->files = projectFiles;
part->toolchainType = tcInfo.type;
part->isMsvc2015Toolchain = tcInfo.isMsvc2015ToolChain;
part->toolChainWordWidth = tcInfo.wordWidth == 64 ? ProjectPart::WordWidth64Bit
: ProjectPart::WordWidth32Bit;
part->toolChainInstallDir = tcInfo.installDir;
part->toolChainTargetTriple = tcInfo.targetTriple;
part->extraCodeModelFlags = tcInfo.extraCodeModelFlags;
part->compilerFlags = flags.commandLineFlags;
part->warningFlags = flags.warningFlags;
if (part->includedFiles.isEmpty()) {
// The project manager did not provide the included files, so take
// the ones we were able to detect from the toolchain's command line.
part->includedFiles = flags.includedFiles;
}
part->language = language;
part->languageExtensions = flags.languageExtensions;
// Toolchain macros and language version
if (tcInfo.macroInspectionRunner) {
auto macroInspectionReport = tcInfo.macroInspectionRunner(flags.commandLineFlags);
part->toolChainMacros = macroInspectionReport.macros;
part->languageVersion = macroInspectionReport.languageVersion;
// No compiler set in kit.
} else if (language == Language::C) {
part->languageVersion = Utils::LanguageVersion::LatestC;
} else {
part->languageVersion = Utils::LanguageVersion::LatestCxx;
}
// Header paths
if (tcInfo.headerPathsRunner) {
const HeaderPaths builtInHeaderPaths
= tcInfo.headerPathsRunner(flags.commandLineFlags,
tcInfo.sysRootPath,
tcInfo.targetTriple);
HeaderPaths &headerPaths = part->headerPaths;
for (const HeaderPath &header : builtInHeaderPaths) {
const HeaderPath headerPath{header.path, header.type};
if (!headerPaths.contains(headerPath))
headerPaths.push_back(headerPath);
}
}
part->languageExtensions |= languageExtensions;
part->languageExtensions = flags.languageExtensions | languageExtensions;
part->setupToolchainProperties(tcInfo, flags.commandLineFlags);
part->updateLanguageFeatures();
return part;

View File

@@ -31,6 +31,8 @@
#include <QDir>
#include <QTextStream>
using namespace ProjectExplorer;
namespace CppTools {
void ProjectPart::updateLanguageFeatures()
@@ -53,6 +55,41 @@ void ProjectPart::updateLanguageFeatures()
}
}
void ProjectPart::setupToolchainProperties(const ToolChainInfo &tcInfo, const QStringList &flags)
{
toolchainType = tcInfo.type;
isMsvc2015Toolchain = tcInfo.isMsvc2015ToolChain;
toolChainWordWidth = tcInfo.wordWidth == 64 ? ProjectPart::WordWidth64Bit
: ProjectPart::WordWidth32Bit;
toolChainInstallDir = tcInfo.installDir;
toolChainTargetTriple = tcInfo.targetTriple;
extraCodeModelFlags = tcInfo.extraCodeModelFlags;
compilerFlags = flags;
// Toolchain macros and language version
if (tcInfo.macroInspectionRunner) {
const auto macroInspectionReport = tcInfo.macroInspectionRunner(compilerFlags);
toolChainMacros = macroInspectionReport.macros;
languageVersion = macroInspectionReport.languageVersion;
// No compiler set in kit.
} else if (language == Utils::Language::C) {
languageVersion = Utils::LanguageVersion::LatestC;
} else {
languageVersion = Utils::LanguageVersion::LatestCxx;
}
// Header paths
if (tcInfo.headerPathsRunner) {
const HeaderPaths builtInHeaderPaths
= tcInfo.headerPathsRunner(compilerFlags, tcInfo.sysRootPath, tcInfo.targetTriple);
for (const HeaderPath &header : builtInHeaderPaths) {
const HeaderPath headerPath{header.path, header.type};
if (!headerPaths.contains(headerPath))
headerPaths.push_back(headerPath);
}
}
}
ProjectPart::Ptr ProjectPart::copy() const
{
return Ptr(new ProjectPart(*this));

View File

@@ -65,6 +65,8 @@ public:
Ptr copy() const;
void updateLanguageFeatures();
void setupToolchainProperties(const ProjectExplorer::ToolChainInfo &tcInfo,
const QStringList &flags);
static QByteArray readProjectConfigFile(const Ptr &projectPart);