-
Notifications
You must be signed in to change notification settings - Fork 23
/
defs.bzl
89 lines (80 loc) · 2.2 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# SPDX-License-Identifier: BSD-3-Clause
def _xacro_impl(ctx):
out = ctx.actions.declare_file(ctx.label.name)
ctx.actions.run(
inputs = [ctx.file.src] + ctx.files.data,
outputs = [out],
executable = ctx.executable._tool,
arguments = [
"-o",
out.path,
ctx.file.src.path,
],
)
return [DefaultInfo(
files = depset([out]),
data_runfiles = ctx.runfiles(files = [out]),
)]
_xacro_rule = rule(
attrs = {
"src": attr.label(
mandatory = True,
allow_single_file = True,
),
"data": attr.label_list(
allow_files = True,
),
"_tool": attr.label(
default = "@xacro//:xacro",
cfg = "host",
executable = True,
),
},
implementation = _xacro_impl,
)
def xacro_file(
name,
src = None,
data = []):
"""Runs xacro on a single input file, creating a single output file.
Xacro is the ROS XML macro tool; http://wiki.ros.org/xacro.
Args:
name: The xml output file of this rule.
src: The single xacro input file of this rule.
data: Optional supplemental files required by the src file.
"""
_xacro_rule(
name = name,
src = src,
data = data,
)
def xacro_filegroup(
name,
srcs = [],
data = []):
"""Runs xacro on several input files, creating a filegroup of the output.
The output filenames will match the input filenames but with the ".xacro"
suffix removed.
Xacro is the ROS XML macro tool; http://wiki.ros.org/xacro.
Args:
name: The name of the filegroup label.
srcs: The xacro input files of this rule.
data: Optional supplemental files required by the srcs.
"""
outs = []
for src in srcs:
if not src.endswith(".xacro"):
fail("xacro_filegroup srcs should be named *.xacro not {}".format(
src,
))
out = src[:-6]
outs.append(out)
xacro_file(
name = out,
src = src,
data = data,
)
native.filegroup(
name = name,
srcs = outs,
)