Skip to content

Commit

Permalink
Add filegroup rule
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Dec 20, 2024
1 parent 6602ced commit 2348098
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ xacro_file(
)
```


A more complex example:

```
Expand Down Expand Up @@ -50,3 +49,18 @@ Note in the case of the more complex example, you can use bazel-specified filena
```

## xacro_filegroup

Allows you to transform multiple xacro files into a generated filegroup

```
xacro_filegroup(
name = "samples",
srcs = [
"sample1.xml.xacro",
"sample2.xml.xacro",
],
data = [
"box.xml",
],
)
```
39 changes: 39 additions & 0 deletions bazel/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,42 @@ def xacro_file(
extra_args = extra_args,
visibility = visibility,
)

def xacro_filegroup(
name,
srcs = [],
data = [],
tags = [],
visibility = None):
"""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,
tags = tags,
visibility = ["//visibility:private"],
)
native.filegroup(
name = name,
srcs = outs,
visibility = visibility,
)

0 comments on commit 2348098

Please sign in to comment.