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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
load("@pip//:requirements.bzl", "requirement")
def _generate_interface_impl(ctx):
out_hdrs = [
ctx.actions.declare_file(ctx.attr.interface + ".h"),
ctx.actions.declare_file(ctx.attr.interface + "_mock.hpp"),
]
out_srcs = [
ctx.actions.declare_file(ctx.attr.interface + "_mock.cpp"),
]
args = ["-l", ctx.file.license.path, "-o", out_hdrs[0].dirname]
ctx.actions.run(
tools = ctx.attr._interface_generator_tool[DefaultInfo].data_runfiles.files,
inputs = [ctx.file.license],
outputs = out_srcs + out_hdrs,
executable = ctx.executable._interface_generator_tool,
arguments = args,
mnemonic = "GenerateInterface",
)
compilation_ctx = cc_common.create_compilation_context(
headers = depset(out_hdrs),
includes = depset([out_hdrs[0].dirname]),
)
return [
DefaultInfo(files = depset(out_srcs)),
CcInfo(compilation_context = compilation_ctx),
]
generate_interface_rule = rule(
implementation = _generate_interface_impl,
attrs = {
"interface": attr.string(),
"license": attr.label(allow_single_file = True),
"_interface_generator_tool": attr.label(
executable = True,
cfg = "exec",
allow_files = True,
providers = [DefaultInfo],
default = Label("//:interface_generator"),
),
"outs": attr.output_list(),
},
)
def generate_interface(name, interface, license, visibility = None):
generate_interface_rule(
name = name,
interface = interface,
outs = [name + "_mock.cpp"],
license = license,
visibility = visibility,
)
def py_pytest(name, srcs, deps = [], **kwargs):
native.py_test(
name = name,
srcs = ["//:pytest_wrapper.py"],
main = "//:pytest_wrapper.py",
data = srcs,
args = [
"--black",
"--pylint",
#"--mypy",
] + ["$(location :%s)" % x for x in srcs],
deps = [
requirement("pytest"),
requirement("pytest-black"),
requirement("pytest-pylint"),
requirement("pytest-mypy"),
] + deps,
**kwargs
)
|