llvm.org GIT mirror llvm / de65999
[gn build] Make `ninja check-clang` also run Clang's unit tests Also add a build file for clang/lib/ASTMatchers/Dynamic, which is only needed by tests (and clang/tools/extra). Also make llvm/utils/gn/build/sync_source_lists_from_cmake.py check that every CMakeLists.txt file below {lld,clang}/unittests has a corresponding BUILD.gn file, so we notice if new test binaries get added (since the failure mode for missing GN build files for tests is just the tests silently not running in the GN build). Also add a unittest() macro for defining unit test targets, and add a lengthy comment there about where the unit test binaries go and why. With this, the build files for //clang are complete. Differential Revision: https://reviews.llvm.org/D56116 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350171 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 9 months ago
26 changed file(s) with 540 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
11 # Targets can opt out of a config by removing it from their local configs list.
22 # If you're adding global flags and don't need targets to be able to opt out,
33 # add the flags to compiler_defaults, not to a new config.
4 _shared_binary_target_configs = [
4 shared_binary_target_configs = [
55 "//llvm/utils/gn/build:compiler_defaults",
66 "//llvm/utils/gn/build:llvm_code",
77 "//llvm/utils/gn/build:warn_covered_switch_default",
99
1010 # Apply that default list to the binary target types.
1111 set_defaults("executable") {
12 configs = _shared_binary_target_configs
12 configs = shared_binary_target_configs
1313 }
1414 set_defaults("loadable_module") {
15 configs = _shared_binary_target_configs
15 configs = shared_binary_target_configs
1616 }
1717 set_defaults("static_library") {
18 configs = _shared_binary_target_configs
18 configs = shared_binary_target_configs
1919 }
2020 set_defaults("shared_library") {
21 configs = _shared_binary_target_configs
21 configs = shared_binary_target_configs
2222 }
2323 set_defaults("source_set") {
24 configs = _shared_binary_target_configs
24 configs = shared_binary_target_configs
2525 }
2626
2727 if (host_os == "win") {
33
44 For each BUILD.gn file in the tree, checks if the list of cpp files in
55 it is identical to the list of cpp files in the corresponding CMakeLists.txt
6 file, and prints the difference if not."""
6 file, and prints the difference if not.
7
8 Also checks that each CMakeLists.txt file below unittests/ folders that define
9 binaries have corresponding BUILD.gn files.
10 """
711
812 from __future__ import print_function
913
1115 import re
1216 import subprocess
1317
14 def main():
18
19 def sync_source_lists():
1520 gn_files = subprocess.check_output(
1621 ['git', 'ls-files', '*BUILD.gn']).splitlines()
1722
4954 print('remove:\n' + '\n'.join(remove))
5055 print()
5156
57
58 def sync_unittests():
59 checked = [ 'clang', 'lld' ]
60 for c in checked:
61 for root, _, _ in os.walk(os.path.join(c, 'unittests')):
62 cmake_file = os.path.join(root, 'CMakeLists.txt')
63 if not os.path.exists(cmake_file):
64 continue
65 gn_file = os.path.join('llvm/utils/gn/secondary', root, 'BUILD.gn')
66 if not os.path.exists(gn_file):
67 print('missing GN file %s for unittest CMake file %s' %
68 (gn_file, cmake_file))
69
70
71 def main():
72 sync_source_lists()
73 sync_unittests()
74
75
5276 if __name__ == '__main__':
5377 main()
0 static_library("Dynamic") {
1 output_name = "clangDynamicASTMatchers"
2 configs += [ "//llvm/utils/gn/build:clang_code" ]
3 deps = [
4 "//clang/lib/AST",
5 "//clang/lib/ASTMatchers",
6 "//clang/lib/Basic",
7 "//llvm/lib/Support",
8 ]
9 sources = [
10 "Diagnostics.cpp",
11 "Parser.cpp",
12 "Registry.cpp",
13 "VariantValue.cpp",
14 ]
15 }
124124 "//clang/tools/clang-rename",
125125 "//clang/tools/diagtool",
126126 "//clang/tools/driver:symlinks",
127 "//clang/unittests",
127128 "//clang/utils/TableGen:clang-tblgen",
128129 "//clang/utils/hmaptool",
129130 "//llvm/tools/llc",
158159 ]
159160 }
160161
161 # FIXME: dep on "//clang/unittests" once it exists
162162 # FIXME: clang_build_examples
163163 testonly = true
164164 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("ASTTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/ASTMatchers",
7 "//clang/lib/Analysis",
8 "//clang/lib/Basic",
9 "//clang/lib/Frontend",
10 "//clang/lib/Tooling",
11 "//llvm/lib/Support",
12 ]
13 sources = [
14 "ASTContextParentMapTest.cpp",
15 "ASTImporterTest.cpp",
16 "ASTTypeTraitsTest.cpp",
17 "ASTVectorTest.cpp",
18 "CommentLexer.cpp",
19 "CommentParser.cpp",
20 "CommentTextTest.cpp",
21 "DataCollectionTest.cpp",
22 "DeclPrinterTest.cpp",
23 "DeclTest.cpp",
24 "EvaluateAsRValueTest.cpp",
25 "ExternalASTSourceTest.cpp",
26 "Language.cpp",
27 "NamedDeclPrinterTest.cpp",
28 "SourceLocationTest.cpp",
29 "StmtPrinterTest.cpp",
30 "StructuralEquivalenceTest.cpp",
31 ]
32 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("ASTMatchersTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/ASTMatchers",
7 "//clang/lib/Basic",
8 "//clang/lib/Frontend",
9 "//clang/lib/Tooling",
10 "//llvm/lib/Support",
11 ]
12 sources = [
13 "ASTMatchersInternalTest.cpp",
14 "ASTMatchersNarrowingTest.cpp",
15 "ASTMatchersNodeTest.cpp",
16 "ASTMatchersTraversalTest.cpp",
17 ]
18 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("DynamicASTMatchersTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/ASTMatchers",
7 "//clang/lib/ASTMatchers/Dynamic",
8 "//clang/lib/Basic",
9 "//clang/lib/Frontend",
10 "//clang/lib/Tooling",
11 "//llvm/lib/Support",
12 ]
13 sources = [
14 "ParserTest.cpp",
15 "RegistryTest.cpp",
16 "VariantValueTest.cpp",
17 ]
18 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("ClangAnalysisTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/ASTMatchers",
7 "//clang/lib/Analysis",
8 "//clang/lib/Basic",
9 "//clang/lib/Frontend",
10 "//clang/lib/Tooling",
11 "//llvm/lib/Support",
12 ]
13 sources = [
14 "CFGTest.cpp",
15 "CloneDetectionTest.cpp",
16 "ExprMutationAnalyzerTest.cpp",
17 ]
18 }
0 import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
1
2 group("unittests") {
3 deps = [
4 "AST:ASTTests",
5 "ASTMatchers:ASTMatchersTests",
6 "ASTMatchers/Dynamic:DynamicASTMatchersTests",
7 "Basic:BasicTests",
8 "CodeGen:ClangCodeGenTests",
9 "CrossTU:CrossTUTests",
10 "Driver:ClangDriverTests",
11 "Format:FormatTests",
12 "Index:IndexTests",
13 "Lex:LexTests",
14 "Rename:ClangRenameTests",
15 "Rewrite:RewriteTests",
16 "Sema:SemaTests",
17 "Tooling:ToolingTests",
18 ]
19 if (clang_enable_static_analyzer) {
20 deps += [
21 "Analysis:ClangAnalysisTests",
22 "Frontend:FrontendTests",
23 "StaticAnalyzer:StaticAnalysisTests",
24 ]
25 }
26 if (host_os != "win") {
27 # FIXME: libclang unit tests are disabled on Windows due
28 # to failures, mostly in libclang.VirtualFileOverlay_*.
29 # FIXME: Also, the executable can't find libclang.dll since that's
30 # in a different directory.
31 deps += [ "libclang:libclangTests" ]
32 }
33 testonly = true
34 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("BasicTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/Basic",
6 "//clang/lib/Lex",
7 "//llvm/lib/Support",
8 ]
9 sources = [
10 "CharInfoTest.cpp",
11 "DiagnosticTest.cpp",
12 "FileManagerTest.cpp",
13 "FixedPointTest.cpp",
14 "MemoryBufferCacheTest.cpp",
15 "SourceManagerTest.cpp",
16 ]
17 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("ClangCodeGenTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/Basic",
7 "//clang/lib/CodeGen",
8 "//clang/lib/Frontend",
9 "//clang/lib/Lex",
10 "//clang/lib/Parse",
11 "//llvm/lib/IR",
12 "//llvm/lib/Support",
13 ]
14 sources = [
15 "BufferSourceTest.cpp",
16 "CodeGenExternalTest.cpp",
17 "IncrementalProcessingTest.cpp",
18 "TBAAMetadataTest.cpp",
19 ]
20 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("CrossTUTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/Basic",
7 "//clang/lib/CrossTU",
8 "//clang/lib/Frontend",
9 "//clang/lib/Tooling",
10 "//llvm/lib/Support",
11 "//llvm/lib/Target:TargetsToBuild",
12 ]
13 sources = [
14 "CrossTranslationUnitTest.cpp",
15 ]
16 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("ClangDriverTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/Basic",
6 "//clang/lib/Driver",
7 "//llvm/lib/Option",
8 "//llvm/lib/Support",
9 "//llvm/lib/Target:TargetsToBuild",
10 ]
11 sources = [
12 "DistroTest.cpp",
13 "ModuleCacheTest.cpp",
14 "MultilibTest.cpp",
15 "ToolChainTest.cpp",
16 ]
17 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("FormatTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/Basic",
6 "//clang/lib/Format",
7 "//clang/lib/Frontend",
8 "//clang/lib/Rewrite",
9 "//clang/lib/Tooling/Core",
10 "//llvm/lib/Support",
11 ]
12 sources = [
13 "CleanupTest.cpp",
14 "FormatTest.cpp",
15 "FormatTestComments.cpp",
16 "FormatTestJS.cpp",
17 "FormatTestJava.cpp",
18 "FormatTestObjC.cpp",
19 "FormatTestProto.cpp",
20 "FormatTestRawStrings.cpp",
21 "FormatTestSelective.cpp",
22 "FormatTestTableGen.cpp",
23 "FormatTestTextProto.cpp",
24 "NamespaceEndCommentsFixerTest.cpp",
25 "SortImportsTestJS.cpp",
26 "SortImportsTestJava.cpp",
27 "SortIncludesTest.cpp",
28 "UsingDeclarationsSorterTest.cpp",
29 ]
30 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("FrontendTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/Basic",
7 "//clang/lib/CodeGen",
8 "//clang/lib/Frontend",
9 "//clang/lib/FrontendTool",
10 "//clang/lib/Lex",
11 "//clang/lib/Sema",
12 "//llvm/lib/Support",
13 ]
14 sources = [
15 "ASTUnitTest.cpp",
16 "CodeGenActionTest.cpp",
17 "CompilerInstanceTest.cpp",
18 "FixedPointString.cpp",
19 "FrontendActionTest.cpp",
20 "OutputStreamTest.cpp",
21 "PCHPreambleTest.cpp",
22 "ParsedSourceLocationTest.cpp",
23 ]
24 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("IndexTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/Basic",
7 "//clang/lib/Frontend",
8 "//clang/lib/Index",
9 "//clang/lib/Lex",
10 "//clang/lib/Serialization",
11 "//clang/lib/Tooling",
12 "//llvm/lib/Support",
13 ]
14 sources = [
15 "IndexTests.cpp",
16 ]
17 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("LexTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/Basic",
7 "//clang/lib/Lex",
8 "//clang/lib/Parse",
9 "//clang/lib/Sema",
10 "//llvm/lib/Support",
11 ]
12 sources = [
13 "HeaderMapTest.cpp",
14 "HeaderSearchTest.cpp",
15 "LexerTest.cpp",
16 "PPCallbacksTest.cpp",
17 "PPConditionalDirectiveRecordTest.cpp",
18 ]
19 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("ClangRenameTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4
5 # We'd like clang/unittests/Tooling/RewriterTestContext.h in the test.
6 include_dirs = [ "../.." ]
7
8 deps = [
9 "//clang/lib/AST",
10 "//clang/lib/ASTMatchers",
11 "//clang/lib/Basic",
12 "//clang/lib/Format",
13 "//clang/lib/Frontend",
14 "//clang/lib/Rewrite",
15 "//clang/lib/Tooling",
16 "//clang/lib/Tooling/Core",
17 "//clang/lib/Tooling/Refactoring",
18 "//llvm/lib/Support",
19 ]
20 sources = [
21 "RenameAliasTest.cpp",
22 "RenameClassTest.cpp",
23 "RenameEnumTest.cpp",
24 "RenameFunctionTest.cpp",
25 "RenameMemberTest.cpp",
26 ]
27 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("RewriteTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/Rewrite",
6 "//llvm/lib/Support",
7 ]
8 sources = [
9 "RewriteBufferTest.cpp",
10 ]
11 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("SemaTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/AST",
6 "//clang/lib/Basic",
7 "//clang/lib/Frontend",
8 "//clang/lib/Parse",
9 "//clang/lib/Sema",
10 "//clang/lib/Tooling",
11 "//llvm/lib/Support",
12 ]
13 sources = [
14 "CodeCompleteTest.cpp",
15 "ExternalSemaSourceTest.cpp",
16 ]
17 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("StaticAnalysisTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/lib/Analysis",
6 "//clang/lib/Basic",
7 "//clang/lib/StaticAnalyzer/Core",
8 "//clang/lib/StaticAnalyzer/Frontend",
9 "//clang/lib/Tooling",
10 "//llvm/lib/Support",
11 ]
12 sources = [
13 "AnalyzerOptionsTest.cpp",
14 "RegisterCustomCheckersTest.cpp",
15 ]
16 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("ToolingTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 include_dirs = [ "." ]
5 deps = [
6 "//clang/lib/AST",
7 "//clang/lib/ASTMatchers",
8 "//clang/lib/Basic",
9 "//clang/lib/Format",
10 "//clang/lib/Frontend",
11 "//clang/lib/Lex",
12 "//clang/lib/Rewrite",
13 "//clang/lib/Tooling",
14 "//clang/lib/Tooling/Core",
15 "//clang/lib/Tooling/Refactoring",
16 "//llvm/lib/Support",
17 "//llvm/lib/Target:TargetsToBuild",
18 ]
19 sources = [
20 "ASTSelectionTest.cpp",
21 "CastExprTest.cpp",
22 "CommentHandlerTest.cpp",
23 "CompilationDatabaseTest.cpp",
24 "DiagnosticsYamlTest.cpp",
25 "ExecutionTest.cpp",
26 "FixItTest.cpp",
27 "HeaderIncludesTest.cpp",
28 "LexicallyOrderedRecursiveASTVisitorTest.cpp",
29 "LookupTest.cpp",
30 "QualTypeNamesTest.cpp",
31 "RecursiveASTVisitorTestDeclVisitor.cpp",
32 "RecursiveASTVisitorTestPostOrderVisitor.cpp",
33 "RecursiveASTVisitorTestTypeLocVisitor.cpp",
34 "RecursiveASTVisitorTests/Attr.cpp",
35 "RecursiveASTVisitorTests/CXXBoolLiteralExpr.cpp",
36 "RecursiveASTVisitorTests/CXXMemberCall.cpp",
37 "RecursiveASTVisitorTests/CXXOperatorCallExprTraverser.cpp",
38 "RecursiveASTVisitorTests/Class.cpp",
39 "RecursiveASTVisitorTests/ConstructExpr.cpp",
40 "RecursiveASTVisitorTests/DeclRefExpr.cpp",
41 "RecursiveASTVisitorTests/ImplicitCtor.cpp",
42 "RecursiveASTVisitorTests/InitListExprPostOrder.cpp",
43 "RecursiveASTVisitorTests/InitListExprPostOrderNoQueue.cpp",
44 "RecursiveASTVisitorTests/InitListExprPreOrder.cpp",
45 "RecursiveASTVisitorTests/InitListExprPreOrderNoQueue.cpp",
46 "RecursiveASTVisitorTests/IntegerLiteral.cpp",
47 "RecursiveASTVisitorTests/LambdaDefaultCapture.cpp",
48 "RecursiveASTVisitorTests/LambdaExpr.cpp",
49 "RecursiveASTVisitorTests/NestedNameSpecifiers.cpp",
50 "RecursiveASTVisitorTests/ParenExpr.cpp",
51 "RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp",
52 "RecursiveASTVisitorTests/TraversalScope.cpp",
53 "RefactoringActionRulesTest.cpp",
54 "RefactoringCallbacksTest.cpp",
55 "RefactoringTest.cpp",
56 "ReplacementsYamlTest.cpp",
57 "RewriterTest.cpp",
58 "ToolingTest.cpp",
59 ]
60 }
0 import("//llvm/utils/unittest/unittest.gni")
1
2 unittest("libclangTests") {
3 configs += [ "//llvm/utils/gn/build:clang_code" ]
4 deps = [
5 "//clang/tools/libclang",
6 ]
7 sources = [
8 "LibclangTest.cpp",
9 ]
10 if (host_os == "mac") {
11 ldflags = [ "-Wl,-rpath," + rebase_path("$root_out_dir/lib") ]
12 }
13 }
None executable("DriverTests") {
1 # test/Unit/lit.cfg expects unittests in LLD_BINARY_DIR/unittest
2 output_dir = target_out_dir
0 import("//llvm/utils/unittest/unittest.gni")
31
2 unittest("DriverTests") {
43 configs += [ "//llvm/utils/gn/build:lld_code" ]
54 deps = [
65 "//lld/lib/Driver",
76 "//lld/lib/ReaderWriter/MachO",
8 "//llvm/utils/unittest/UnitTestMain",
97 ]
108 sources = [
119 "DarwinLdDriverTest.cpp",
1210 ]
13 testonly = true
1411 }
None executable("MachOTests") {
1 # test/Unit/lit.cfg expects unittests in LLD_BINARY_DIR/unittest
2 output_dir = target_out_dir
0 import("//llvm/utils/unittest/unittest.gni")
31
2 unittest("MachOTests") {
43 configs += [ "//llvm/utils/gn/build:lld_code" ]
54 deps = [
65 "//lld/lib/Driver",
76 "//lld/lib/ReaderWriter/MachO",
87 "//lld/lib/ReaderWriter/YAML",
9 "//llvm/utils/unittest/UnitTestMain",
108 ]
119 sources = [
1210 "MachONormalizedFileBinaryReaderTests.cpp",
1412 "MachONormalizedFileToAtomsTests.cpp",
1513 "MachONormalizedFileYAMLTests.cpp",
1614 ]
17 testonly = true
1815 }
0 # This file defines a template for adding a unittest binary.
1 #
2 # It's a thin wrapper around GN's built-in executable() target type and
3 # accepts the same parameters.
4 #
5 # Example use:
6 #
7 # unittest("FormatTest") {
8 # sources = [ ... ]
9 # ...
10 # }
11
12 template("unittest") {
13 executable(target_name) {
14 # Foward everything (configs, sources, deps, ...).
15 forward_variables_from(invoker, "*")
16 assert(!defined(invoker.output_dir), "cannot set unittest output_dir")
17 assert(!defined(invoker.testonly), "cannot set unittest testonly")
18
19 # Common settings for all unit tests.
20 # Unit test binaries shouldn't go right in out/gn/bin, for two reasons:
21 # 1. That's where production binaries go.
22 # 2. The CMake build doesn't put the unit tests of all projects (clang,
23 # lld,...) in one directory, so it's not guaranteed that there won't
24 # be name collisions between test binaries from separate projects.
25 # Each lit suite takes an foo_obj_root parameter and puts temporary files
26 # for lit tests at foo_obj_root/test and looks for unit test binaries
27 # below foo_obj_root/unittests. As long as the BUILD.gn files processing
28 # the lit.site.cfg.py.in files match the output dir here, it doesn't
29 # matter all that much where the unit test binaries go, with the weak
30 # constraints that test binaries of different projects should go in
31 # different folders, and that it's not too difficult to manually
32 # run the unit test binary if necessary. Using target_out_dir here
33 # means that //clang/unittests/Format gets its binary in
34 # out/gn/obj/clang/unittests/Format/FormatTests, which seems fine.
35 output_dir = target_out_dir
36 deps += [ "//llvm/utils/unittest/UnitTestMain" ]
37 testonly = true
38 }
39 }
40
41 set_defaults("unittest") {
42 configs = shared_binary_target_configs
43 }