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:
Ivan Donchevskii
2018-08-06 11:32:32 +02:00
parent 960fccc763
commit 344cbb3a1b
7 changed files with 42 additions and 41 deletions

View File

@@ -209,7 +209,8 @@ AnalyzeUnits ClangToolRunControl::unitsToAnalyze(const QString &clangVersion)
{ {
QTC_ASSERT(m_projectInfo.isValid(), return AnalyzeUnits()); 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); return toAnalyzeUnits(m_fileInfos, clangVersion, clangResourceDirectory);
} }
@@ -232,7 +233,7 @@ ClangToolRunControl::ClangToolRunControl(RunControl *runControl,
const FileInfos &fileInfos) const FileInfos &fileInfos)
: RunWorker(runControl) : RunWorker(runControl)
, m_projectBuilder(new ProjectBuilder(runControl, target->project(), this)) , 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_temporaryDir("clangtools-XXXXXX")
, m_target(target) , m_target(target)
, m_fileInfos(fileInfos) , m_fileInfos(fileInfos)

View File

@@ -29,6 +29,7 @@
#include "clangtidyclazytool.h" #include "clangtidyclazytool.h"
#include "clangtoolsutils.h" #include "clangtoolsutils.h"
#include <coreplugin/icore.h>
#include <cpptools/compileroptionsbuilder.h> #include <cpptools/compileroptionsbuilder.h>
#include <cpptools/projectinfo.h> #include <cpptools/projectinfo.h>
#include <projectexplorer/kitinformation.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); const ToolChain * const toolchain = ToolChainKitInformation::toolChain(kit, ProjectExplorer::Constants::CXX_LANGUAGE_ID);
QTC_ASSERT(toolchain, return false); 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.", qWarning("Project \"%s\": Skipping target \"%s\" since no suitable clang was found for the toolchain.",
qPrintable(projectFileName), qPrintable(projectFileName),
qPrintable(target->displayName())); qPrintable(target->displayName()));

View File

@@ -29,6 +29,7 @@
#include "clangtidyclazytool.h" #include "clangtidyclazytool.h"
#include "clangtoolsutils.h" #include "clangtoolsutils.h"
#include <coreplugin/icore.h>
#include <cpptools/cppcodemodelsettings.h> #include <cpptools/cppcodemodelsettings.h>
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <cpptools/cpptoolstestcase.h> #include <cpptools/cpptoolstestcase.h>
@@ -62,7 +63,7 @@ void ClangToolsUnitTests::initTestCase()
if (!toolchain) if (!toolchain)
QSKIP("This test requires that there is a kit with a 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"); QSKIP("No clang suitable for analyzing found");
m_tmpDir = new CppTools::Tests::TemporaryCopiedDir(QLatin1String(":/unit-tests")); m_tmpDir = new CppTools::Tests::TemporaryCopiedDir(QLatin1String(":/unit-tests"));

View File

@@ -459,6 +459,28 @@ QString ICore::libexecPath()
return QDir::cleanPath(QApplication::applicationDirPath() + '/' + RELATIVE_LIBEXEC_PATH); 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() static QString compilerString()
{ {
#if defined(Q_CC_CLANG) // must be before GNU, because clang claims to be GNU too #if defined(Q_CC_CLANG) // must be before GNU, because clang claims to be GNU too

View File

@@ -97,6 +97,9 @@ public:
static QString installerResourcePath(); static QString installerResourcePath();
static QString documentationPath(); static QString documentationPath();
static QString libexecPath(); static QString libexecPath();
static QString clangExecutable(const QString &clangBinDirectory);
static QString clangIncludeDirectory(const QString &clangVersion,
const QString &clangResourceDirectory);
static QString versionString(); static QString versionString();
static QString buildCompatibilityString(); static QString buildCompatibilityString();

View File

@@ -510,6 +510,16 @@ void CompilerOptionsBuilder::addPredefinedHeaderPathsOptions()
addClangIncludeFolder(); 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() void CompilerOptionsBuilder::addClangIncludeFolder()
{ {
QTC_CHECK(!m_clangVersion.isEmpty()); 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() void CompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
{ {
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) { if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {

View File

@@ -97,15 +97,4 @@ private:
QString m_clangResourceDirectory; 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 } // namespace CppTools