[PATCH] D89709: [clang-format] Drop clangFrontend dependency for FormatTests

2020-10-20 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG66a3b9073ac1: [clang-format] Drop clangFrontend dependency 
for FormatTests (authored by arichardson).

Changed prior to commit:
  https://reviews.llvm.org/D89709?vs=299078=299302#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89709/new/

https://reviews.llvm.org/D89709

Files:
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/CleanupTest.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestComments.cpp
  clang/unittests/Format/FormatTestObjC.cpp
  clang/unittests/Format/FormatTestRawStrings.cpp
  clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
  clang/unittests/Tooling/RewriterTestContext.h

Index: clang/unittests/Tooling/RewriterTestContext.h
===
--- clang/unittests/Tooling/RewriterTestContext.h
+++ clang/unittests/Tooling/RewriterTestContext.h
@@ -18,7 +18,6 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceManager.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -26,6 +25,22 @@
 
 namespace clang {
 
+/// \brief A very simple diagnostic consumer that prints to stderr and keeps
+/// track of the number of diagnostics.
+///
+/// This avoids a dependency on clangFrontend for FormatTests.
+struct RewriterDiagnosticConsumer : public DiagnosticConsumer {
+  RewriterDiagnosticConsumer() : NumDiagnosticsSeen(0) {}
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic ) override {
+++NumDiagnosticsSeen;
+SmallString<100> OutStr;
+Info.FormatDiagnostic(OutStr);
+llvm::errs() << OutStr;
+  }
+  unsigned NumDiagnosticsSeen;
+};
+
 /// \brief A class that sets up a ready to use Rewriter.
 ///
 /// Useful in unit tests that need a Rewriter. Creates all dependencies
@@ -37,7 +52,6 @@
: DiagOpts(new DiagnosticOptions()),
  Diagnostics(IntrusiveRefCntPtr(new DiagnosticIDs),
  &*DiagOpts),
- DiagnosticPrinter(llvm::outs(), &*DiagOpts),
  InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
  OverlayFileSystem(
  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())),
@@ -113,7 +127,7 @@
 
   IntrusiveRefCntPtr DiagOpts;
   DiagnosticsEngine Diagnostics;
-  TextDiagnosticPrinter DiagnosticPrinter;
+  RewriterDiagnosticConsumer DiagnosticPrinter;
   IntrusiveRefCntPtr InMemoryFileSystem;
   IntrusiveRefCntPtr OverlayFileSystem;
   FileManager Files;
Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -8,7 +8,6 @@
 
 #include "clang/Format/Format.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "gtest/gtest.h"
 
Index: clang/unittests/Format/FormatTestRawStrings.cpp
===
--- clang/unittests/Format/FormatTestRawStrings.cpp
+++ clang/unittests/Format/FormatTestRawStrings.cpp
@@ -11,7 +11,6 @@
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -11,7 +11,6 @@
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -11,7 +11,6 @@
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11,7 +11,6 @@
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include 

[PATCH] D89709: [clang-format] Drop clangFrontend dependency for FormatTests

2020-10-20 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM, I'm for anything that speeds up the build


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89709/new/

https://reviews.llvm.org/D89709

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89709: [clang-format] Drop clangFrontend dependency for FormatTests

2020-10-19 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson created this revision.
arichardson added reviewers: klimek, MyDeveloperDay.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.
arichardson requested review of this revision.

This allows building the clang-format unit tests in only 657 ninja steps
rather than 1257 which allows for much faster incremental builds after a
git pull.

Depends on D89708 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89709

Files:
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/CleanupTest.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestComments.cpp
  clang/unittests/Format/FormatTestObjC.cpp
  clang/unittests/Format/FormatTestRawStrings.cpp
  clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
  clang/unittests/Tooling/RewriterTestContext.h

Index: clang/unittests/Tooling/RewriterTestContext.h
===
--- clang/unittests/Tooling/RewriterTestContext.h
+++ clang/unittests/Tooling/RewriterTestContext.h
@@ -18,7 +18,6 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceManager.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -26,6 +25,22 @@
 
 namespace clang {
 
+/// \brief A very simple diagnostic consumer that prints to stderr and keeps
+/// track of the number of diagnostics.
+///
+/// This avoids a dependency on clangFrontend for FormatTests.
+struct RewriterDiagnosticConsumer : public DiagnosticConsumer {
+  RewriterDiagnosticConsumer() : NumDiagnosticsSeen(0) {}
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic ) override {
+++NumDiagnosticsSeen;
+SmallString<100> OutStr;
+Info.FormatDiagnostic(OutStr);
+llvm::errs() << OutStr;
+  }
+  unsigned NumDiagnosticsSeen;
+};
+
 /// \brief A class that sets up a ready to use Rewriter.
 ///
 /// Useful in unit tests that need a Rewriter. Creates all dependencies
@@ -37,7 +52,6 @@
: DiagOpts(new DiagnosticOptions()),
  Diagnostics(IntrusiveRefCntPtr(new DiagnosticIDs),
  &*DiagOpts),
- DiagnosticPrinter(llvm::outs(), &*DiagOpts),
  InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
  OverlayFileSystem(
  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())),
@@ -113,7 +127,7 @@
 
   IntrusiveRefCntPtr DiagOpts;
   DiagnosticsEngine Diagnostics;
-  TextDiagnosticPrinter DiagnosticPrinter;
+  RewriterDiagnosticConsumer DiagnosticPrinter;
   IntrusiveRefCntPtr InMemoryFileSystem;
   IntrusiveRefCntPtr OverlayFileSystem;
   FileManager Files;
Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -8,7 +8,6 @@
 
 #include "clang/Format/Format.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "gtest/gtest.h"
 
Index: clang/unittests/Format/FormatTestRawStrings.cpp
===
--- clang/unittests/Format/FormatTestRawStrings.cpp
+++ clang/unittests/Format/FormatTestRawStrings.cpp
@@ -11,7 +11,6 @@
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -11,7 +11,6 @@
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -11,7 +11,6 @@
 #include "../Tooling/ReplacementTest.h"
 #include "FormatTestUtils.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12,7 +12,6 @@
 #include "FormatTestUtils.h"
 #include "TestLexer.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"