-
-
Notifications
You must be signed in to change notification settings - Fork 521
/
Copy pathdefs.bzl
52 lines (46 loc) · 1.88 KB
/
defs.bzl
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
# buildifier: disable=module-docstring
# We can transition on native options using this
# //command_line_option:<option-name> syntax
_BUILD_SETTING = "//command_line_option:test_arg"
def _test_arg_transition_impl(_, __):
return {_BUILD_SETTING: ["new arg"]}
_test_arg_transition = transition(
implementation = _test_arg_transition_impl,
inputs = [],
outputs = [_BUILD_SETTING],
)
def _test_transition_rule_impl(ctx):
# We need to copy the executable because starlark doesn't allow
# providing an executable not created by the rule
executable_src = ctx.executable.actual_test
executable_dst = ctx.actions.declare_file(ctx.label.name)
ctx.actions.run_shell(
tools = [executable_src],
outputs = [executable_dst],
command = "cp %s %s" % (executable_src.path, executable_dst.path),
)
runfiles = ctx.attr.actual_test[DefaultInfo].default_runfiles
return [DefaultInfo(runfiles = runfiles, executable = executable_dst)]
transition_rule_test = rule(
cfg = _test_arg_transition,
implementation = _test_transition_rule_impl,
attrs = {
"actual_test": attr.label(cfg = "target", executable = True),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
test = True,
)
def test_arg_cc_test(name, **kwargs):
# Prepend leading underscore (_) to mark the native test as internal.
cc_test_name = "_" + name + "_native_test"
transition_rule_test(
name = name,
# bazel test picks up the args from the transitioned test.
args = kwargs.pop("args", None),
actual_test = ":%s" % cc_test_name,
)
# The native test is built as usual, but mark as "manual" so that blaze test :all
# does not run it.
native.cc_test(name = cc_test_name, tags = kwargs.pop("tags", []) + ["manual"], **kwargs)