Commit 3e225628 authored by hjk's avatar hjk Committed by Tobias Hunger

Revert "Clang: Add possibility to "pgo-train" libclang with a batch file"

This reverts commit 07f4ae62,
which broke compilation

clangbatchfileprocessor.cpp:170:27: error: ambiguous overload for
    'operator==' (operand types are 'const QChar' and 'char')

and only worked in QT_TEST=1 cases.

Change-Id: I089427359958221882cb4e4369c4b88d71779acf
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 92d818f3
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "clangautomationutils.h"
#include "clangcompletionassistinterface.h"
#include "clangcompletionassistprovider.h"
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/assistproposalitem.h>
#include <texteditor/codeassist/completionassistprovider.h>
#include <texteditor/codeassist/genericproposalmodel.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
#include <QElapsedTimer>
namespace ClangCodeModel {
namespace Internal {
class WaitForAsyncCompletions
{
public:
enum WaitResult { GotResults, GotInvalidResults, Timeout };
WaitResult wait(TextEditor::IAssistProcessor *processor,
TextEditor::AssistInterface *assistInterface,
int timeoutInMs)
{
QTC_ASSERT(processor, return Timeout);
QTC_ASSERT(assistInterface, return Timeout);
bool gotResults = false;
processor->setAsyncCompletionAvailableHandler(
[this, &gotResults] (TextEditor::IAssistProposal *proposal) {
QTC_ASSERT(proposal, return);
proposalModel = proposal->model();
delete proposal;
gotResults = true;
});
// Are there any immediate results?
if (TextEditor::IAssistProposal *proposal = processor->perform(assistInterface)) {
delete processor;
proposalModel = proposal->model();
delete proposal;
QTC_ASSERT(proposalModel, return GotInvalidResults);
return GotResults;
}
// There are not any, so wait for async results.
QElapsedTimer timer;
timer.start();
while (!gotResults) {
if (timer.elapsed() >= timeoutInMs)
return Timeout;
QCoreApplication::processEvents();
}
return proposalModel ? GotResults : GotInvalidResults;
}
public:
TextEditor::IAssistProposalModel *proposalModel;
};
static const CppTools::ProjectPartHeaderPaths toHeaderPaths(const QStringList &paths)
{
using namespace CppTools;
ProjectPartHeaderPaths result;
foreach (const QString &path, paths)
result << ProjectPartHeaderPath(path, ProjectPartHeaderPath::IncludePath);
return result;
}
ProposalModel completionResults(TextEditor::BaseTextEditor *textEditor,
const QStringList &includePaths,
int timeOutInMs)
{
using namespace TextEditor;
TextEditorWidget *textEditorWidget = qobject_cast<TextEditorWidget *>(textEditor->widget());
QTC_ASSERT(textEditorWidget, return ProposalModel());
AssistInterface *assistInterface = textEditorWidget->createAssistInterface(
TextEditor::Completion, TextEditor::ExplicitlyInvoked);
QTC_ASSERT(assistInterface, return ProposalModel());
if (!includePaths.isEmpty()) {
auto clangAssistInterface = static_cast<ClangCompletionAssistInterface *>(assistInterface);
clangAssistInterface->setHeaderPaths(toHeaderPaths(includePaths));
}
CompletionAssistProvider *assistProvider
= textEditor->textDocument()->completionAssistProvider();
QTC_ASSERT(qobject_cast<ClangCompletionAssistProvider *>(assistProvider),
return ProposalModel());
QTC_ASSERT(assistProvider, return ProposalModel());
QTC_ASSERT(assistProvider->runType() == IAssistProvider::Asynchronous, return ProposalModel());
IAssistProcessor *processor = assistProvider->createProcessor();
QTC_ASSERT(processor, return ProposalModel());
WaitForAsyncCompletions waitForCompletions;
const WaitForAsyncCompletions::WaitResult result = waitForCompletions.wait(processor,
assistInterface,
timeOutInMs);
QTC_ASSERT(result == WaitForAsyncCompletions::GotResults, return ProposalModel());
return QSharedPointer<TextEditor::IAssistProposalModel>(waitForCompletions.proposalModel);
}
} // namespace Internal
} // namespace ClangCodeModel
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QString>
#include <QSharedPointer>
namespace TextEditor {
class BaseTextEditor;
class IAssistProposalModel;
}
namespace ClangCodeModel {
namespace Internal {
using ProposalModel = QSharedPointer<TextEditor::IAssistProposalModel>;
ProposalModel completionResults(TextEditor::BaseTextEditor *textEditor,
const QStringList &includePaths = QStringList(),
int timeOutInMs = 10000);
} // namespace Internal
} // namespace ClangCodeModel
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QString>
namespace ClangCodeModel {
namespace Internal {
bool runClangBatchFile(const QString &filePath);
} // namespace Internal
} // namespace ClangCodeModel
......@@ -9,9 +9,7 @@ SOURCES += \
clangassistproposal.cpp \
clangassistproposalitem.cpp \
clangassistproposalmodel.cpp \
clangautomationutils.cpp \
clangbackendipcintegration.cpp \
clangbatchfileprocessor.cpp \
clangcodemodelplugin.cpp \
clangcompletionassistinterface.cpp \
clangcompletionassistprocessor.cpp \
......@@ -41,9 +39,7 @@ HEADERS += \
clangassistproposal.h \
clangassistproposalitem.h \
clangassistproposalmodel.h \
clangautomationutils.h \
clangbackendipcintegration.h \
clangbatchfileprocessor.h \
clangcodemodelplugin.h \
clangcompletionassistinterface.h \
clangcompletionassistprocessor.h \
......
......@@ -41,12 +41,8 @@ QtcPlugin {
"clangassistproposalitem.h",
"clangassistproposalmodel.cpp",
"clangassistproposalmodel.h",
"clangautomationutils.cpp",
"clangautomationutils.h",
"clangbackendipcintegration.cpp",
"clangbackendipcintegration.h",
"clangbatchfileprocessor.cpp",
"clangbatchfileprocessor.h",
"clangcodemodel.qrc",
"clangcodemodelplugin.cpp",
"clangcodemodelplugin.h",
......
......@@ -25,7 +25,6 @@
#include "clangcodemodelplugin.h"
#include "clangbatchfileprocessor.h"
#include "clangconstants.h"
#include "clangprojectsettingswidget.h"
......@@ -75,13 +74,8 @@ void addProjectPanelWidget()
bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
Q_UNUSED(arguments);
Q_UNUSED(errorMessage);
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
&ProjectExplorer::ProjectExplorerPlugin::finishedInitialization,
this,
&ClangCodeModelPlugin::maybeHandleBatchFileAndExit);
Q_UNUSED(arguments)
Q_UNUSED(errorMessage)
CppTools::CppModelManager::instance()->activateClangCodeModel(&m_modelManagerSupportProvider);
......@@ -95,16 +89,6 @@ void ClangCodeModelPlugin::extensionsInitialized()
{
}
// For e.g. creation of profile-guided optimization builds.
void ClangCodeModelPlugin::maybeHandleBatchFileAndExit() const
{
const QString batchFilePath = QString::fromLocal8Bit(qgetenv("QTC_CLANG_BATCH"));
if (!batchFilePath.isEmpty() && QTC_GUARD(QFileInfo::exists(batchFilePath))) {
const bool runSucceeded = runClangBatchFile(batchFilePath);
QCoreApplication::exit(!runSucceeded);
}
}
#ifdef WITH_TESTS
QList<QObject *> ClangCodeModelPlugin::createTestObjects() const
{
......
......@@ -41,9 +41,6 @@ public:
bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized();
private:
void maybeHandleBatchFileAndExit() const;
private:
ModelManagerSupportProviderClang m_modelManagerSupportProvider;
......
......@@ -25,7 +25,6 @@
#include "clangcodecompletion_test.h"
#include "../clangautomationutils.h"
#include "../clangbackendipcintegration.h"
#include "../clangcompletionassistinterface.h"
#include "../clangmodelmanagersupport.h"
......@@ -39,8 +38,12 @@
#include <cpptools/cpptoolstestcase.h>
#include <cpptools/modelmanagertesthelper.h>
#include <cpptools/projectinfo.h>
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/assistproposalitem.h>
#include <texteditor/codeassist/completionassistprovider.h>
#include <texteditor/codeassist/genericproposalmodel.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
......@@ -177,6 +180,53 @@ void insertTextAtTopOfEditor(TextEditor::BaseTextEditor *editor, const QByteArra
cs.apply(&textCursor);
}
class WaitForAsyncCompletions
{
public:
enum WaitResult { GotResults, GotInvalidResults, Timeout };
WaitResult wait(TextEditor::IAssistProcessor *processor,
TextEditor::AssistInterface *assistInterface);
TextEditor::IAssistProposalModel *proposalModel;
};
WaitForAsyncCompletions::WaitResult WaitForAsyncCompletions::wait(
TextEditor::IAssistProcessor *processor,
TextEditor::AssistInterface *assistInterface)
{
QTC_ASSERT(processor, return Timeout);
QTC_ASSERT(assistInterface, return Timeout);
bool gotResults = false;
processor->setAsyncCompletionAvailableHandler(
[this, &gotResults] (TextEditor::IAssistProposal *proposal) {
QTC_ASSERT(proposal, return);
proposalModel = proposal->model();
delete proposal;
gotResults = true;
});
// Are there any immediate results?
if (TextEditor::IAssistProposal *proposal = processor->perform(assistInterface)) {
delete processor;
proposalModel = proposal->model();
delete proposal;
QTC_ASSERT(proposalModel, return GotInvalidResults);
return GotResults;
}
// There are not any, so wait for async results.
QElapsedTimer timer; timer.start();
while (!gotResults) {
if (timer.elapsed() >= 30 * 1000)
return Timeout;
QCoreApplication::processEvents();
}
return proposalModel ? GotResults : GotInvalidResults;
}
class ChangeDocumentReloadSetting
{
public:
......@@ -371,6 +421,51 @@ public:
QString senderLog;
};
const CppTools::ProjectPartHeaderPaths toHeaderPaths(const QStringList &paths)
{
using namespace CppTools;
ProjectPartHeaderPaths result;
foreach (const QString &path, paths)
result << ProjectPartHeaderPath(path, ProjectPartHeaderPath::IncludePath);
return result;
}
using ProposalModel = QSharedPointer<TextEditor::IAssistProposalModel>;
ProposalModel completionResults(
TextEditor::BaseTextEditor *textEditor,
const QStringList &includePaths = QStringList())
{
using namespace TextEditor;
TextEditorWidget *textEditorWidget = qobject_cast<TextEditorWidget *>(textEditor->widget());
QTC_ASSERT(textEditorWidget, return ProposalModel());
AssistInterface *assistInterface = textEditorWidget->createAssistInterface(
TextEditor::Completion, TextEditor::ExplicitlyInvoked);
QTC_ASSERT(assistInterface, return ProposalModel());
if (!includePaths.isEmpty()) {
auto clangAssistInterface = static_cast<ClangCompletionAssistInterface *>(assistInterface);
clangAssistInterface->setHeaderPaths(toHeaderPaths(includePaths));
}
CompletionAssistProvider *assistProvider
= textEditor->textDocument()->completionAssistProvider();
QTC_ASSERT(qobject_cast<ClangCompletionAssistProvider *>(assistProvider),
return ProposalModel());
QTC_ASSERT(assistProvider, return ProposalModel());
QTC_ASSERT(assistProvider->runType() == IAssistProvider::Asynchronous, return ProposalModel());
IAssistProcessor *processor = assistProvider->createProcessor();
QTC_ASSERT(processor, return ProposalModel());
WaitForAsyncCompletions waitForCompletions;
const WaitForAsyncCompletions::WaitResult result = waitForCompletions.wait(processor,
assistInterface);
QTC_ASSERT(result == WaitForAsyncCompletions::GotResults, return ProposalModel());
return QSharedPointer<TextEditor::IAssistProposalModel>(waitForCompletions.proposalModel);
}
class TestDocument
{
public:
......@@ -594,7 +689,7 @@ public:
if (!textToInsert.isEmpty())
openEditor.editor()->insert(textToInsert);
proposal = completionResults(openEditor.editor(), includePaths, 15000);
proposal = completionResults(openEditor.editor(), includePaths);
}
ProposalModel proposal;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment