Stop exporting clangTesting library?

clangTesting is a few helpers used in clang unittests.
It’s currently set up as a public clang library like any other: it’s part of libclang-cpp.so, debian provides /usr/lib/llvm-13/include/clang/testing/TestClangConfig.h on my system, etc.
I don’t think this was particularly intended or useful (though it could conceivably be used).

I’d like to remove this from the public libraries, and have it been an in-tree unittest helper only. Mechanically, this means making it an add_llvm_library(... BUILDTREE_ONLY) instead of an add_clang_library(), and only building it if unittests are on. This is how llvmTestingSupport works.

Any objections to this? I plan to send a patch soon and will link it here.


Immediate motivation: I’d like to add some test helpers that would depend on gtest, just as the llvmTestingSupport library does. However, the public clangd libraries can’t depend on gtest, and in fact you can do a standalone build of clangd without gtest (you can’t build the unittests, obviously).

Specifically, a helper object to parse some code and keep the AST alive, for use in AST unittests and include cleaner. We’ve used this approach in clangd to good effect.

1 Like

A patch: ⚙ D123610 [Testing] Drop clangTesting from clang's public library interface

I found some additional motivation for this: clang/unittests/ASTMatchers/ASTMatchersTest.h is a fairly general test helper, and is in fact used in other parts of the codebase! The first line of clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp is:

#include "../../clang/unittests/ASTMatchers/ASTMatchersTest.h"

If these helpers are going to be reused in this way they should be in clangTesting rather than having different subprojects reach into each others’ unittests directory to grab header-only libraries. But this file depends on gtest so it also can’t be moved there without this change.

I believe we do not ship our version of gtest, so this all makes sense to me–useless to anyway who isn’t building in-tree anyway.