]> granicus.if.org Git - llvm/commitdiff
[gn build] Make `ninja check-clang` also run Clang's unit tests
authorNico Weber <nicolasweber@gmx.de>
Mon, 31 Dec 2018 00:10:47 +0000 (00:10 +0000)
committerNico Weber <nicolasweber@gmx.de>
Mon, 31 Dec 2018 00:10:47 +0000 (00:10 +0000)
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

26 files changed:
utils/gn/build/BUILDCONFIG.gn
utils/gn/build/sync_source_lists_from_cmake.py
utils/gn/secondary/clang/lib/ASTMatchers/Dynamic/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/test/BUILD.gn
utils/gn/secondary/clang/unittests/AST/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/ASTMatchers/Dynamic/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Analysis/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Basic/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/CodeGen/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/CrossTU/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Driver/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Format/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Frontend/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Index/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Lex/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Rename/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Rewrite/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Sema/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/StaticAnalyzer/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/Tooling/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/clang/unittests/libclang/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn
utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn
utils/gn/secondary/llvm/utils/unittest/unittest.gni [new file with mode: 0644]

index c4403657e5df3881f452805d0b528b519a9662d7..5ff504da07260d0482ee6bd32bb1e12f375098a6 100644 (file)
@@ -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") {
index 77539672e33ad3c805ec87c629dea980400693eb..f5d92ce0bba70b3920563a46a93d97271d842c14 100755 (executable)
@@ -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 (file)
index 0000000..31d27de
--- /dev/null
@@ -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 8264644be3b2514584ab302490d80ce00f15e628..1ac7ce1baba37611c6cf4441ee4a0108afc19569 100644 (file)
@@ -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 (file)
index 0000000..d5b00af
--- /dev/null
@@ -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 (file)
index 0000000..241d03d
--- /dev/null
@@ -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 (file)
index 0000000..de89f0f
--- /dev/null
@@ -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 (file)
index 0000000..c6c6fbe
--- /dev/null
@@ -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 (file)
index 0000000..a8293ba
--- /dev/null
@@ -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 (file)
index 0000000..31277ae
--- /dev/null
@@ -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 (file)
index 0000000..37b514e
--- /dev/null
@@ -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 (file)
index 0000000..6330f30
--- /dev/null
@@ -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 (file)
index 0000000..6a91b03
--- /dev/null
@@ -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 (file)
index 0000000..aaf990b
--- /dev/null
@@ -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 (file)
index 0000000..f3b535c
--- /dev/null
@@ -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 (file)
index 0000000..c2e6395
--- /dev/null
@@ -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 (file)
index 0000000..63180cb
--- /dev/null
@@ -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 (file)
index 0000000..54c0dba
--- /dev/null
@@ -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 (file)
index 0000000..350f67d
--- /dev/null
@@ -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 (file)
index 0000000..b65865d
--- /dev/null
@@ -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 (file)
index 0000000..4263853
--- /dev/null
@@ -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 (file)
index 0000000..5b027dc
--- /dev/null
@@ -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 (file)
index 0000000..cd99640
--- /dev/null
@@ -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 abb365a182f36ca2203e7f881618160744479503..b683c3507a2d1d190b297c9d7663e68ff48de273 100644 (file)
@@ -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 be2878f8822e031599d689040a1c41b7c91e29bf..90d0a618c309c0f159eed136f40372af9c7ced4e 100644 (file)
@@ -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 (file)
index 0000000..d2a6e37
--- /dev/null
@@ -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
+}