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

This allows to start Qt Creator in batch processing mode:

  $ export QTC_CLANG_BATCH=/path/to/file
  $ export QT_LOGGING_RULES=qtc.clangcodemodel.batch=true
  $ ./qtcreator -load ClangCodeModel

The batch file will be executed and Qt Creator will exit. Advanced
logging output can be activated as stated above.

Note that it is required that the project was already configured/set up
properly with the used settingspath, otherwise the wrong configuration
will be taken or a pop-up dialog will block the execution.

A small example follows that covers all the understood and so far needed
batch file commands in order to train libclang for profile guided
optimization. ${PWD} expands to the directory of the batch file.

    openProject "${PWD}/calendarwidget.pro"

    # Initial parsing
    openDocument "${PWD}/window.cpp"
    closeAllDocuments
    openDocument "${PWD}/window.cpp"

    # Reparse
    setCursor 478 1
    insertText " "
    insertText " "
    insertText " "

    # Completion
    complete
    complete
    complete

    # Member completion
    insertText "comboBox->"
    complete
    complete
    complete

    # Wait in order to inspect the result
    processEvents 3000

Change-Id: I7dc5dddc6752272ecc2fb4f30497b17cee3f9a9f
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Nikolai Kosjar
2016-05-10 15:10:15 +02:00
parent f8ad72deb3
commit ca1d1dfbe2
9 changed files with 1052 additions and 99 deletions

View File

@@ -25,6 +25,7 @@
#include "clangcodemodelplugin.h"
#include "clangbatchfileprocessor.h"
#include "clangconstants.h"
#include "clangprojectsettingswidget.h"
@@ -74,8 +75,13 @@ void addProjectPanelWidget()
bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
Q_UNUSED(arguments)
Q_UNUSED(errorMessage)
Q_UNUSED(arguments);
Q_UNUSED(errorMessage);
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
&ProjectExplorer::ProjectExplorerPlugin::finishedInitialization,
this,
&ClangCodeModelPlugin::maybeHandleBatchFileAndExit);
CppTools::CppModelManager::instance()->activateClangCodeModel(&m_modelManagerSupportProvider);
@@ -89,6 +95,16 @@ 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
{