Debian Codegraph @

utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl

raw
1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5 """LLVM libc starlark rules for tests.
6
7 libc functions are created though the libc_build_rules.bzl:libc_function.
8 They come in two flavors:
9 - the internal one that is scoped into the `LIBC_NAMESPACE` namespace.
10 - the libc one that is the regular C function.
11
12 When performing tests we make sure to always use the internal version.
13 """
14
15 load("//libc:libc_build_rules.bzl", "libc_common_copts", "libc_internal_target")
16 load("//libc:libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")
17
18 def libc_test(name, srcs, libc_function_deps = [], copts = [], deps = [], local_defines = [], **kwargs):
19 """Add target for a libc test.
20
21 Args:
22 name: Test target name
23 srcs: List of sources for the test.
24 libc_function_deps: List of libc_function targets used by this test.
25 copts: The list of options to add to the C++ compilation command.
26 deps: The list of other libraries to be linked in to the test target.
27 local_defines: The list of target local_defines if any.
28 **kwargs: Attributes relevant for a libc_test. For example, name, srcs.
29 """
30 all_function_deps = libc_function_deps + ["//libc:errno"]
31 native.cc_test(
32 name = name,
33 srcs = srcs,
34 local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,
35 deps = [libc_internal_target(d) for d in all_function_deps] + [
36 "//libc/test/UnitTest:LibcUnitTest",
37 "//libc:__support_macros_config",
38 ] + deps,
39 features = ["-link_llvmlibc"], # Do not link libllvmlibc.a
40 copts = copts + libc_common_copts(),
41 linkstatic = 1,
42 **kwargs
43 )