From 66a3b9073ac116f0ee39baf625c733abe18140e5 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 19 Oct 2020 17:14:01 +0100 Subject: [PATCH] [clang-format] Drop clangFrontend dependency for FormatTests 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 | 1 - clang/unittests/Format/CleanupTest.cpp | 1 - clang/unittests/Format/FormatTest.cpp | 1 - clang/unittests/Format/FormatTestComments.cpp | 1 - clang/unittests/Format/FormatTestObjC.cpp | 1 - .../unittests/Format/FormatTestRawStrings.cpp | 1 - .../Format/NamespaceEndCommentsFixerTest.cpp | 1 - clang/unittests/Tooling/RewriterTestContext.h | 20 ++++++++++++++++--- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/clang/unittests/Format/CMakeLists.txt b/clang/unittests/Format/CMakeLists.txt index d0cc2cae179f17..472e6eec40af44 100644 --- a/clang/unittests/Format/CMakeLists.txt +++ b/clang/unittests/Format/CMakeLists.txt @@ -27,7 +27,6 @@ clang_target_link_libraries(FormatTests PRIVATE clangBasic clangFormat - clangFrontend clangRewrite clangToolingCore ) diff --git a/clang/unittests/Format/CleanupTest.cpp b/clang/unittests/Format/CleanupTest.cpp index 9649b981d558d0..dc149b502bc523 100644 --- a/clang/unittests/Format/CleanupTest.cpp +++ b/clang/unittests/Format/CleanupTest.cpp @@ -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" diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 1bdd7062fbb82a..be9c8433226582 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/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 "llvm/Support/MemoryBuffer.h" #include "gtest/gtest.h" diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index 34d6b62b26c84a..95afb17114a2b0 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/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" diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp index 21b8d4701271ac..a34a0832286b87 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/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" diff --git a/clang/unittests/Format/FormatTestRawStrings.cpp b/clang/unittests/Format/FormatTestRawStrings.cpp index 31490355468e41..6310fe510fd3b1 100644 --- a/clang/unittests/Format/FormatTestRawStrings.cpp +++ b/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" diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp index 463afa67e8b028..3340e02f4a1cc5 100644 --- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/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" diff --git a/clang/unittests/Tooling/RewriterTestContext.h b/clang/unittests/Tooling/RewriterTestContext.h index 99f7a11dca98ae..ae2d2baa0fdcc3 100644 --- a/clang/unittests/Tooling/RewriterTestContext.h +++ b/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 &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(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 DiagOpts; DiagnosticsEngine Diagnostics; - TextDiagnosticPrinter DiagnosticPrinter; + RewriterDiagnosticConsumer DiagnosticPrinter; IntrusiveRefCntPtr InMemoryFileSystem; IntrusiveRefCntPtr OverlayFileSystem; FileManager Files;