Index: llvm/trunk/utils/gn/build/BUILDCONFIG.gn =================================================================== --- llvm/trunk/utils/gn/build/BUILDCONFIG.gn +++ llvm/trunk/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 @@ # 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") { Index: llvm/trunk/utils/gn/build/sync_source_lists_from_cmake.py =================================================================== --- llvm/trunk/utils/gn/build/sync_source_lists_from_cmake.py +++ llvm/trunk/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 re import subprocess -def main(): + +def sync_source_lists(): gn_files = subprocess.check_output( ['git', 'ls-files', '*BUILD.gn']).splitlines() @@ -50,5 +55,24 @@ 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() Index: llvm/trunk/utils/gn/secondary/clang/lib/ASTMatchers/Dynamic/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/lib/ASTMatchers/Dynamic/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/test/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/test/BUILD.gn +++ llvm/trunk/utils/gn/secondary/clang/test/BUILD.gn @@ -125,6 +125,7 @@ "//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 @@ ] } - # FIXME: dep on "//clang/unittests" once it exists # FIXME: clang_build_examples testonly = true } Index: llvm/trunk/utils/gn/secondary/clang/unittests/AST/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/AST/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/ASTMatchers/Dynamic/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/ASTMatchers/Dynamic/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Analysis/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Analysis/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/BUILD.gn +++ llvm/trunk/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 +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Basic/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Basic/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/CodeGen/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/CodeGen/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/CrossTU/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/CrossTU/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Driver/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Driver/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Format/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Format/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Frontend/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Frontend/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Index/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Index/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Lex/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Lex/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Rename/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Rename/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Rewrite/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Rewrite/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Sema/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Sema/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/StaticAnalyzer/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/StaticAnalyzer/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/Tooling/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/Tooling/BUILD.gn +++ llvm/trunk/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", + ] +} Index: llvm/trunk/utils/gn/secondary/clang/unittests/libclang/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/clang/unittests/libclang/BUILD.gn +++ llvm/trunk/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") ] + } +} Index: llvm/trunk/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn +++ llvm/trunk/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 } Index: llvm/trunk/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn =================================================================== --- llvm/trunk/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn +++ llvm/trunk/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 @@ "MachONormalizedFileToAtomsTests.cpp", "MachONormalizedFileYAMLTests.cpp", ] - testonly = true } Index: llvm/trunk/utils/gn/secondary/llvm/utils/unittest/unittest.gni =================================================================== --- llvm/trunk/utils/gn/secondary/llvm/utils/unittest/unittest.gni +++ llvm/trunk/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 +}