[PATCH] D108982: [clang][deps] Avoid creating diagnostic serialization file, add test
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 2 06:57:02 PDT 2021
jansvoboda11 updated this revision to Diff 370260.
jansvoboda11 added a comment.
Split out tests into a separate patch in order to avoid temporary regression.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108982/new/
https://reviews.llvm.org/D108982
Files:
clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===================================================================
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -269,8 +269,6 @@
DependencyScanningWorker::DependencyScanningWorker(
DependencyScanningService &Service)
: Format(Service.getFormat()) {
- DiagOpts = new DiagnosticOptions();
-
PCHContainerOps = std::make_shared<PCHContainerOperations>();
PCHContainerOps->registerReader(
std::make_unique<ObjectFilePCHContainerReader>());
@@ -290,16 +288,20 @@
Files = new FileManager(FileSystemOptions(), RealFS);
}
-static llvm::Error runWithDiags(
- DiagnosticOptions *DiagOpts,
- llvm::function_ref<bool(DiagnosticConsumer &DC)> BodyShouldSucceed) {
+static llvm::Error
+runWithDiags(DiagnosticOptions *DiagOpts,
+ llvm::function_ref<bool(DiagnosticConsumer &, DiagnosticOptions &)>
+ BodyShouldSucceed) {
+ // Avoid serializing diagnostics.
+ DiagOpts->DiagnosticSerializationFile.clear();
+
// Capture the emitted diagnostics and report them to the client
// in the case of a failure.
std::string DiagnosticOutput;
llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
TextDiagnosticPrinter DiagPrinter(DiagnosticsOS, DiagOpts);
- if (BodyShouldSucceed(DiagPrinter))
+ if (BodyShouldSucceed(DiagPrinter, *DiagOpts))
return llvm::Error::success();
return llvm::make_error<llvm::StringError>(DiagnosticsOS.str(),
llvm::inconvertibleErrorCode());
@@ -313,15 +315,22 @@
llvm::IntrusiveRefCntPtr<FileManager> CurrentFiles =
Files ? Files : new FileManager(FileSystemOptions(), RealFS);
- return runWithDiags(DiagOpts.get(), [&](DiagnosticConsumer &DC) {
- DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS,
- PPSkipMappings.get(), Format);
- // Create an invocation that uses the underlying file system to ensure that
- // any file system requests that are made by the driver do not go through
- // the dependency scanning filesystem.
- ToolInvocation Invocation(CommandLine, &Action, CurrentFiles.get(),
- PCHContainerOps);
- Invocation.setDiagnosticConsumer(&DC);
- return Invocation.run();
- });
+ std::vector<const char *> CCommandLine(CommandLine.size(), nullptr);
+ llvm::transform(CommandLine, CCommandLine.begin(),
+ [](const std::string &Str) { return Str.c_str(); });
+
+ return runWithDiags(
+ CreateAndPopulateDiagOpts(CCommandLine).release(),
+ [&](DiagnosticConsumer &DC, DiagnosticOptions &DiagOpts) {
+ DependencyScanningAction Action(WorkingDirectory, Consumer, DepFS,
+ PPSkipMappings.get(), Format);
+ // Create an invocation that uses the underlying file system to ensure
+ // that any file system requests that are made by the driver do not go
+ // through the dependency scanning filesystem.
+ ToolInvocation Invocation(CommandLine, &Action, CurrentFiles.get(),
+ PCHContainerOps);
+ Invocation.setDiagnosticConsumer(&DC);
+ Invocation.setDiagnosticOptions(&DiagOpts);
+ return Invocation.run();
+ });
}
Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
===================================================================
--- clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -66,7 +66,6 @@
DependencyConsumer &Consumer);
private:
- IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
std::shared_ptr<PCHContainerOperations> PCHContainerOps;
std::unique_ptr<ExcludedPreprocessorDirectiveSkipMapping> PPSkipMappings;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108982.370260.patch
Type: text/x-patch
Size: 4011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210902/b213d863/attachment-0001.bin>
More information about the cfe-commits
mailing list