File: unittest.gni

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (58 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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, 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:
#
#   unittest("FormatTest") {
#     sources = [ ... ]
#     ...
#   }

template("unittest") {
  executable(target_name) {
    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")

    # 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.
    #
    # If you change output_dir here, look through
    # `git grep target_out_dir '*/unittests/*'` and update those too.
    output_dir = target_out_dir

    if (has_custom_main) {
      deps += [ "//third-party/unittest:gtest" ]
    } else {
      deps += [ "//third-party/unittest/UnitTestMain" ]
    }
    testonly = true
  }
}

set_defaults("unittest") {
  configs = shared_binary_target_configs
}