Commit 5f98b8ec authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Remove PchManager

...which is the last dependency to libclang from the plugin.

Change-Id: I173ee7e9621912ec88706b4cf62db2b1dbcf7610
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent daf93696
......@@ -34,7 +34,6 @@
#include "clangeditordocumentprocessor.h"
#include "clangmodelmanagersupport.h"
#include "clangutils.h"
#include "pchmanager.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
......@@ -335,10 +334,8 @@ void IpcCommunicator::initializeBackend()
static QStringList projectPartOptions(const CppTools::ProjectPart::Ptr &projectPart)
{
QStringList options = ClangCodeModel::Utils::createClangOptions(projectPart,
const QStringList options = ClangCodeModel::Utils::createClangOptions(projectPart,
CppTools::ProjectFile::Unclassified); // No language option
if (PchInfo::Ptr pchInfo = PchManager::instance()->pchInfo(projectPart))
options += ClangCodeModel::Utils::createPCHInclusionOptions(pchInfo->fileName());
return options;
}
......
include(../../qtcreatorplugin.pri)
include(../../shared/clang/clang_installation.pri)
LIBS += $$LLVM_LIBS
INCLUDEPATH += $$LLVM_INCLUDEPATH
DEFINES += CLANGCODEMODEL_LIBRARY
# The following defines are used to determine the clang include path for intrinsics.
DEFINES += CLANG_VERSION=\\\"$${LLVM_VERSION}\\\"
DEFINES += "\"CLANG_RESOURCE_DIR=\\\"$${LLVM_LIBDIR}/clang/$${LLVM_VERSION}/include\\\"\""
unix:QMAKE_LFLAGS += -Wl,-rpath,\'$$LLVM_LIBDIR\'
SOURCES += \
activationsequencecontextprocessor.cpp \
activationsequenceprocessor.cpp \
......@@ -36,12 +32,7 @@ SOURCES += \
clangtextmark.cpp \
clangutils.cpp \
completionchunkstotextconverter.cpp \
highlightingmarksreporter.cpp \
pchinfo.cpp \
pchmanager.cpp \
raii/scopedclangoptions.cpp \
unit.cpp \
unsavedfiledata.cpp
highlightingmarksreporter.cpp
HEADERS += \
activationsequencecontextprocessor.h \
......@@ -70,12 +61,7 @@ HEADERS += \
clangutils.h \
completionchunkstotextconverter.h \
constants.h \
highlightingmarksreporter.h \
pchinfo.h \
pchmanager.h \
raii/scopedclangoptions.h \
unit.h \
unsavedfiledata.h
highlightingmarksreporter.h
FORMS += clangprojectsettingspropertiespage.ui
......
......@@ -23,16 +23,10 @@ QtcPlugin {
property string llvmConfig: Clang.llvmConfig(qbs, QtcFunctions, QtcProcessOutputReader)
property string llvmIncludeDir: Clang.includeDir(llvmConfig, QtcProcessOutputReader)
property string llvmLibDir: Clang.libDir(llvmConfig, QtcProcessOutputReader)
property string llvmLibs: Clang.libraries(qbs.targetOS)
property string llvmVersion: Clang.version(llvmConfig, QtcProcessOutputReader)
condition: llvmConfig && File.exists(llvmIncludeDir.concat("/clang-c/Index.h"))
cpp.includePaths: base.concat(llvmIncludeDir)
cpp.libraryPaths: base.concat(llvmLibDir)
cpp.rpaths: cpp.libraryPaths
cpp.dynamicLibraries: base.concat(llvmLibs)
cpp.defines: {
var defines = base;
// The following defines are used to determine the clang include path for intrinsics.
......@@ -95,16 +89,6 @@ QtcPlugin {
"constants.h",
"highlightingmarksreporter.cpp",
"highlightingmarksreporter.h",
"pchinfo.cpp",
"pchinfo.h",
"pchmanager.cpp",
"pchmanager.h",
"raii/scopedclangoptions.cpp",
"raii/scopedclangoptions.h",
"unit.cpp",
"unit.h",
"unsavedfiledata.cpp",
"unsavedfiledata.h",
]
Group {
......
......@@ -32,7 +32,6 @@
#include "clangprojectsettingspropertiespage.h"
#include "constants.h"
#include "pchmanager.h"
#ifdef WITH_TESTS
# include "test/clangcodecompletion_test.h"
......@@ -46,8 +45,6 @@
#include <texteditor/textmark.h>
#include <clang-c/Index.h>
namespace ClangCodeModel {
namespace Internal {
......@@ -61,23 +58,6 @@ void initializeTextMarks()
Utils::Theme::ClangCodeModel_Error_TextMarkColor);
}
static bool clangInitialised = false;
static QMutex initialisationMutex;
void initializeClang()
{
if (clangInitialised)
return;
QMutexLocker locker(&initialisationMutex);
if (clangInitialised)
return;
clang_toggleCrashRecovery(1);
clang_enableStackTraces();
clangInitialised = true;
}
} // anonymous namespace
bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *errorMessage)
......@@ -92,19 +72,8 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
panelFactory->setSimpleCreateWidgetFunction<ClangProjectSettingsWidget>(QIcon());
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
// Initialize Clang
ClangCodeModel::Internal::initializeClang();
// Set up PchManager
PchManager *pchManager = new PchManager(this);
ProjectExplorer::SessionManager *sessionManager = ProjectExplorer::SessionManager::instance();
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject,
pchManager, &PchManager::onAboutToRemoveProject);
auto cppModelManager = CppTools::CppModelManager::instance();
connect(cppModelManager, &CppTools::CppModelManager::projectPartsUpdated,
pchManager, &PchManager::onProjectPartsUpdated);
// Register ModelManagerSupportProvider
auto cppModelManager = CppTools::CppModelManager::instance();
cppModelManager->setClangModelManagerSupportProvider(&m_modelManagerSupportProvider);
initializeTextMarks();
......
......@@ -32,14 +32,10 @@
#include "clangutils.h"
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cpptoolsreuse.h>
#include <cpptools/cppworkingcopy.h>
#include <texteditor/texteditor.h>
#include <cplusplus/Token.h>
namespace ClangCodeModel {
namespace Internal {
......@@ -50,18 +46,13 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(
const QString &fileName,
TextEditor::AssistReason reason,
const CppTools::ProjectPart::HeaderPaths &headerPaths,
const PchInfo::Ptr &pchInfo,
const CPlusPlus::LanguageFeatures &features)
: AssistInterface(textEditorWidget->document(), position, fileName, reason)
, m_ipcCommunicator(ipcCommunicator)
, m_headerPaths(headerPaths)
, m_savedPchPointer(pchInfo)
, m_languageFeatures(features)
, m_textEditorWidget(textEditorWidget)
{
m_unsavedFiles = Utils::createUnsavedFiles(
CppTools::CppModelManager::instance()->workingCopy(),
CppTools::modifiedFiles());
}
bool ClangCompletionAssistInterface::objcEnabled() const
......@@ -94,11 +85,6 @@ IpcCommunicator &ClangCompletionAssistInterface::ipcCommunicator() const
return m_ipcCommunicator;
}
const Utils::UnsavedFiles &ClangCompletionAssistInterface::unsavedFiles() const
{
return m_unsavedFiles;
}
} // namespace Internal
} // namespace ClangCodeModel
......@@ -32,7 +32,6 @@
#define CLANGCODEMODEL_INTERNAL_CLANGCOMPLETIONASSISTINTERFACE_H
#include "clangbackendipcintegration.h"
#include "pchinfo.h"
#include "clangutils.h"
#include <cpptools/cppcompletionassistprovider.h>
......@@ -51,11 +50,9 @@ public:
const QString &fileName,
TextEditor::AssistReason reason,
const CppTools::ProjectPart::HeaderPaths &headerPaths,
const PchInfo::Ptr &pchInfo,
const CPlusPlus::LanguageFeatures &features);
IpcCommunicator &ipcCommunicator() const;
const Utils::UnsavedFiles &unsavedFiles() const;
bool objcEnabled() const;
const CppTools::ProjectPart::HeaderPaths &headerPaths() const;
CPlusPlus::LanguageFeatures languageFeatures() const;
......@@ -65,10 +62,8 @@ public:
private:
IpcCommunicator &m_ipcCommunicator;
Utils::UnsavedFiles m_unsavedFiles;
QStringList m_options;
CppTools::ProjectPart::HeaderPaths m_headerPaths;
Internal::PchInfo::Ptr m_savedPchPointer;
CPlusPlus::LanguageFeatures m_languageFeatures;
const TextEditor::TextEditorWidget *m_textEditorWidget;
};
......
......@@ -33,7 +33,6 @@
#include "clangcompletionassistprocessor.h"
#include "clangeditordocumentprocessor.h"
#include "clangutils.h"
#include "pchmanager.h"
#include <cplusplus/Token.h>
#include <cpptools/cppcompletionassistprocessor.h>
......@@ -73,14 +72,12 @@ TextEditor::AssistInterface *ClangCompletionAssistProvider::createAssistInterfac
{
const CppTools::ProjectPart::Ptr projectPart = Utils::projectPartForFileBasedOnProcessor(filePath);
if (projectPart) {
const PchInfo::Ptr pchInfo = PchManager::instance()->pchInfo(projectPart);
return new ClangCompletionAssistInterface(m_ipcCommunicator,
textEditorWidget,
position,
filePath,
reason,
projectPart->headerPaths,
pchInfo,
projectPart->languageFeatures);
}
......
......@@ -35,7 +35,6 @@
#include "clangmodelmanagersupport.h"
#include "clangutils.h"
#include "highlightingmarksreporter.h"
#include "pchinfo.h"
#include <diagnosticcontainer.h>
#include <sourcelocationcontainer.h>
......
......@@ -30,11 +30,6 @@
#include "clangprojectsettings.h"
#include "clangprojectsettingspropertiespage.h"
#include "pchmanager.h"
#include <QButtonGroup>
#include <QCoreApplication>
#include <QFileDialog>
using namespace ProjectExplorer;
using namespace ClangCodeModel::Internal;
......@@ -43,88 +38,4 @@ ClangProjectSettingsWidget::ClangProjectSettingsWidget(Project *project)
: m_project(project)
{
m_ui.setupUi(this);
ClangProjectSettings *cps = PchManager::instance()->settingsForProject(project);
Q_ASSERT(cps);
QButtonGroup *pchGroup = new QButtonGroup(this);
pchGroup->addButton(m_ui.noneButton, ClangProjectSettings::PchUse_None);
pchGroup->addButton(m_ui.exactButton, ClangProjectSettings::PchUse_BuildSystem_Exact);
pchGroup->addButton(m_ui.fuzzyButton, ClangProjectSettings::PchUse_BuildSystem_Fuzzy);
pchGroup->addButton(m_ui.customButton, ClangProjectSettings::PchUse_Custom);
switch (cps->pchUsage()) {
case ClangProjectSettings::PchUse_None:
case ClangProjectSettings::PchUse_BuildSystem_Exact:
case ClangProjectSettings::PchUse_BuildSystem_Fuzzy:
case ClangProjectSettings::PchUse_Custom:
pchGroup->button(cps->pchUsage())->setChecked(true);
break;
default: break;
}
pchUsageChanged(cps->pchUsage());
connect(pchGroup, SIGNAL(buttonClicked(int)),
this, SLOT(pchUsageChanged(int)));
m_ui.customField->setText(cps->customPchFile());
connect(m_ui.customField, SIGNAL(editingFinished()),
this, SLOT(customPchFileChanged()));
connect(m_ui.customButton, SIGNAL(clicked()),
this, SLOT(customPchButtonClicked()));
}
void ClangProjectSettingsWidget::pchUsageChanged(int id)
{
ClangProjectSettings *cps = PchManager::instance()->settingsForProject(m_project);
Q_ASSERT(cps);
cps->setPchUsage(static_cast<ClangProjectSettings::PchUsage>(id));
switch (id) {
case ClangProjectSettings::PchUse_None:
case ClangProjectSettings::PchUse_BuildSystem_Fuzzy:
case ClangProjectSettings::PchUse_BuildSystem_Exact:
m_ui.customField->setEnabled(false);
m_ui.chooseButton->setEnabled(false);
break;
case ClangProjectSettings::PchUse_Custom:
m_ui.customField->setEnabled(true);
m_ui.chooseButton->setEnabled(true);
break;
default:
break;
}
}
void ClangProjectSettingsWidget::customPchFileChanged()
{
ClangProjectSettings *cps = PchManager::instance()->settingsForProject(m_project);
Q_ASSERT(cps);
if (cps->pchUsage() != ClangProjectSettings::PchUse_Custom)
return;
QString fileName = m_ui.customField->text();
if (!QFile(fileName).exists())
return;
cps->setCustomPchFile(fileName);
}
void ClangProjectSettingsWidget::customPchButtonClicked()
{
ClangProjectSettings *cps = PchManager::instance()->settingsForProject(m_project);
Q_ASSERT(cps);
QFileDialog d(this);
d.setNameFilters(QStringList() << tr("Header Files (*.h)")
<< tr("All Files (*)"));
d.setFileMode(QFileDialog::ExistingFile);
d.setDirectory(m_project->projectDirectory().toString());
if (!d.exec())
return;
const QStringList fileNames = d.selectedFiles();
if (fileNames.isEmpty() || fileNames.first().isEmpty())
return;
m_ui.customField->setText(fileNames.first());
cps->setCustomPchFile(fileNames.first());
}
......@@ -33,10 +33,8 @@
#include "ui_clangprojectsettingspropertiespage.h"
#include <QString>
namespace ProjectExplorer {
class Project;
class Project;
}
namespace ClangCodeModel {
......@@ -49,11 +47,6 @@ class ClangProjectSettingsWidget: public QWidget
public:
ClangProjectSettingsWidget(ProjectExplorer::Project *project);
protected slots:
void pchUsageChanged(int id);
void customPchFileChanged();
void customPchButtonClicked();
private:
Ui::ClangProjectSettingsPropertiesPage m_ui;
ProjectExplorer::Project *m_project;
......
......@@ -2,6 +2,9 @@
<ui version="4.0">
<class>ClangCodeModel::Internal::ClangProjectSettingsPropertiesPage</class>
<widget class="QWidget" name="ClangCodeModel::Internal::ClangProjectSettingsPropertiesPage">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
......
......@@ -32,25 +32,18 @@
#include "clangeditordocumentprocessor.h"
#include <clang-c/Index.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cpptools/baseeditordocumentparser.h>
#include <cpptools/cppprojects.h>
#include <cpptools/cppworkingcopy.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/qtcassert.h>
#include <QDir>
#include <QFile>
#include <QLoggingCategory>
#include <QRegularExpression>
#include <QSet>
#include <QString>
#include <QStringList>
using namespace ClangCodeModel;
using namespace ClangCodeModel::Internal;
......@@ -62,21 +55,6 @@ namespace Utils {
Q_LOGGING_CATEGORY(verboseRunLog, "qtc.clangcodemodel.verboserun")
UnsavedFiles createUnsavedFiles(const WorkingCopy &workingCopy,
const ::Utils::FileNameList &modifiedFiles)
{
UnsavedFiles result;
QHashIterator< ::Utils::FileName, QPair<QByteArray, unsigned> > wcIter = workingCopy.iterator();
while (wcIter.hasNext()) {
wcIter.next();
const ::Utils::FileName &fileName = wcIter.key();
if (modifiedFiles.contains(fileName) && QFile(fileName.toString()).exists())
result.insert(fileName.toString(), wcIter.value().first);
}
return result;
}
/**
* @brief Creates list of message-line arguments required for correct parsing
* @param pPart Null if file isn't part of any project
......
......@@ -33,20 +33,15 @@
#include "clang_global.h"
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cppprojects.h>
#include <QLoggingCategory>
namespace ClangCodeModel {
namespace Utils {
typedef QMap<QString, QByteArray> UnsavedFiles;
Q_DECLARE_LOGGING_CATEGORY(verboseRunLog)
UnsavedFiles createUnsavedFiles(const CppTools::WorkingCopy &workingCopy,
const ::Utils::FileNameList &modifiedFiles);
QStringList createClangOptions(const CppTools::ProjectPart::Ptr &pPart,
CppTools::ProjectFile::Kind fileKind);
QStringList createClangOptions(const CppTools::ProjectPart::Ptr &pPart,
......
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "pchinfo.h"
#include <QDir>
using namespace ClangCodeModel::Internal;
PchInfo::PchInfo()
{
}
PchInfo::~PchInfo()
{
}
PchInfo::Ptr PchInfo::createEmpty()
{
return Ptr(new PchInfo);
}
PchInfo::Ptr PchInfo::createWithFileName(const QString &inputFileName,
const QStringList &options,
bool objcEnabled)
{
Ptr result(new PchInfo);
result->m_inputFileName = inputFileName;
result->m_options = options;
result->m_objcEnabled = objcEnabled;
// The next 2 lines are just here to generate the file name....
result->m_file.open();
result->m_file.close();
return result;
}
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef PCHINFO_H
#define PCHINFO_H
#include <QString>
#include <QStringList>
#include <QSharedPointer>
#include <QTemporaryFile>
namespace ClangCodeModel {
namespace Internal {
class PchInfo
{
PchInfo();
public:
typedef QSharedPointer<PchInfo> Ptr;
public:
~PchInfo();
static Ptr createEmpty();
static Ptr createWithFileName(const QString &inputFileName,
const QStringList &options, bool objcEnabled);
/// \return the (temporary) file name for the PCH file.
QString fileName() const
{ return m_file.fileName(); }
/// \return the input file for the PCH compilation.
QString inputFileName() const
{ return m_inputFileName; }
/// \return the options used to generate this PCH file.
QStringList options() const
{ return m_options; }
bool objcWasEnabled() const
{ return m_objcEnabled; }
private:
QString m_inputFileName;
QStringList m_options;
bool m_objcEnabled;
QTemporaryFile m_file;
};
} // Internal namespace
} // ClangCodeModel namespace
#endif // PCHINFO_H
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef PCHMANAGER_H
#define PCHMANAGER_H
#include "clangprojectsettings.h"
#include "pchinfo.h"
#include <cpptools/cppmodelmanager.h>
#include <projectexplorer/project.h>
#include <coreplugin/messagemanager.h>
#include <QFutureWatcher>
#include <QHash>
#include <QMutex>
#include <QObject>
namespace ClangCodeModel {
namespace Internal {
class PchManager : public QObject
{
Q_OBJECT
typedef CppTools::ProjectPart ProjectPart;
static PchManager *m_instance;
public:
PchManager(QObject *parent = 0);
virtual ~PchManager();
static PchManager *instance();
PchInfo::Ptr pchInfo(const ProjectPart::Ptr &projectPart) const;
ClangProjectSettings *settingsForProject(ProjectExplorer::Project *project);
signals:
void pchMessage(const QString &message, Core::MessageManager::PrintToOutputPaneFlags flags);
public slots:
void clangProjectSettingsChanged();
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onProjectPartsUpdated(ProjectExplorer::Project *project);
private slots:
void updateActivePchFiles();
private:
struct UpdateParams {
UpdateParams(const QString &customPchFile, const QList<ProjectPart::Ptr> &projectParts)
: customPchFile(customPchFile) , projectParts(projectParts) {}