1# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2#
3# defs.bzl - Definitions for Facebook-specific buck build integration
4# in TARGETS
5
6load("@fbcode_macros//build_defs:coverage.bzl", "coverage")
7load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary")
8load("@fbcode_macros//build_defs:custom_unittest.bzl", "custom_unittest")
9
10def test_binary(
11        test_name,
12        test_cc,
13        parallelism,
14        rocksdb_arch_preprocessor_flags,
15        rocksdb_os_preprocessor_flags,
16        rocksdb_compiler_flags,
17        rocksdb_preprocessor_flags,
18        rocksdb_external_deps,
19        rocksdb_os_deps,
20        extra_deps,
21        extra_compiler_flags):
22    TEST_RUNNER = native.package_name() + "/buckifier/rocks_test_runner.sh"
23
24    ttype = "gtest" if parallelism == "parallel" else "simple"
25    test_bin = test_name + "_bin"
26
27    cpp_binary(
28        name = test_bin,
29        srcs = [test_cc],
30        arch_preprocessor_flags = rocksdb_arch_preprocessor_flags,
31        os_preprocessor_flags = rocksdb_os_preprocessor_flags,
32        compiler_flags = rocksdb_compiler_flags + extra_compiler_flags,
33        preprocessor_flags = rocksdb_preprocessor_flags,
34        deps = [":rocksdb_test_lib"] + extra_deps,
35        os_deps = rocksdb_os_deps,
36        external_deps = rocksdb_external_deps,
37    )
38
39    binary_path = "$(location :{})".format(test_bin)
40
41    base_path = native.package_name()
42    tags = []
43    if coverage.is_coverage_enabled(base_path):
44        # This tag instructs testpilot to use
45        # the lower-memory coverage runner
46        # (e.g. it tells testpilot that the binary
47        # is actually instrumented with coverage info)
48        tags = ["coverage"]
49
50    custom_unittest(
51        name = test_name,
52        command = [TEST_RUNNER, binary_path],
53        type = ttype,
54        env = {"BUCK_BASE_BINARY": binary_path},
55        tags = tags,
56    )
57