From: Nico Weber Date: Mon, 31 Dec 2018 00:10:47 +0000 (+0000) Subject: [gn build] Make `ninja check-clang` also run Clang's unit tests X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de6599953cef85d3999d32eb5a501b1025c47cd8;p=llvm [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 --- diff --git a/utils/gn/build/BUILDCONFIG.gn b/utils/gn/build/BUILDCONFIG.gn index c4403657e5d..5ff504da072 100644 --- a/utils/gn/build/BUILDCONFIG.gn +++ b/utils/gn/build/BUILDCONFIG.gn @@ -2,7 +2,7 @@ # Targets can opt out of a config by removing it from their local configs list. # If you're adding global flags and don't need targets to be able to opt out, # add the flags to compiler_defaults, not to a new config. -_shared_binary_target_configs = [ +shared_binary_target_configs = [ "//llvm/utils/gn/build:compiler_defaults", "//llvm/utils/gn/build:llvm_code", "//llvm/utils/gn/build:warn_covered_switch_default", @@ -10,19 +10,19 @@ _shared_binary_target_configs = [ # Apply that default list to the binary target types. set_defaults("executable") { - configs = _shared_binary_target_configs + configs = shared_binary_target_configs } set_defaults("loadable_module") { - configs = _shared_binary_target_configs + configs = shared_binary_target_configs } set_defaults("static_library") { - configs = _shared_binary_target_configs + configs = shared_binary_target_configs } set_defaults("shared_library") { - configs = _shared_binary_target_configs + configs = shared_binary_target_configs } set_defaults("source_set") { - configs = _shared_binary_target_configs + configs = shared_binary_target_configs } if (host_os == "win") { diff --git a/utils/gn/build/sync_source_lists_from_cmake.py b/utils/gn/build/sync_source_lists_from_cmake.py index 77539672e33..f5d92ce0bba 100755 --- a/utils/gn/build/sync_source_lists_from_cmake.py +++ b/utils/gn/build/sync_source_lists_from_cmake.py @@ -4,7 +4,11 @@ For each BUILD.gn file in the tree, checks if the list of cpp files in it is identical to the list of cpp files in the corresponding CMakeLists.txt -file, and prints the difference if not.""" +file, and prints the difference if not. + +Also checks that each CMakeLists.txt file below unittests/ folders that define +binaries have corresponding BUILD.gn files. +""" from __future__ import print_function @@ -12,7 +16,8 @@ import os import re import subprocess -def main(): + +def sync_source_lists(): gn_files = subprocess.check_output( ['git', 'ls-files', '*BUILD.gn']).splitlines() @@ -50,5 +55,24 @@ def main(): print('remove:\n' + '\n'.join(remove)) print() + +def sync_unittests(): + checked = [ 'clang', 'lld' ] + for c in checked: + for root, _, _ in os.walk(os.path.join(c, 'unittests')): + cmake_file = os.path.join(root, 'CMakeLists.txt') + if not os.path.exists(cmake_file): + continue + gn_file = os.path.join('llvm/utils/gn/secondary', root, 'BUILD.gn') + if not os.path.exists(gn_file): + print('missing GN file %s for unittest CMake file %s' % + (gn_file, cmake_file)) + + +def main(): + sync_source_lists() + sync_unittests() + + if __name__ == '__main__': main() diff --git a/utils/gn/secondary/clang/lib/ASTMatchers/Dynamic/BUILD.gn b/utils/gn/secondary/clang/lib/ASTMatchers/Dynamic/BUILD.gn new file mode 100644 index 00000000000..31d27de0491 --- /dev/null +++ b/utils/gn/secondary/clang/lib/ASTMatchers/Dynamic/BUILD.gn @@ -0,0 +1,16 @@ +static_library("Dynamic") { + output_name = "clangDynamicASTMatchers" + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/ASTMatchers", + "//clang/lib/Basic", + "//llvm/lib/Support", + ] + sources = [ + "Diagnostics.cpp", + "Parser.cpp", + "Registry.cpp", + "VariantValue.cpp", + ] +} diff --git a/utils/gn/secondary/clang/test/BUILD.gn b/utils/gn/secondary/clang/test/BUILD.gn index 8264644be3b..1ac7ce1baba 100644 --- a/utils/gn/secondary/clang/test/BUILD.gn +++ b/utils/gn/secondary/clang/test/BUILD.gn @@ -125,6 +125,7 @@ group("test") { "//clang/tools/clang-rename", "//clang/tools/diagtool", "//clang/tools/driver:symlinks", + "//clang/unittests", "//clang/utils/TableGen:clang-tblgen", "//clang/utils/hmaptool", "//llvm/tools/llc", @@ -159,7 +160,6 @@ group("test") { ] } - # FIXME: dep on "//clang/unittests" once it exists # FIXME: clang_build_examples testonly = true } diff --git a/utils/gn/secondary/clang/unittests/AST/BUILD.gn b/utils/gn/secondary/clang/unittests/AST/BUILD.gn new file mode 100644 index 00000000000..d5b00af3ae5 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/AST/BUILD.gn @@ -0,0 +1,33 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("ASTTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/ASTMatchers", + "//clang/lib/Analysis", + "//clang/lib/Basic", + "//clang/lib/Frontend", + "//clang/lib/Tooling", + "//llvm/lib/Support", + ] + sources = [ + "ASTContextParentMapTest.cpp", + "ASTImporterTest.cpp", + "ASTTypeTraitsTest.cpp", + "ASTVectorTest.cpp", + "CommentLexer.cpp", + "CommentParser.cpp", + "CommentTextTest.cpp", + "DataCollectionTest.cpp", + "DeclPrinterTest.cpp", + "DeclTest.cpp", + "EvaluateAsRValueTest.cpp", + "ExternalASTSourceTest.cpp", + "Language.cpp", + "NamedDeclPrinterTest.cpp", + "SourceLocationTest.cpp", + "StmtPrinterTest.cpp", + "StructuralEquivalenceTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn b/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn new file mode 100644 index 00000000000..241d03dd61c --- /dev/null +++ b/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn @@ -0,0 +1,19 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("ASTMatchersTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/ASTMatchers", + "//clang/lib/Basic", + "//clang/lib/Frontend", + "//clang/lib/Tooling", + "//llvm/lib/Support", + ] + sources = [ + "ASTMatchersInternalTest.cpp", + "ASTMatchersNarrowingTest.cpp", + "ASTMatchersNodeTest.cpp", + "ASTMatchersTraversalTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/ASTMatchers/Dynamic/BUILD.gn b/utils/gn/secondary/clang/unittests/ASTMatchers/Dynamic/BUILD.gn new file mode 100644 index 00000000000..de89f0fc809 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/ASTMatchers/Dynamic/BUILD.gn @@ -0,0 +1,19 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("DynamicASTMatchersTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/ASTMatchers", + "//clang/lib/ASTMatchers/Dynamic", + "//clang/lib/Basic", + "//clang/lib/Frontend", + "//clang/lib/Tooling", + "//llvm/lib/Support", + ] + sources = [ + "ParserTest.cpp", + "RegistryTest.cpp", + "VariantValueTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Analysis/BUILD.gn b/utils/gn/secondary/clang/unittests/Analysis/BUILD.gn new file mode 100644 index 00000000000..c6c6fbe58a9 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Analysis/BUILD.gn @@ -0,0 +1,19 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("ClangAnalysisTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/ASTMatchers", + "//clang/lib/Analysis", + "//clang/lib/Basic", + "//clang/lib/Frontend", + "//clang/lib/Tooling", + "//llvm/lib/Support", + ] + sources = [ + "CFGTest.cpp", + "CloneDetectionTest.cpp", + "ExprMutationAnalyzerTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/BUILD.gn b/utils/gn/secondary/clang/unittests/BUILD.gn new file mode 100644 index 00000000000..a8293ba926b --- /dev/null +++ b/utils/gn/secondary/clang/unittests/BUILD.gn @@ -0,0 +1,35 @@ +import("//clang/lib/StaticAnalyzer/Frontend/enable.gni") + +group("unittests") { + deps = [ + "AST:ASTTests", + "ASTMatchers:ASTMatchersTests", + "ASTMatchers/Dynamic:DynamicASTMatchersTests", + "Basic:BasicTests", + "CodeGen:ClangCodeGenTests", + "CrossTU:CrossTUTests", + "Driver:ClangDriverTests", + "Format:FormatTests", + "Index:IndexTests", + "Lex:LexTests", + "Rename:ClangRenameTests", + "Rewrite:RewriteTests", + "Sema:SemaTests", + "Tooling:ToolingTests", + ] + if (clang_enable_static_analyzer) { + deps += [ + "Analysis:ClangAnalysisTests", + "Frontend:FrontendTests", + "StaticAnalyzer:StaticAnalysisTests", + ] + } + if (host_os != "win") { + # FIXME: libclang unit tests are disabled on Windows due + # to failures, mostly in libclang.VirtualFileOverlay_*. + # FIXME: Also, the executable can't find libclang.dll since that's + # in a different directory. + deps += [ "libclang:libclangTests" ] + } + testonly = true +} diff --git a/utils/gn/secondary/clang/unittests/Basic/BUILD.gn b/utils/gn/secondary/clang/unittests/Basic/BUILD.gn new file mode 100644 index 00000000000..31277aea8d2 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Basic/BUILD.gn @@ -0,0 +1,18 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("BasicTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/Basic", + "//clang/lib/Lex", + "//llvm/lib/Support", + ] + sources = [ + "CharInfoTest.cpp", + "DiagnosticTest.cpp", + "FileManagerTest.cpp", + "FixedPointTest.cpp", + "MemoryBufferCacheTest.cpp", + "SourceManagerTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/CodeGen/BUILD.gn b/utils/gn/secondary/clang/unittests/CodeGen/BUILD.gn new file mode 100644 index 00000000000..37b514eab49 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/CodeGen/BUILD.gn @@ -0,0 +1,21 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("ClangCodeGenTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/Basic", + "//clang/lib/CodeGen", + "//clang/lib/Frontend", + "//clang/lib/Lex", + "//clang/lib/Parse", + "//llvm/lib/IR", + "//llvm/lib/Support", + ] + sources = [ + "BufferSourceTest.cpp", + "CodeGenExternalTest.cpp", + "IncrementalProcessingTest.cpp", + "TBAAMetadataTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/CrossTU/BUILD.gn b/utils/gn/secondary/clang/unittests/CrossTU/BUILD.gn new file mode 100644 index 00000000000..6330f300579 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/CrossTU/BUILD.gn @@ -0,0 +1,17 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("CrossTUTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/Basic", + "//clang/lib/CrossTU", + "//clang/lib/Frontend", + "//clang/lib/Tooling", + "//llvm/lib/Support", + "//llvm/lib/Target:TargetsToBuild", + ] + sources = [ + "CrossTranslationUnitTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Driver/BUILD.gn b/utils/gn/secondary/clang/unittests/Driver/BUILD.gn new file mode 100644 index 00000000000..6a91b036441 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Driver/BUILD.gn @@ -0,0 +1,18 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("ClangDriverTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/Basic", + "//clang/lib/Driver", + "//llvm/lib/Option", + "//llvm/lib/Support", + "//llvm/lib/Target:TargetsToBuild", + ] + sources = [ + "DistroTest.cpp", + "ModuleCacheTest.cpp", + "MultilibTest.cpp", + "ToolChainTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Format/BUILD.gn b/utils/gn/secondary/clang/unittests/Format/BUILD.gn new file mode 100644 index 00000000000..aaf990b485e --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Format/BUILD.gn @@ -0,0 +1,31 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("FormatTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/Basic", + "//clang/lib/Format", + "//clang/lib/Frontend", + "//clang/lib/Rewrite", + "//clang/lib/Tooling/Core", + "//llvm/lib/Support", + ] + sources = [ + "CleanupTest.cpp", + "FormatTest.cpp", + "FormatTestComments.cpp", + "FormatTestJS.cpp", + "FormatTestJava.cpp", + "FormatTestObjC.cpp", + "FormatTestProto.cpp", + "FormatTestRawStrings.cpp", + "FormatTestSelective.cpp", + "FormatTestTableGen.cpp", + "FormatTestTextProto.cpp", + "NamespaceEndCommentsFixerTest.cpp", + "SortImportsTestJS.cpp", + "SortImportsTestJava.cpp", + "SortIncludesTest.cpp", + "UsingDeclarationsSorterTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Frontend/BUILD.gn b/utils/gn/secondary/clang/unittests/Frontend/BUILD.gn new file mode 100644 index 00000000000..f3b535cf486 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Frontend/BUILD.gn @@ -0,0 +1,25 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("FrontendTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/Basic", + "//clang/lib/CodeGen", + "//clang/lib/Frontend", + "//clang/lib/FrontendTool", + "//clang/lib/Lex", + "//clang/lib/Sema", + "//llvm/lib/Support", + ] + sources = [ + "ASTUnitTest.cpp", + "CodeGenActionTest.cpp", + "CompilerInstanceTest.cpp", + "FixedPointString.cpp", + "FrontendActionTest.cpp", + "OutputStreamTest.cpp", + "PCHPreambleTest.cpp", + "ParsedSourceLocationTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Index/BUILD.gn b/utils/gn/secondary/clang/unittests/Index/BUILD.gn new file mode 100644 index 00000000000..c2e6395f377 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Index/BUILD.gn @@ -0,0 +1,18 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("IndexTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/Basic", + "//clang/lib/Frontend", + "//clang/lib/Index", + "//clang/lib/Lex", + "//clang/lib/Serialization", + "//clang/lib/Tooling", + "//llvm/lib/Support", + ] + sources = [ + "IndexTests.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Lex/BUILD.gn b/utils/gn/secondary/clang/unittests/Lex/BUILD.gn new file mode 100644 index 00000000000..63180cb9953 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Lex/BUILD.gn @@ -0,0 +1,20 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("LexTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/Basic", + "//clang/lib/Lex", + "//clang/lib/Parse", + "//clang/lib/Sema", + "//llvm/lib/Support", + ] + sources = [ + "HeaderMapTest.cpp", + "HeaderSearchTest.cpp", + "LexerTest.cpp", + "PPCallbacksTest.cpp", + "PPConditionalDirectiveRecordTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Rename/BUILD.gn b/utils/gn/secondary/clang/unittests/Rename/BUILD.gn new file mode 100644 index 00000000000..54c0dba0859 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Rename/BUILD.gn @@ -0,0 +1,28 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("ClangRenameTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + + # We'd like clang/unittests/Tooling/RewriterTestContext.h in the test. + include_dirs = [ "../.." ] + + deps = [ + "//clang/lib/AST", + "//clang/lib/ASTMatchers", + "//clang/lib/Basic", + "//clang/lib/Format", + "//clang/lib/Frontend", + "//clang/lib/Rewrite", + "//clang/lib/Tooling", + "//clang/lib/Tooling/Core", + "//clang/lib/Tooling/Refactoring", + "//llvm/lib/Support", + ] + sources = [ + "RenameAliasTest.cpp", + "RenameClassTest.cpp", + "RenameEnumTest.cpp", + "RenameFunctionTest.cpp", + "RenameMemberTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Rewrite/BUILD.gn b/utils/gn/secondary/clang/unittests/Rewrite/BUILD.gn new file mode 100644 index 00000000000..350f67d2e08 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Rewrite/BUILD.gn @@ -0,0 +1,12 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("RewriteTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/Rewrite", + "//llvm/lib/Support", + ] + sources = [ + "RewriteBufferTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Sema/BUILD.gn b/utils/gn/secondary/clang/unittests/Sema/BUILD.gn new file mode 100644 index 00000000000..b65865d37e6 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Sema/BUILD.gn @@ -0,0 +1,18 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("SemaTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/AST", + "//clang/lib/Basic", + "//clang/lib/Frontend", + "//clang/lib/Parse", + "//clang/lib/Sema", + "//clang/lib/Tooling", + "//llvm/lib/Support", + ] + sources = [ + "CodeCompleteTest.cpp", + "ExternalSemaSourceTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/StaticAnalyzer/BUILD.gn b/utils/gn/secondary/clang/unittests/StaticAnalyzer/BUILD.gn new file mode 100644 index 00000000000..426385387e9 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/StaticAnalyzer/BUILD.gn @@ -0,0 +1,17 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("StaticAnalysisTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/lib/Analysis", + "//clang/lib/Basic", + "//clang/lib/StaticAnalyzer/Core", + "//clang/lib/StaticAnalyzer/Frontend", + "//clang/lib/Tooling", + "//llvm/lib/Support", + ] + sources = [ + "AnalyzerOptionsTest.cpp", + "RegisterCustomCheckersTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/Tooling/BUILD.gn b/utils/gn/secondary/clang/unittests/Tooling/BUILD.gn new file mode 100644 index 00000000000..5b027dc1b84 --- /dev/null +++ b/utils/gn/secondary/clang/unittests/Tooling/BUILD.gn @@ -0,0 +1,61 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("ToolingTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + include_dirs = [ "." ] + deps = [ + "//clang/lib/AST", + "//clang/lib/ASTMatchers", + "//clang/lib/Basic", + "//clang/lib/Format", + "//clang/lib/Frontend", + "//clang/lib/Lex", + "//clang/lib/Rewrite", + "//clang/lib/Tooling", + "//clang/lib/Tooling/Core", + "//clang/lib/Tooling/Refactoring", + "//llvm/lib/Support", + "//llvm/lib/Target:TargetsToBuild", + ] + sources = [ + "ASTSelectionTest.cpp", + "CastExprTest.cpp", + "CommentHandlerTest.cpp", + "CompilationDatabaseTest.cpp", + "DiagnosticsYamlTest.cpp", + "ExecutionTest.cpp", + "FixItTest.cpp", + "HeaderIncludesTest.cpp", + "LexicallyOrderedRecursiveASTVisitorTest.cpp", + "LookupTest.cpp", + "QualTypeNamesTest.cpp", + "RecursiveASTVisitorTestDeclVisitor.cpp", + "RecursiveASTVisitorTestPostOrderVisitor.cpp", + "RecursiveASTVisitorTestTypeLocVisitor.cpp", + "RecursiveASTVisitorTests/Attr.cpp", + "RecursiveASTVisitorTests/CXXBoolLiteralExpr.cpp", + "RecursiveASTVisitorTests/CXXMemberCall.cpp", + "RecursiveASTVisitorTests/CXXOperatorCallExprTraverser.cpp", + "RecursiveASTVisitorTests/Class.cpp", + "RecursiveASTVisitorTests/ConstructExpr.cpp", + "RecursiveASTVisitorTests/DeclRefExpr.cpp", + "RecursiveASTVisitorTests/ImplicitCtor.cpp", + "RecursiveASTVisitorTests/InitListExprPostOrder.cpp", + "RecursiveASTVisitorTests/InitListExprPostOrderNoQueue.cpp", + "RecursiveASTVisitorTests/InitListExprPreOrder.cpp", + "RecursiveASTVisitorTests/InitListExprPreOrderNoQueue.cpp", + "RecursiveASTVisitorTests/IntegerLiteral.cpp", + "RecursiveASTVisitorTests/LambdaDefaultCapture.cpp", + "RecursiveASTVisitorTests/LambdaExpr.cpp", + "RecursiveASTVisitorTests/NestedNameSpecifiers.cpp", + "RecursiveASTVisitorTests/ParenExpr.cpp", + "RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp", + "RecursiveASTVisitorTests/TraversalScope.cpp", + "RefactoringActionRulesTest.cpp", + "RefactoringCallbacksTest.cpp", + "RefactoringTest.cpp", + "ReplacementsYamlTest.cpp", + "RewriterTest.cpp", + "ToolingTest.cpp", + ] +} diff --git a/utils/gn/secondary/clang/unittests/libclang/BUILD.gn b/utils/gn/secondary/clang/unittests/libclang/BUILD.gn new file mode 100644 index 00000000000..cd99640423f --- /dev/null +++ b/utils/gn/secondary/clang/unittests/libclang/BUILD.gn @@ -0,0 +1,14 @@ +import("//llvm/utils/unittest/unittest.gni") + +unittest("libclangTests") { + configs += [ "//llvm/utils/gn/build:clang_code" ] + deps = [ + "//clang/tools/libclang", + ] + sources = [ + "LibclangTest.cpp", + ] + if (host_os == "mac") { + ldflags = [ "-Wl,-rpath," + rebase_path("$root_out_dir/lib") ] + } +} diff --git a/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn b/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn index abb365a182f..b683c3507a2 100644 --- a/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn +++ b/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn @@ -1,15 +1,12 @@ -executable("DriverTests") { - # test/Unit/lit.cfg expects unittests in LLD_BINARY_DIR/unittest - output_dir = target_out_dir +import("//llvm/utils/unittest/unittest.gni") +unittest("DriverTests") { configs += [ "//llvm/utils/gn/build:lld_code" ] deps = [ "//lld/lib/Driver", "//lld/lib/ReaderWriter/MachO", - "//llvm/utils/unittest/UnitTestMain", ] sources = [ "DarwinLdDriverTest.cpp", ] - testonly = true } diff --git a/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn b/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn index be2878f8822..90d0a618c30 100644 --- a/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn +++ b/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn @@ -1,13 +1,11 @@ -executable("MachOTests") { - # test/Unit/lit.cfg expects unittests in LLD_BINARY_DIR/unittest - output_dir = target_out_dir +import("//llvm/utils/unittest/unittest.gni") +unittest("MachOTests") { configs += [ "//llvm/utils/gn/build:lld_code" ] deps = [ "//lld/lib/Driver", "//lld/lib/ReaderWriter/MachO", "//lld/lib/ReaderWriter/YAML", - "//llvm/utils/unittest/UnitTestMain", ] sources = [ "MachONormalizedFileBinaryReaderTests.cpp", @@ -15,5 +13,4 @@ executable("MachOTests") { "MachONormalizedFileToAtomsTests.cpp", "MachONormalizedFileYAMLTests.cpp", ] - testonly = true } diff --git a/utils/gn/secondary/llvm/utils/unittest/unittest.gni b/utils/gn/secondary/llvm/utils/unittest/unittest.gni new file mode 100644 index 00000000000..d2a6e37fdd4 --- /dev/null +++ b/utils/gn/secondary/llvm/utils/unittest/unittest.gni @@ -0,0 +1,44 @@ +# This file defines a template for adding a unittest binary. +# +# It's a thin wrapper around GN's built-in executable() target type and +# accepts the same parameters. +# +# Example use: +# +# unittest("FormatTest") { +# sources = [ ... ] +# ... +# } + +template("unittest") { + executable(target_name) { + # Foward everything (configs, sources, deps, ...). + forward_variables_from(invoker, "*") + assert(!defined(invoker.output_dir), "cannot set unittest output_dir") + assert(!defined(invoker.testonly), "cannot set unittest testonly") + + # Common settings for all unit tests. + # Unit test binaries shouldn't go right in out/gn/bin, for two reasons: + # 1. That's where production binaries go. + # 2. The CMake build doesn't put the unit tests of all projects (clang, + # lld,...) in one directory, so it's not guaranteed that there won't + # be name collisions between test binaries from separate projects. + # Each lit suite takes an foo_obj_root parameter and puts temporary files + # for lit tests at foo_obj_root/test and looks for unit test binaries + # below foo_obj_root/unittests. As long as the BUILD.gn files processing + # the lit.site.cfg.py.in files match the output dir here, it doesn't + # matter all that much where the unit test binaries go, with the weak + # constraints that test binaries of different projects should go in + # different folders, and that it's not too difficult to manually + # run the unit test binary if necessary. Using target_out_dir here + # means that //clang/unittests/Format gets its binary in + # out/gn/obj/clang/unittests/Format/FormatTests, which seems fine. + output_dir = target_out_dir + deps += [ "//llvm/utils/unittest/UnitTestMain" ] + testonly = true + } +} + +set_defaults("unittest") { + configs = shared_binary_target_configs +}