Skip to content

Commit

Permalink
[clang-format] Drop clangFrontend dependency for FormatTests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arichardson committed Oct 20, 2020
1 parent a221475 commit 66a3b90
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion clang/unittests/Format/CMakeLists.txt
Expand Up @@ -27,7 +27,6 @@ clang_target_link_libraries(FormatTests
PRIVATE
clangBasic
clangFormat
clangFrontend
clangRewrite
clangToolingCore
)
1 change: 0 additions & 1 deletion clang/unittests/Format/CleanupTest.cpp
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/Format/FormatTest.cpp
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/Format/FormatTestComments.cpp
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/Format/FormatTestObjC.cpp
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/Format/FormatTestRawStrings.cpp
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
Expand Up @@ -8,7 +8,6 @@

#include "clang/Format/Format.h"

#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "llvm/Support/Debug.h"
#include "gtest/gtest.h"

Expand Down
20 changes: 17 additions & 3 deletions clang/unittests/Tooling/RewriterTestContext.h
Expand Up @@ -18,14 +18,29 @@
#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"
#include "llvm/Support/raw_ostream.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
Expand All @@ -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())),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 66a3b90

Please sign in to comment.