Skip to content

Commit

Permalink
Address reviewer feedback:
Browse files Browse the repository at this point in the history
* Remove src glob
* Add provides
* Trim extension based on string length
* Directly expose xacro_file rule

Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Dec 20, 2024
1 parent 2348098 commit 7531667
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 42 deletions.
14 changes: 8 additions & 6 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ write_file(

py_library(
name = "xacro_lib",
srcs = glob(
[
"xacro/**/*.py",
],
allow_empty = False,
),
srcs = [
"xacro/__init__.py",
"xacro/bazel_support.py",
"xacro/cli.py",
"xacro/color.py",
"xacro/substitution_args.py",
"xacro/xmlutils.py",
],
imports = ["."],
visibility = ["//visibility:public"],
deps = [
Expand Down
44 changes: 8 additions & 36 deletions bazel/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ XacroInfo = provider(
fields = ["result", "data"],
)

XACRO_EXTENSION = ".xacro"

def _xacro_impl(ctx):
if ctx.outputs.out:
out = ctx.outputs.out
else:
src = ctx.file.src.basename
if not src.endswith(".xacro"):
if not src.endswith(XACRO_EXTENSION):
fail("xacro_file src should be named *.xacro not {}".format(src))
out = ctx.actions.declare_file(src[:-6])
out = ctx.actions.declare_file(src[:-len(XACRO_EXTENSION)])

# The list of arguments we pass to the script.
args = [ctx.file.src.path, "-o", out.path] + ctx.attr.extra_args
Expand Down Expand Up @@ -43,7 +45,7 @@ def _xacro_impl(ctx):
),
]

_xacro_rule = rule(
xacro_file = rule(
attrs = {
"src": attr.label(
mandatory = True,
Expand All @@ -62,39 +64,9 @@ _xacro_rule = rule(
),
},
implementation = _xacro_impl,
provides = [XacroInfo, DefaultInfo],
)

def xacro_file(
name,
src = None,
out = None,
data = [],
tags = [],
deps = [],
extra_args = [],
visibility = None):
"""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.
out: Optional output file name
data: Optional supplemental files required by the src file.
extra_args: Optional arguments to be interpreted by xacro
"""
_xacro_rule(
name = name,
src = src,
out = out,
data = data,
tags = tags,
deps = deps,
extra_args = extra_args,
visibility = visibility,
)

def xacro_filegroup(
name,
srcs = [],
Expand All @@ -115,11 +87,11 @@ def xacro_filegroup(
"""
outs = []
for src in srcs:
if not src.endswith(".xacro"):
if not src.endswith(XACRO_EXTENSION):
fail("xacro_filegroup srcs should be named *.xacro not {}".format(
src,
))
out = src[:-6]
out = src[:-len(XACRO_EXTENSION)]
outs.append(out)
xacro_file(
name = out,
Expand Down

0 comments on commit 7531667

Please sign in to comment.