forked from qt-creator/qt-creator
ClangTools: Always use CompilerOptionsBuilder for clang tools
We do not ship clang-cl anymore which makes it impossible to run clang with MSVC options. Secondly we used to we tweak compiler options quite a bit so why not to switch to CompilerOptionsBuilder totally? Change-Id: Id323cb554587afaea7d9aa530e947a45a03922d1 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -171,152 +171,6 @@ private:
|
||||
bool m_success = false;
|
||||
};
|
||||
|
||||
static void prependWordWidthArgumentIfNotIncluded(QStringList *arguments,
|
||||
ProjectPart::ToolChainWordWidth wordWidth)
|
||||
{
|
||||
QTC_ASSERT(arguments, return);
|
||||
|
||||
const QString m64Argument = QLatin1String("-m64");
|
||||
const QString m32Argument = QLatin1String("-m32");
|
||||
|
||||
const QString argument = wordWidth == ProjectPart::WordWidth64Bit ? m64Argument : m32Argument;
|
||||
if (!arguments->contains(argument))
|
||||
arguments->prepend(argument);
|
||||
|
||||
QTC_CHECK(!arguments->contains(m32Argument) || !arguments->contains(m64Argument));
|
||||
}
|
||||
|
||||
static void prependTargetTripleIfNotIncludedAndNotEmpty(QStringList *arguments,
|
||||
const QString &targetTriple)
|
||||
{
|
||||
QTC_ASSERT(arguments, return);
|
||||
|
||||
if (targetTriple.isEmpty())
|
||||
return;
|
||||
|
||||
const QString targetOption = QLatin1String("-target");
|
||||
|
||||
if (!arguments->contains(targetOption)) {
|
||||
arguments->prepend(targetTriple);
|
||||
arguments->prepend(targetOption);
|
||||
}
|
||||
}
|
||||
|
||||
// Removes (1) inputFile (2) -o <somePath>.
|
||||
QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStringList &arguments)
|
||||
{
|
||||
QStringList newArguments;
|
||||
|
||||
bool skip = false;
|
||||
foreach (const QString &argument, arguments) {
|
||||
if (skip) {
|
||||
skip = false;
|
||||
continue;
|
||||
} else if (argument == QLatin1String("-o")) {
|
||||
skip = true;
|
||||
continue;
|
||||
} else if (QDir::fromNativeSeparators(argument) == inputFile) {
|
||||
continue; // TODO: Let it in?
|
||||
}
|
||||
|
||||
newArguments << argument;
|
||||
}
|
||||
QTC_CHECK(skip == false);
|
||||
|
||||
return newArguments;
|
||||
}
|
||||
|
||||
static QStringList createMsCompatibilityVersionOption(const ProjectPart &projectPart)
|
||||
{
|
||||
CompilerOptionsBuilder optionsBuilder(projectPart);
|
||||
optionsBuilder.addMsvcCompatibilityVersion();
|
||||
const QStringList option = optionsBuilder.options();
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
static QStringList createOptionsToUndefineCppLanguageFeatureMacrosForMsvc2015(
|
||||
const ProjectPart &projectPart)
|
||||
{
|
||||
CompilerOptionsBuilder optionsBuilder(projectPart);
|
||||
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
return optionsBuilder.options();
|
||||
}
|
||||
|
||||
static QStringList createOptionsToUndefineClangVersionMacrosForMsvc(const ProjectPart &projectPart)
|
||||
{
|
||||
CompilerOptionsBuilder optionsBuilder(projectPart);
|
||||
optionsBuilder.undefineClangVersionMacrosForMsvc();
|
||||
|
||||
return optionsBuilder.options();
|
||||
}
|
||||
|
||||
static QStringList createHeaderPathsOptionsForClangOnMac(const ProjectPart &projectPart)
|
||||
{
|
||||
QStringList options;
|
||||
|
||||
if (Utils::HostOsInfo::isMacHost()
|
||||
&& projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID) {
|
||||
CompilerOptionsBuilder optionsBuilder(projectPart);
|
||||
optionsBuilder.addHeaderPathOptions();
|
||||
options = optionsBuilder.options();
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
static QStringList tweakedArguments(const ProjectPart &projectPart,
|
||||
const QString &filePath,
|
||||
const QStringList &arguments,
|
||||
const QString &targetTriple)
|
||||
{
|
||||
const bool isMsvc = projectPart.toolchainType
|
||||
== ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
||||
QStringList newArguments = inputAndOutputArgumentsRemoved(filePath, arguments);
|
||||
prependWordWidthArgumentIfNotIncluded(&newArguments, projectPart.toolChainWordWidth);
|
||||
if (!isMsvc)
|
||||
prependTargetTripleIfNotIncludedAndNotEmpty(&newArguments, targetTriple);
|
||||
newArguments.append(createHeaderPathsOptionsForClangOnMac(projectPart));
|
||||
newArguments.append(createMsCompatibilityVersionOption(projectPart));
|
||||
newArguments.append(createOptionsToUndefineClangVersionMacrosForMsvc(projectPart));
|
||||
newArguments.append(createOptionsToUndefineCppLanguageFeatureMacrosForMsvc2015(projectPart));
|
||||
|
||||
return newArguments;
|
||||
}
|
||||
|
||||
static AnalyzeUnits unitsToAnalyzeFromCompilerCallData(
|
||||
const QHash<QString, ProjectPart::Ptr> &callGroupToProjectPart,
|
||||
const ProjectInfo::CompilerCallData &compilerCallData,
|
||||
const QString &targetTriple)
|
||||
{
|
||||
qCDebug(LOG) << "Taking arguments for analyzing from CompilerCallData.";
|
||||
|
||||
AnalyzeUnits unitsToAnalyze;
|
||||
|
||||
foreach (const ProjectInfo::CompilerCallGroup &compilerCallGroup, compilerCallData) {
|
||||
const ProjectPart::Ptr projectPart
|
||||
= callGroupToProjectPart.value(compilerCallGroup.groupId);
|
||||
QTC_ASSERT(projectPart, continue);
|
||||
|
||||
QHashIterator<QString, QList<QStringList> > it(compilerCallGroup.callsPerSourceFile);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
const QString file = it.key();
|
||||
const QList<QStringList> compilerCalls = it.value();
|
||||
foreach (const QStringList &options, compilerCalls) {
|
||||
const QStringList arguments = tweakedArguments(*projectPart,
|
||||
file,
|
||||
options,
|
||||
targetTriple);
|
||||
unitsToAnalyze << AnalyzeUnit(file, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return unitsToAnalyze;
|
||||
}
|
||||
|
||||
static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QVector<ProjectPart::Ptr> projectParts,
|
||||
const QString &clangVersion,
|
||||
const QString &clangResourceDirectory)
|
||||
@@ -349,19 +203,6 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QVector<ProjectPart::Pt
|
||||
return unitsToAnalyze;
|
||||
}
|
||||
|
||||
static QHash<QString, ProjectPart::Ptr> generateCallGroupToProjectPartMapping(
|
||||
const QVector<ProjectPart::Ptr> &projectParts)
|
||||
{
|
||||
QHash<QString, ProjectPart::Ptr> mapping;
|
||||
|
||||
foreach (const ProjectPart::Ptr &projectPart, projectParts) {
|
||||
QTC_ASSERT(projectPart, continue);
|
||||
mapping[projectPart->callGroupId] = projectPart;
|
||||
}
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
static QString clangResourceDir(const QString &clangExecutable, const QString &clangVersion)
|
||||
{
|
||||
QDir llvmDir = QFileInfo(clangExecutable).dir();
|
||||
@@ -373,19 +214,9 @@ AnalyzeUnits ClangStaticAnalyzerToolRunner::sortedUnitsToAnalyze(const QString &
|
||||
{
|
||||
QTC_ASSERT(m_projectInfo.isValid(), return AnalyzeUnits());
|
||||
|
||||
AnalyzeUnits units;
|
||||
const ProjectInfo::CompilerCallData compilerCallData = m_projectInfo.compilerCallData();
|
||||
if (compilerCallData.isEmpty()) {
|
||||
const QString clangResourceDirectory = clangResourceDir(m_clangExecutable, clangVersion);
|
||||
units = unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(), clangVersion,
|
||||
AnalyzeUnits units = unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(), clangVersion,
|
||||
clangResourceDirectory);
|
||||
} else {
|
||||
const QHash<QString, ProjectPart::Ptr> callGroupToProjectPart
|
||||
= generateCallGroupToProjectPartMapping(m_projectInfo.projectParts());
|
||||
units = unitsToAnalyzeFromCompilerCallData(callGroupToProjectPart,
|
||||
compilerCallData,
|
||||
m_targetTriple);
|
||||
}
|
||||
|
||||
Utils::sort(units, &AnalyzeUnit::file);
|
||||
return units;
|
||||
|
@@ -1101,19 +1101,6 @@ QFuture<void> CppModelManager::updateProjectInfo(QFutureInterface<void> &futureI
|
||||
return indexingFuture;
|
||||
}
|
||||
|
||||
ProjectInfo CppModelManager::updateCompilerCallDataForProject(
|
||||
ProjectExplorer::Project *project,
|
||||
ProjectInfo::CompilerCallData &compilerCallData)
|
||||
{
|
||||
QMutexLocker locker(&d->m_projectMutex);
|
||||
|
||||
ProjectInfo projectInfo = d->m_projectToProjectsInfo.value(project, ProjectInfo());
|
||||
projectInfo.setCompilerCallData(compilerCallData);
|
||||
d->m_projectToProjectsInfo.insert(project, projectInfo);
|
||||
|
||||
return projectInfo;
|
||||
}
|
||||
|
||||
ProjectPart::Ptr CppModelManager::projectPartForId(const QString &projectPartId) const
|
||||
{
|
||||
return d->m_projectPartIdToProjectProjectPart.value(projectPartId);
|
||||
|
@@ -117,9 +117,6 @@ public:
|
||||
QFuture<void> updateProjectInfo(QFutureInterface<void> &futureInterface,
|
||||
const ProjectInfo &newProjectInfo);
|
||||
|
||||
ProjectInfo updateCompilerCallDataForProject(ProjectExplorer::Project *project,
|
||||
ProjectInfo::CompilerCallData &compilerCallData);
|
||||
|
||||
/// \return The project part with the given project file
|
||||
ProjectPart::Ptr projectPartForId(const QString &projectPartId) const;
|
||||
/// \return All project parts that mention the given file name as one of the sources/headers.
|
||||
|
@@ -91,28 +91,10 @@ const QSet<QString> ProjectInfo::sourceFiles() const
|
||||
return m_sourceFiles;
|
||||
}
|
||||
|
||||
void ProjectInfo::setCompilerCallData(const CompilerCallData &data)
|
||||
{
|
||||
m_compilerCallData = data;
|
||||
}
|
||||
|
||||
ProjectInfo::CompilerCallData ProjectInfo::compilerCallData() const
|
||||
{
|
||||
return m_compilerCallData;
|
||||
}
|
||||
|
||||
static bool operator==(const ProjectInfo::CompilerCallGroup &first,
|
||||
const ProjectInfo::CompilerCallGroup &second)
|
||||
{
|
||||
return first.groupId == second.groupId
|
||||
&& first.callsPerSourceFile == second.callsPerSourceFile;
|
||||
}
|
||||
|
||||
bool ProjectInfo::operator ==(const ProjectInfo &other) const
|
||||
{
|
||||
return m_project == other.m_project
|
||||
&& m_projectParts == other.m_projectParts
|
||||
&& m_compilerCallData == other.m_compilerCallData
|
||||
&& m_headerPaths == other.m_headerPaths
|
||||
&& m_sourceFiles == other.m_sourceFiles
|
||||
&& m_defines == other.m_defines;
|
||||
|
@@ -95,16 +95,6 @@ public:
|
||||
const QVector<ProjectPart::Ptr> projectParts() const;
|
||||
const QSet<QString> sourceFiles() const;
|
||||
|
||||
struct CompilerCallGroup {
|
||||
using CallsPerSourceFile = QHash<QString, QList<QStringList>>;
|
||||
|
||||
QString groupId;
|
||||
CallsPerSourceFile callsPerSourceFile;
|
||||
};
|
||||
using CompilerCallData = QVector<CompilerCallGroup>;
|
||||
void setCompilerCallData(const CompilerCallData &data);
|
||||
CompilerCallData compilerCallData() const;
|
||||
|
||||
// Comparisons
|
||||
bool operator ==(const ProjectInfo &other) const;
|
||||
bool operator !=(const ProjectInfo &other) const;
|
||||
@@ -119,7 +109,6 @@ public:
|
||||
private:
|
||||
QPointer<ProjectExplorer::Project> m_project;
|
||||
QVector<ProjectPart::Ptr> m_projectParts;
|
||||
CompilerCallData m_compilerCallData;
|
||||
|
||||
// The members below are (re)calculated from the project parts with finish()
|
||||
ProjectPartHeaderPaths m_headerPaths;
|
||||
|
@@ -613,7 +613,6 @@ void QbsProject::updateAfterBuild()
|
||||
m_projectData = projectData;
|
||||
updateProjectNodes();
|
||||
updateBuildTargetData();
|
||||
updateCppCompilerCallData();
|
||||
if (m_extraCompilersPending) {
|
||||
m_extraCompilersPending = false;
|
||||
updateCppCodeModel();
|
||||
@@ -1039,53 +1038,6 @@ void QbsProject::updateCppCodeModel()
|
||||
m_cppCodeModelUpdater->update({this, cToolChain, cxxToolChain, k, rpps});
|
||||
}
|
||||
|
||||
void QbsProject::updateCppCompilerCallData()
|
||||
{
|
||||
OpTimer optimer("updateCppCompilerCallData");
|
||||
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||
QTC_ASSERT(m_cppCodeModelProjectInfo == modelManager->projectInfo(this), return);
|
||||
|
||||
CppTools::ProjectInfo::CompilerCallData data;
|
||||
foreach (const qbs::ProductData &product, m_projectData.allProducts()) {
|
||||
if (!product.isEnabled())
|
||||
continue;
|
||||
|
||||
foreach (const qbs::GroupData &group, product.groups()) {
|
||||
if (!group.isEnabled())
|
||||
continue;
|
||||
|
||||
CppTools::ProjectInfo::CompilerCallGroup compilerCallGroup;
|
||||
compilerCallGroup.groupId = groupLocationToCallGroupId(group.location());
|
||||
|
||||
foreach (const qbs::ArtifactData &file, group.allSourceArtifacts()) {
|
||||
const QString &filePath = file.filePath();
|
||||
if (!CppTools::ProjectFile::isSource(cppFileType(file)))
|
||||
continue;
|
||||
|
||||
qbs::ErrorInfo errorInfo;
|
||||
const qbs::RuleCommandList ruleCommands = m_qbsProject.ruleCommands(product,
|
||||
filePath, QLatin1String("obj"), &errorInfo);
|
||||
if (errorInfo.hasError())
|
||||
continue;
|
||||
|
||||
QList<QStringList> calls;
|
||||
foreach (const qbs::RuleCommand &ruleCommand, ruleCommands) {
|
||||
if (ruleCommand.type() == qbs::RuleCommand::ProcessCommandType)
|
||||
calls << ruleCommand.arguments();
|
||||
}
|
||||
|
||||
if (!calls.isEmpty())
|
||||
compilerCallGroup.callsPerSourceFile.insert(filePath, calls);
|
||||
}
|
||||
|
||||
if (!compilerCallGroup.callsPerSourceFile.isEmpty())
|
||||
data.append(compilerCallGroup);
|
||||
}
|
||||
}
|
||||
|
||||
m_cppCodeModelProjectInfo = modelManager->updateCompilerCallDataForProject(this, data);
|
||||
}
|
||||
|
||||
void QbsProject::updateQmlJsCodeModel()
|
||||
{
|
||||
OpTimer optimer("updateQmlJsCodeModel");
|
||||
|
@@ -122,7 +122,6 @@ private:
|
||||
void prepareForParsing();
|
||||
void updateDocuments(const QSet<QString> &files);
|
||||
void updateCppCodeModel();
|
||||
void updateCppCompilerCallData();
|
||||
void updateQmlJsCodeModel();
|
||||
void updateApplicationTargets();
|
||||
void updateDeploymentInfo();
|
||||
|
Reference in New Issue
Block a user