[clang-format] Drop clangFrontend dependency for FormatTests
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Mon, 19 Oct 2020 16:14:01 +0000 (17:14 +0100)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Tue, 20 Oct 2020 09:13:28 +0000 (10:13 +0100)
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.

Reviewed By: MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D89709

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 d0cc2ca..472e6ee 100644 (file)
@@ -27,7 +27,6 @@ clang_target_link_libraries(FormatTests
   PRIVATE
   clangBasic
   clangFormat
-  clangFrontend
   clangRewrite
   clangToolingCore
   )
index 9649b98..dc149b5 100644 (file)
@@ -9,7 +9,6 @@
 #include "clang/Format/Format.h"
 
 #include "../Tooling/ReplacementTest.h"
-#include "../Tooling/RewriterTestContext.h"
 #include "clang/Tooling/Core/Replacement.h"
 
 #include "gtest/gtest.h"
index 1bdd706..be9c843 100644 (file)
@@ -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 34d6b62..95afb17 100644 (file)
@@ -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 21b8d47..a34a083 100644 (file)
@@ -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 3149035..6310fe5 100644 (file)
@@ -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 463afa6..3340e02 100644 (file)
@@ -8,7 +8,6 @@
 
 #include "clang/Format/Format.h"
 
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "llvm/Support/Debug.h"
 #include "gtest/gtest.h"
 
index 99f7a11..ae2d2ba 100644 (file)
@@ -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"
 
 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 &Info) 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 @@ class RewriterTestContext {
        : DiagOpts(new DiagnosticOptions()),
          Diagnostics(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
                      &*DiagOpts),
-         DiagnosticPrinter(llvm::outs(), &*DiagOpts),
          InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
          OverlayFileSystem(
              new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())),
@@ -113,7 +127,7 @@ class RewriterTestContext {
 
   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
   DiagnosticsEngine Diagnostics;
-  TextDiagnosticPrinter DiagnosticPrinter;
+  RewriterDiagnosticConsumer DiagnosticPrinter;
   IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem;
   IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem;
   FileManager Files;