Clang: Fix some issues with running indexer over Qt Creator

- fix qDebug channels on Windows
 - fix the number of perameters in the sql statement
 - fix nullptr access
 - speed up preprocessor a little bit

Change-Id: Ic9b32fbcc6b409c4064c4f522b94391cbff8654e
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2019-01-30 09:07:45 +01:00
parent f369556dca
commit 7d64c9e3ec
12 changed files with 57 additions and 33 deletions

View File

@@ -270,7 +270,7 @@ public:
void addNoStdIncAndNoStdLibInc()
{
commandLine.emplace_back("-nostdinc");
commandLine.emplace_back("-nostdlibinc");
commandLine.emplace_back("-nostdinc++");
}
public:

View File

@@ -161,5 +161,6 @@ public:
using ProjectPartContainers = std::vector<ProjectPartContainer>;
QDebug operator<<(QDebug debug, const ProjectPartContainer &container);
CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const ProjectPartContainer &container);
} // namespace ClangBackEnd

View File

@@ -55,6 +55,7 @@
#include <QTemporaryDir>
#include <QTimer>
#include <chrono>
#include <iostream>
#include <thread>
using namespace std::chrono_literals;
@@ -214,8 +215,20 @@ struct Data // because we have a cycle dependency
ClangBackEnd::CallDoInMainThreadAfterFinished::Yes};
};
#ifdef Q_OS_WIN
static void messageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg)
{
std::wcout << msg.toStdWString() << std::endl;
if (type == QtFatalMsg)
abort();
}
#endif
int main(int argc, char *argv[])
{
#ifdef Q_OS_WIN
qInstallMessageHandler(messageOutput);
#endif
try {
QCoreApplication::setOrganizationName(QStringLiteral("QtProject"));
QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org"));

View File

@@ -58,6 +58,7 @@ public:
auto &preprocessor = compilerInstance.getPreprocessor();
preprocessor.SetSuppressIncludeNotFoundError(true);
preprocessor.SetMacroExpansionOnlyInDirectives();
auto macroPreprocessorCallbacks = new CollectBuildDependencyPreprocessorCallbacks(
m_buildDependency,

View File

@@ -39,6 +39,7 @@
#include <sqliteexception.h>
#include <chrono>
#include <iostream>
using namespace std::chrono_literals;
@@ -97,8 +98,20 @@ struct Data // because we have a cycle dependency
SymbolIndexing symbolIndexing{database, filePathCache, generatedFiles, [&] (int progress, int total) { clangCodeModelServer.setProgress(progress, total); }};
};
#ifdef Q_OS_WIN
static void messageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg)
{
std::wcout << msg.toStdWString() << std::endl;
if (type == QtFatalMsg)
abort();
}
#endif
int main(int argc, char *argv[])
{
#ifdef Q_OS_WIN
qInstallMessageHandler(messageOutput);
#endif
try {
QCoreApplication::setOrganizationName(QStringLiteral("QtProject"));
QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org"));

View File

@@ -95,8 +95,6 @@ public:
bool isClean() const;
private:
RefactoringCompilationDatabase m_compilationDatabase;
std::vector<FileContent> m_fileContents;

View File

@@ -341,12 +341,14 @@ public:
m_database};
mutable ReadStatement m_getProjectPartArtefactsBySourceId{
"SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, "
"projectIncludeSearchPaths, projectPartId FROM projectParts WHERE projectPartId = (SELECT "
"projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension "
"FROM projectParts WHERE projectPartId = (SELECT "
"projectPartId FROM projectPartsSources WHERE sourceId = ?)",
m_database};
mutable ReadStatement m_getProjectPartArtefactsByProjectPartName{
"SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, "
"projectIncludeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?",
"projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension "
"FROM projectParts WHERE projectPartName = ?",
m_database};
mutable ReadStatement m_getPrecompiledHeader{
"SELECT projectPchPath, projectPchBuildTime FROM precompiledHeaders WHERE projectPartId = ?",

View File

@@ -68,7 +68,8 @@ public:
bool isAlreadyParsed(clang::FileID fileId)
{
const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID(fileId);
if (!fileEntry)
return false;
return m_sourcesManager.alreadyParsed(filePathId(fileEntry),
fileEntry->getModificationTime());
}

View File

@@ -435,9 +435,7 @@ TEST_F(BuildDependencyCollector, CollectUsedMacrosWithExternalDefine)
ElementsAre(Eq(UsedMacro{"DEFINED", fileId}),
Eq(UsedMacro{"IF_DEFINE", fileId}),
Eq(UsedMacro{"__clang__", fileId}),
Eq(UsedMacro{"CLASS_EXPORT", fileId}),
Eq(UsedMacro{"IF_NOT_DEFINE", fileId}),
Eq(UsedMacro{"MACRO_EXPANSION", fileId}),
Eq(UsedMacro{"COMPILER_ARGUMENT", fileId})));
}
@@ -452,9 +450,7 @@ TEST_F(BuildDependencyCollector, CollectUsedMacrosWithoutExternalDefine)
ElementsAre(Eq(UsedMacro{"DEFINED", fileId}),
Eq(UsedMacro{"IF_DEFINE", fileId}),
Eq(UsedMacro{"__clang__", fileId}),
Eq(UsedMacro{"CLASS_EXPORT", fileId}),
Eq(UsedMacro{"IF_NOT_DEFINE", fileId}),
Eq(UsedMacro{"MACRO_EXPANSION", fileId}),
Eq(UsedMacro{"COMPILER_ARGUMENT", fileId})));
}
@@ -639,7 +635,6 @@ TEST_F(BuildDependencyCollector, Create)
SourceType::TopProjectInclude))),
Field(&BuildDependency::usedMacros,
UnorderedElementsAre(
UsedMacro{"DEFINE", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")},
UsedMacro{"IFDEF", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")},
UsedMacro{"DEFINED",
id(TESTDATA_DIR "/builddependencycollector/project/macros.h")})),

View File

@@ -136,7 +136,7 @@ TYPED_TEST(CommandLineBuilder, CTask)
ASSERT_THAT(
builder.commandLine,
ElementsAre("clang", "-x", "c-header", "-std=c11", "-nostdinc", "-nostdlibinc", "/source/file.c"));
ElementsAre("clang", "-x", "c-header", "-std=c11", "-nostdinc", "-nostdinc++", "/source/file.c"));
}
TYPED_TEST(CommandLineBuilder, ObjectiveCTask)
@@ -153,7 +153,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCTask)
"objective-c-header",
"-std=c11",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"/source/file.c"));
}
@@ -170,7 +170,7 @@ TYPED_TEST(CommandLineBuilder, CppTask)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"/source/file.cpp"));
}
@@ -188,7 +188,7 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppTask)
"objective-c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"/source/file.cpp"));
}
@@ -420,7 +420,7 @@ TYPED_TEST(CommandLineBuilder, IncludesOrder)
"c++-header",
"-std=c++11",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-I",
"/include/foo",
"-I",
@@ -441,7 +441,7 @@ TYPED_TEST(CommandLineBuilder, EmptySourceFile)
Builder<TypeParam> builder{this->emptyProjectInfo, {}, {}};
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++", "-x", "c++-header", "-std=c++98", "-nostdinc", "-nostdlibinc"));
ElementsAre("clang++", "-x", "c++-header", "-std=c++98", "-nostdinc", "-nostdinc++"));
}
TYPED_TEST(CommandLineBuilder, SourceFile)
@@ -454,7 +454,7 @@ TYPED_TEST(CommandLineBuilder, SourceFile)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"/source/file.cpp"));
}
@@ -469,7 +469,7 @@ TYPED_TEST(CommandLineBuilder, EmptyOutputFile)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"/source/file.cpp"));
}
@@ -483,7 +483,7 @@ TYPED_TEST(CommandLineBuilder, OutputFile)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-o",
"/output/file.o",
"/source/file.cpp"));
@@ -499,7 +499,7 @@ TYPED_TEST(CommandLineBuilder, IncludePchPath)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-Xclang",
"-include-pch",
"-Xclang",
@@ -521,7 +521,7 @@ TYPED_TEST(CommandLineBuilder, CompilerMacros)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DER=2",
"-DYI=1"));
}

View File

@@ -157,7 +157,7 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArguments)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-I",
TESTDATA_DIR "/builddependencycollector/project",
"-isystem",
@@ -183,7 +183,7 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-I",
TESTDATA_DIR "/builddependencycollector/project",
"-isystem",

View File

@@ -269,7 +269,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
"c++-header",
"-std=c++14",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
@@ -299,7 +299,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl
"c++-header",
"-std=c++14",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
@@ -332,7 +332,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInC
"c++-header",
"-std=c++14",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
@@ -512,7 +512,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact)
"c++-header",
"-std=c++14",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
@@ -564,7 +564,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact)
"c++-header",
"-std=c++14",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
@@ -620,7 +620,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
"c++-header",
"-std=c++14",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
@@ -682,7 +682,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
"c++-header",
"-std=c++14",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
@@ -717,7 +717,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
"c++-header",
"-std=c++14",
"-nostdinc",
"-nostdlibinc",
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",