forked from qt-creator/qt-creator
Clang: Move clang paths helper functions to Core plugin
These functions require core plugin so they can't go to utils library. At the same time to use them in ProjectExplorer plugin there are not too many choices where to put them without introducing new dependencies. Change-Id: I3cccccffaae8ac4bbce924fd809b5423da5dc503 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -209,7 +209,8 @@ AnalyzeUnits ClangToolRunControl::unitsToAnalyze(const QString &clangVersion)
|
||||
{
|
||||
QTC_ASSERT(m_projectInfo.isValid(), return AnalyzeUnits());
|
||||
|
||||
const QString clangResourceDirectory = clangIncludeDirectory(m_clangExecutable, clangVersion);
|
||||
const QString clangResourceDirectory = Core::ICore::clangIncludeDirectory(m_clangExecutable,
|
||||
clangVersion);
|
||||
return toAnalyzeUnits(m_fileInfos, clangVersion, clangResourceDirectory);
|
||||
}
|
||||
|
||||
@@ -232,7 +233,7 @@ ClangToolRunControl::ClangToolRunControl(RunControl *runControl,
|
||||
const FileInfos &fileInfos)
|
||||
: RunWorker(runControl)
|
||||
, m_projectBuilder(new ProjectBuilder(runControl, target->project(), this))
|
||||
, m_clangExecutable(CppTools::clangExecutable(CLANG_BINDIR))
|
||||
, m_clangExecutable(Core::ICore::clangExecutable(CLANG_BINDIR))
|
||||
, m_temporaryDir("clangtools-XXXXXX")
|
||||
, m_target(target)
|
||||
, m_fileInfos(fileInfos)
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "clangtidyclazytool.h"
|
||||
#include "clangtoolsutils.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/projectinfo.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
@@ -168,7 +169,7 @@ static QList<Target *> validTargets(Project *project)
|
||||
const ToolChain * const toolchain = ToolChainKitInformation::toolChain(kit, ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
||||
QTC_ASSERT(toolchain, return false);
|
||||
|
||||
if (CppTools::clangExecutable(CLANG_BINDIR).isEmpty()) {
|
||||
if (Core::ICore::clangExecutable(CLANG_BINDIR).isEmpty()) {
|
||||
qWarning("Project \"%s\": Skipping target \"%s\" since no suitable clang was found for the toolchain.",
|
||||
qPrintable(projectFileName),
|
||||
qPrintable(target->displayName()));
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "clangtidyclazytool.h"
|
||||
#include "clangtoolsutils.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <cpptools/cppcodemodelsettings.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/cpptoolstestcase.h>
|
||||
@@ -62,7 +63,7 @@ void ClangToolsUnitTests::initTestCase()
|
||||
if (!toolchain)
|
||||
QSKIP("This test requires that there is a kit with a toolchain.");
|
||||
|
||||
if (CppTools::clangExecutable(CLANG_BINDIR).isEmpty())
|
||||
if (Core::ICore::clangExecutable(CLANG_BINDIR).isEmpty())
|
||||
QSKIP("No clang suitable for analyzing found");
|
||||
|
||||
m_tmpDir = new CppTools::Tests::TemporaryCopiedDir(QLatin1String(":/unit-tests"));
|
||||
|
@@ -459,6 +459,28 @@ QString ICore::libexecPath()
|
||||
return QDir::cleanPath(QApplication::applicationDirPath() + '/' + RELATIVE_LIBEXEC_PATH);
|
||||
}
|
||||
|
||||
static QString clangIncludePath(const QString &clangVersion)
|
||||
{
|
||||
return "/lib/clang/" + clangVersion + "/include";
|
||||
}
|
||||
|
||||
QString ICore::clangIncludeDirectory(const QString &clangVersion, const QString &clangResourceDirectory)
|
||||
{
|
||||
QDir dir(libexecPath() + "/clang" + clangIncludePath(clangVersion));
|
||||
if (!dir.exists() || !QFileInfo(dir, "stdint.h").exists())
|
||||
dir = QDir(clangResourceDirectory);
|
||||
return QDir::toNativeSeparators(dir.canonicalPath());
|
||||
}
|
||||
|
||||
QString ICore::clangExecutable(const QString &clangBinDirectory)
|
||||
{
|
||||
const QString hostExeSuffix(QTC_HOST_EXE_SUFFIX);
|
||||
QFileInfo executable(libexecPath() + "/clang/bin/clang" + hostExeSuffix);
|
||||
if (!executable.exists())
|
||||
executable = QFileInfo(clangBinDirectory + "/clang" + hostExeSuffix);
|
||||
return QDir::toNativeSeparators(executable.canonicalFilePath());
|
||||
}
|
||||
|
||||
static QString compilerString()
|
||||
{
|
||||
#if defined(Q_CC_CLANG) // must be before GNU, because clang claims to be GNU too
|
||||
|
@@ -97,6 +97,9 @@ public:
|
||||
static QString installerResourcePath();
|
||||
static QString documentationPath();
|
||||
static QString libexecPath();
|
||||
static QString clangExecutable(const QString &clangBinDirectory);
|
||||
static QString clangIncludeDirectory(const QString &clangVersion,
|
||||
const QString &clangResourceDirectory);
|
||||
|
||||
static QString versionString();
|
||||
static QString buildCompatibilityString();
|
||||
|
@@ -510,6 +510,16 @@ void CompilerOptionsBuilder::addPredefinedHeaderPathsOptions()
|
||||
addClangIncludeFolder();
|
||||
}
|
||||
|
||||
static QString clangIncludeDirectory(const QString &clangVersion,
|
||||
const QString &clangResourceDirectory)
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
return Core::ICore::clangIncludeDirectory(clangVersion, clangResourceDirectory);
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::addClangIncludeFolder()
|
||||
{
|
||||
QTC_CHECK(!m_clangVersion.isEmpty());
|
||||
@@ -525,32 +535,6 @@ void CompilerOptionsBuilder::addProjectConfigFileInclude()
|
||||
}
|
||||
}
|
||||
|
||||
static QString creatorLibexecPath()
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
return Core::ICore::instance()->libexecPath();
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString clangIncludeDirectory(const QString &clangVersion, const QString &clangResourceDirectory)
|
||||
{
|
||||
QDir dir(creatorLibexecPath() + "/clang" + clangIncludePath(clangVersion));
|
||||
if (!dir.exists() || !QFileInfo(dir, "stdint.h").exists())
|
||||
dir = QDir(clangResourceDirectory);
|
||||
return QDir::toNativeSeparators(dir.canonicalPath());
|
||||
}
|
||||
|
||||
QString clangExecutable(const QString &clangBinDirectory)
|
||||
{
|
||||
const QString hostExeSuffix(QTC_HOST_EXE_SUFFIX);
|
||||
QFileInfo executable(creatorLibexecPath() + "/clang/bin/clang" + hostExeSuffix);
|
||||
if (!executable.exists())
|
||||
executable = QFileInfo(clangBinDirectory + "/clang" + hostExeSuffix);
|
||||
return QDir::toNativeSeparators(executable.canonicalFilePath());
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
||||
|
@@ -97,15 +97,4 @@ private:
|
||||
QString m_clangResourceDirectory;
|
||||
};
|
||||
|
||||
QString CPPTOOLS_EXPORT clangExecutable(const QString &clangBinDirectory);
|
||||
|
||||
QString CPPTOOLS_EXPORT clangIncludeDirectory(const QString &clangVersion,
|
||||
const QString &clangResourceDirectory);
|
||||
|
||||
template<class T>
|
||||
T clangIncludePath(const T &clangVersion)
|
||||
{
|
||||
return "/lib/clang/" + clangVersion + "/include";
|
||||
}
|
||||
|
||||
} // namespace CppTools
|
||||
|
Reference in New Issue
Block a user