data: Record errors in precompiled header generation

* also records include dependencies within precompiled header file
This commit is contained in:
Eberhard Graether
2019-07-31 23:28:22 +02:00
parent 4b58bb679c
commit b35d4657d5
11 changed files with 96 additions and 23 deletions
+1 -1
View File
@@ -549,7 +549,7 @@ void Project::buildIndex(RefreshInfo info, std::shared_ptr<DialogView> dialogVie
{
if (sourceGroup->getStatus() == SOURCE_GROUP_STATUS_ENABLED)
{
preIndexTasks->addTask(sourceGroup->getPreIndexTask(dialogView));
preIndexTasks->addTask(sourceGroup->getPreIndexTask(storageProvider, dialogView));
}
}
+2 -1
View File
@@ -12,7 +12,8 @@ std::shared_ptr<IndexerCommandProvider> SourceGroup::getIndexerCommandProvider(c
return std::make_shared<MemoryIndexerCommandProvider>(getIndexerCommands(filesToIndex));
}
std::shared_ptr<Task> SourceGroup::getPreIndexTask(std::shared_ptr<DialogView> dialogView) const
std::shared_ptr<Task> SourceGroup::getPreIndexTask(
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView) const
{
return std::make_shared<TaskLambda>([]() {});
}
+3 -1
View File
@@ -15,6 +15,7 @@ class FilePathFilter;
class IndexerCommand;
class IndexerCommandProvider;
class SourceGroupSettings;
class StorageProvider;
class Task;
class SourceGroup
@@ -29,7 +30,8 @@ public:
virtual std::set<FilePath> getAllSourceFilePaths() const = 0;
virtual std::shared_ptr<IndexerCommandProvider> getIndexerCommandProvider(const std::set<FilePath>& filesToIndex) const;
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const std::set<FilePath>& filesToIndex) const = 0;
virtual std::shared_ptr<Task> getPreIndexTask(std::shared_ptr<DialogView> dialogView) const;
virtual std::shared_ptr<Task> getPreIndexTask(
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView) const;
SourceGroupType getType() const;
LanguageType getLanguage() const;
@@ -1,8 +1,18 @@
#include "GeneratePCHAction.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Serialization/ASTWriter.h"
#include "clang/Frontend/MultiplexConsumer.h"
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Serialization/ASTWriter.h>
#include <clang/Frontend/MultiplexConsumer.h>
#include "PreprocessorCallbacks.h"
GeneratePCHAction::GeneratePCHAction(
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
)
: m_client(client)
, m_canonicalFilePathCache(canonicalFilePathCache)
{}
bool GeneratePCHAction::shouldEraseOutputFiles()
{
@@ -37,3 +47,12 @@ std::unique_ptr<clang::ASTConsumer> GeneratePCHAction::CreateASTConsumer(clang::
return llvm::make_unique<clang::MultiplexConsumer>(std::move(Consumers));
}
bool GeneratePCHAction::BeginSourceFileAction(clang::CompilerInstance& compiler)
{
clang::Preprocessor& preprocessor = compiler.getPreprocessor();
preprocessor.addPPCallbacks(llvm::make_unique<PreprocessorCallbacks>(
compiler.getSourceManager(), m_client, m_canonicalFilePathCache
));
return true;
}
@@ -3,14 +3,30 @@
#include "clang/Frontend/FrontendActions.h"
class GeneratePCHAction : public clang::GeneratePCHAction
class ParserClient;
class CanonicalFilePathCache;
class GeneratePCHAction
: public clang::GeneratePCHAction
{
public:
explicit GeneratePCHAction(
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
);
protected:
// this method has been overridden to prevent erasing output file independently of provided flags
bool shouldEraseOutputFiles() override;
// this method has been overridden to always set "AllowASTWithErrors" of the PCHGenerator to "true"
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef InFile) override;
bool BeginSourceFileAction(clang::CompilerInstance& compiler) override;
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
};
#endif // GENERATE_PCH_ACTION_H
+3 -2
View File
@@ -151,7 +151,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
return getIndexerCommandProvider(filesToIndex)->consumeAllCommands();
}
std::shared_ptr<Task> SourceGroupCxxCdb::getPreIndexTask(std::shared_ptr<DialogView> dialogView) const
std::shared_ptr<Task> SourceGroupCxxCdb::getPreIndexTask(
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView) const
{
if (m_settings->getPchInputFilePath().empty())
{
@@ -213,7 +214,7 @@ std::shared_ptr<Task> SourceGroupCxxCdb::getPreIndexTask(std::shared_ptr<DialogV
utility::append(compilerFlags, m_settings->getPchFlags());
return utility::createBuildPchTask(m_settings.get(), compilerFlags, dialogView);
return utility::createBuildPchTask(m_settings.get(), compilerFlags, storageProvider, dialogView);
}
std::shared_ptr<SourceGroupSettings> SourceGroupCxxCdb::getSourceGroupSettings()
+2 -1
View File
@@ -27,7 +27,8 @@ public:
std::set<FilePath> getAllSourceFilePaths(std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb) const;
std::shared_ptr<IndexerCommandProvider> getIndexerCommandProvider(const std::set<FilePath>& filesToIndex) const override;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const std::set<FilePath>& filesToIndex) const override;
std::shared_ptr<Task> getPreIndexTask(std::shared_ptr<DialogView> dialogView) const override;
std::shared_ptr<Task> getPreIndexTask(
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView) const override;
private:
std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() override;
+3 -2
View File
@@ -112,7 +112,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxEmpty::getIndexerComm
return getIndexerCommandProvider(filesToIndex)->consumeAllCommands();
}
std::shared_ptr<Task> SourceGroupCxxEmpty::getPreIndexTask(std::shared_ptr<DialogView> dialogView) const
std::shared_ptr<Task> SourceGroupCxxEmpty::getPreIndexTask(
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView) const
{
const SourceGroupSettingsWithCxxPchOptions* pchSettings =
dynamic_cast<const SourceGroupSettingsWithCxxPchOptions*>(m_settings.get());
@@ -134,7 +135,7 @@ std::shared_ptr<Task> SourceGroupCxxEmpty::getPreIndexTask(std::shared_ptr<Dialo
utility::append(compilerFlags, pchSettings->getPchFlags());
}
return utility::createBuildPchTask(m_settings.get(), compilerFlags, dialogView);
return utility::createBuildPchTask(m_settings.get(), compilerFlags, storageProvider, dialogView);
}
std::shared_ptr<SourceGroupSettings> SourceGroupCxxEmpty::getSourceGroupSettings()
+2 -1
View File
@@ -17,7 +17,8 @@ public:
std::set<FilePath> getAllSourceFilePaths() const override;
std::shared_ptr<IndexerCommandProvider> getIndexerCommandProvider(const std::set<FilePath>& filesToIndex) const override;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const std::set<FilePath>& filesToIndex) const override;
std::shared_ptr<Task> getPreIndexTask(std::shared_ptr<DialogView> dialogView) const override;
std::shared_ptr<Task> getPreIndexTask(
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView) const override;
private:
std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() override;
+38 -9
View File
@@ -1,23 +1,31 @@
#include "utilitySourceGroupCxx.h"
#include "CanonicalFilePathCache.h"
#include "CxxCompilationDatabaseSingle.h"
#include "CxxDiagnosticConsumer.h"
#include "CxxParser.h"
#include "DialogView.h"
#include "FilePathFilter.h"
#include "FileRegister.h"
#include "FileSystem.h"
#include "GeneratePCHAction.h"
#include "logging.h"
#include "ParserClientImpl.h"
#include "SingleFrontendActionFactory.h"
#include "SourceGroupSettingsCxx.h"
#include "SourceGroupSettingsWithCxxPchOptions.h"
#include "StorageProvider.h"
#include "TaskLambda.h"
#include "utility.h"
namespace utility
{
std::shared_ptr<Task> createBuildPchTask(
const SourceGroupSettingsCxx* settings, std::vector<std::wstring> compilerFlags, std::shared_ptr<DialogView> dialogView)
const SourceGroupSettingsCxx* settings, std::vector<std::wstring> compilerFlags,
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView)
{
const SourceGroupSettingsWithCxxPchOptions* pchSettings = dynamic_cast<const SourceGroupSettingsWithCxxPchOptions*>(settings);
const SourceGroupSettingsWithCxxPchOptions* pchSettings =
dynamic_cast<const SourceGroupSettingsWithCxxPchOptions*>(settings);
if (!pchSettings)
{
return std::make_shared<TaskLambda>([](){});
@@ -37,7 +45,8 @@ namespace utility
return std::make_shared<TaskLambda>([]() {});
}
const FilePath pchOutputFilePath = pchDependenciesDirectoryPath.getConcatenated(pchInputFilePath.fileName()).replaceExtension(L"pch");
const FilePath pchOutputFilePath =
pchDependenciesDirectoryPath.getConcatenated(pchInputFilePath.fileName()).replaceExtension(L"pch");
compilerFlags.push_back(pchInputFilePath.wstr());
compilerFlags.push_back(L"-emit-pch");
@@ -45,7 +54,7 @@ namespace utility
compilerFlags.push_back(pchOutputFilePath.wstr());
return std::make_shared<TaskLambda>(
[dialogView, pchInputFilePath, pchOutputFilePath, compilerFlags]()
[dialogView, storageProvider, pchInputFilePath, pchOutputFilePath, compilerFlags]()
{
dialogView->showUnknownProgressDialog(L"Preparing Indexing", L"Processing Precompiled Headers");
LOG_INFO(
@@ -60,24 +69,43 @@ namespace utility
FileSystem::createDirectory(pchOutputFilePath.getParentDirectory());
}
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
std::shared_ptr<ParserClientImpl> client = std::make_shared<ParserClientImpl>(storage.get());
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(
pchInputFilePath, std::set<FilePath>{ pchInputFilePath }, std::set<FilePathFilter>{});
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache =
std::make_shared<CanonicalFilePathCache>(fileRegister);
clang::tooling::CompileCommand pchCommand;
pchCommand.Filename = utility::encodeToUtf8(pchInputFilePath.fileName());
pchCommand.Directory = pchOutputFilePath.getParentDirectory().str();
// DON'T use "-fsyntax-only" here because it will cause the output file to be erased
pchCommand.CommandLine = utility::concat({ "clang-tool" }, CxxParser::getCommandlineArgumentsEssential(compilerFlags));
pchCommand.CommandLine =
utility::concat({ "clang-tool" }, CxxParser::getCommandlineArgumentsEssential(compilerFlags));
CxxCompilationDatabaseSingle compilationDatabase(pchCommand);
clang::tooling::ClangTool tool(compilationDatabase, std::vector<std::string>(1, utility::encodeToUtf8(pchInputFilePath.wstr())));
GeneratePCHAction* action = new GeneratePCHAction();
clang::tooling::ClangTool tool(compilationDatabase, { utility::encodeToUtf8(pchInputFilePath.wstr()) });
GeneratePCHAction* action = new GeneratePCHAction(client, canonicalFilePathCache);
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
CxxDiagnosticConsumer diagnostics(
llvm::errs(), &*options, client, canonicalFilePathCache, pchInputFilePath, true);
tool.setDiagnosticConsumer(&diagnostics);
tool.clearArgumentsAdjusters();
tool.run(new SingleFrontendActionFactory(action));
storageProvider->insert(storage);
}
);
}
std::vector<std::wstring> getIncludePchFlags(const SourceGroupSettingsCxx* settings)
{
const SourceGroupSettingsWithCxxPchOptions* pchSettings = dynamic_cast<const SourceGroupSettingsWithCxxPchOptions*>(settings);
const SourceGroupSettingsWithCxxPchOptions* pchSettings =
dynamic_cast<const SourceGroupSettingsWithCxxPchOptions*>(settings);
if (pchSettings)
{
const FilePath pchInputFilePath = pchSettings->getPchInputFilePathExpandedAndAbsolute();
@@ -85,7 +113,8 @@ namespace utility
if (!pchInputFilePath.empty() && !pchDependenciesDirectoryPath.empty())
{
const FilePath pchOutputFilePath = pchDependenciesDirectoryPath.getConcatenated(pchInputFilePath.fileName()).replaceExtension(L"pch");
const FilePath pchOutputFilePath =
pchDependenciesDirectoryPath.getConcatenated(pchInputFilePath.fileName()).replaceExtension(L"pch");
return {
L"-fallow-pch-with-compiler-errors",
L"-include-pch",
+3 -1
View File
@@ -7,12 +7,14 @@
class DialogView;
class SourceGroupSettingsCxx;
class StorageProvider;
class Task;
namespace utility
{
std::shared_ptr<Task> createBuildPchTask(
const SourceGroupSettingsCxx* settings, std::vector<std::wstring> compilerFlags, std::shared_ptr<DialogView> dialogView);
const SourceGroupSettingsCxx* settings, std::vector<std::wstring> compilerFlags,
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView);
std::vector<std::wstring> getIncludePchFlags(const SourceGroupSettingsCxx* settings);
}