]> granicus.if.org Git - llvm/commitdiff
[gn build] Add build files for LLVM unittests with a custom main() function
authorNico Weber <nicolasweber@gmx.de>
Sun, 6 Jan 2019 15:09:22 +0000 (15:09 +0000)
committerNico Weber <nicolasweber@gmx.de>
Sun, 6 Jan 2019 15:09:22 +0000 (15:09 +0000)
Differential Revision: https://reviews.llvm.org/D56219

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350492 91177308-0d34-0410-b5e6-96231b3b80d8

utils/gn/secondary/llvm/unittests/BUILD.gn
utils/gn/secondary/llvm/unittests/CodeGen/GlobalISel/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/llvm/unittests/MI/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/llvm/unittests/tools/llvm-cfi-verify/BUILD.gn [new file with mode: 0644]
utils/gn/secondary/llvm/utils/unittest/unittest.gni

index b7cd0e793eb037da7d76f5ab0795e4e99897cebc..ac53b603f67ce93bad604070d0e893dcac4a0a23 100644 (file)
@@ -8,9 +8,7 @@ group("unittests") {
     "BinaryFormat:BinaryFormatTests",
     "Bitcode:BitcodeTests",
     "CodeGen:CodeGenTests",
-
-    # FIXME: Add.
-    #"CodeGen/GlobalISel:GlobalISelTests",
+    "CodeGen/GlobalISel:GlobalISelTests",
     "DebugInfo/CodeView:DebugInfoCodeViewTests",
     "DebugInfo/DWARF:DebugInfoDWARFTests",
     "DebugInfo/MSF:DebugInfoMSFTests",
@@ -24,9 +22,7 @@ group("unittests") {
     "LineEditor:LineEditorTests",
     "Linker:LinkerTests",
     "MC:MCTests",
-
-    # FIXME: Add.
-    #"MI:MITests",
+    "MI:MITests",
     "Object:ObjectTests",
     "ObjectYAML:ObjectYAMLTests",
     "OptRemarks:OptRemarksTests",
@@ -41,9 +37,7 @@ group("unittests") {
     "Transforms/Utils:UtilsTests",
     "Transforms/Vectorize:VectorizeTests",
     "XRay:XRayTests",
-
-    # FIXME: Add more:
-    #"tools/llvm-cfi-verify:CFIVerifyTests",
+    "tools/llvm-cfi-verify:CFIVerifyTests",
     "tools/llvm-exegesis:LLVMExegesisTests",
   ]
 
diff --git a/utils/gn/secondary/llvm/unittests/CodeGen/GlobalISel/BUILD.gn b/utils/gn/secondary/llvm/unittests/CodeGen/GlobalISel/BUILD.gn
new file mode 100644 (file)
index 0000000..a63dad6
--- /dev/null
@@ -0,0 +1,20 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+unittest("GlobalISelTests") {
+  deps = [
+    "//llvm/lib/CodeGen",
+    "//llvm/lib/CodeGen/GlobalISel",
+    "//llvm/lib/CodeGen/MIRParser",
+    "//llvm/lib/IR",
+    "//llvm/lib/MC",
+    "//llvm/lib/Support",
+    "//llvm/lib/Target",
+    "//llvm/lib/Target:TargetsToBuild",
+  ]
+  sources = [
+    "LegalizerHelperTest.cpp",
+    "LegalizerInfoTest.cpp",
+    "PatternMatchTest.cpp",
+  ]
+  has_custom_main = true
+}
diff --git a/utils/gn/secondary/llvm/unittests/MI/BUILD.gn b/utils/gn/secondary/llvm/unittests/MI/BUILD.gn
new file mode 100644 (file)
index 0000000..4ef5ebf
--- /dev/null
@@ -0,0 +1,17 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+unittest("MITests") {
+  deps = [
+    "//llvm/lib/CodeGen",
+    "//llvm/lib/CodeGen/MIRParser",
+    "//llvm/lib/IR",
+    "//llvm/lib/MC",
+    "//llvm/lib/Support",
+    "//llvm/lib/Target",
+    "//llvm/lib/Target:TargetsToBuild",
+  ]
+  sources = [
+    "LiveIntervalTest.cpp",
+  ]
+  has_custom_main = true
+}
diff --git a/utils/gn/secondary/llvm/unittests/tools/llvm-cfi-verify/BUILD.gn b/utils/gn/secondary/llvm/unittests/tools/llvm-cfi-verify/BUILD.gn
new file mode 100644 (file)
index 0000000..e973126
--- /dev/null
@@ -0,0 +1,22 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+unittest("CFIVerifyTests") {
+  deps = [
+    "//llvm/lib/DebugInfo/Symbolize",
+    "//llvm/lib/MC",
+    "//llvm/lib/MC/MCParser",
+    "//llvm/lib/Object",
+    "//llvm/lib/Support",
+    "//llvm/lib/Target:AllTargetsAsmParsers",
+    "//llvm/lib/Target:AllTargetsAsmPrinters",
+    "//llvm/lib/Target:AllTargetsDescs",
+    "//llvm/lib/Target:AllTargetsDisassemblers",
+    "//llvm/lib/Target:AllTargetsInfos",
+    "//llvm/tools/llvm-cfi-verify/lib",
+  ]
+  sources = [
+    "FileAnalysis.cpp",
+    "GraphBuilder.cpp",
+  ]
+  has_custom_main = true
+}
index 10f4ad3ff339af888259699bec2c92f96d416e0c..f0c8309a9aff2c2d573f9a5e61ff0ed017291fb3 100644 (file)
@@ -1,7 +1,11 @@
 # 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.
+# accepts the same parameters, and in addition this paramater:
+#
+#   has_custom_main (optional)
+#       [bool] If set, link against gtest instead of UnitTestMain; for tests
+#              that define their own main() function.
 #
 # Example use:
 #
@@ -12,7 +16,9 @@
 
 template("unittest") {
   executable(target_name) {
-    # Foward everything (configs, sources, deps, ...).
+    has_custom_main = false  # Default value.
+
+    # Foward everything (has_custom_main if set; 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")
@@ -37,7 +43,12 @@ template("unittest") {
     # If you change output_dir here, look through
     # `git grep target_out_dir '*/unittests/*'` and update those too.
     output_dir = target_out_dir
-    deps += [ "//llvm/utils/unittest/UnitTestMain" ]
+
+    if (has_custom_main) {
+      deps += [ "//llvm/utils/unittest:gtest" ]
+    } else {
+      deps += [ "//llvm/utils/unittest/UnitTestMain" ]
+    }
     testonly = true
   }
 }