Skip to content

Commit 0041bf0

Browse files
Added support for data and test
1 parent 7a93b3c commit 0041bf0

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

bazel_ros2_rules/lib/private/xacro.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _ros_xacro_impl(ctx):
4747
args.add("-o", output)
4848
args.add_all(ctx.attr.xacro_args)
4949
ctx.actions.run(
50-
inputs = [ctx.file.src] + ctx.files.deps,
50+
inputs = [ctx.file.src] + ctx.files.data,
5151
outputs = [output],
5252
executable = ctx.executable.xacro_tool,
5353
arguments = [args],
@@ -61,7 +61,7 @@ _ros_xacro_rule = rule(
6161
mandatory = True,
6262
doc = "The main .urdf.xacro file to process.",
6363
),
64-
"deps": attr.label_list(
64+
"data": attr.label_list(
6565
allow_files = [".xacro"],
6666
default = [],
6767
doc = "Additional .xacro files included via relative paths.",
@@ -80,7 +80,7 @@ _ros_xacro_rule = rule(
8080
implementation = _ros_xacro_impl,
8181
)
8282

83-
def ros_xacro(name, src, deps = [], ros_packages = {}, xacro_args = [], visibility = None, **kwargs):
83+
def ros_xacro(name, src, data = [], ros_packages = {}, xacro_args = [], visibility = None, **kwargs):
8484
"""Transforms a .urdf.xacro file into a .urdf file.
8585
8686
User-defined packages are declared inline via the ros_packages dict. Each
@@ -97,7 +97,7 @@ def ros_xacro(name, src, deps = [], ros_packages = {}, xacro_args = [], visibili
9797
ros_xacro(
9898
name = "example",
9999
src = "robot.urdf.xacro",
100-
deps = ["base.xacro", "arm.xacro"],
100+
data = ["base.xacro", "arm.xacro"],
101101
ros_packages = {
102102
"my_robot": glob(["urdf/**"]),
103103
},
@@ -107,7 +107,7 @@ def ros_xacro(name, src, deps = [], ros_packages = {}, xacro_args = [], visibili
107107
Args:
108108
name: target name; the output file is named <name>.urdf
109109
src: the .urdf.xacro source file
110-
deps: additional .xacro files included via relative paths
110+
data: additional .xacro files included via relative paths
111111
(i.e. plain <xacro:include filename="other.xacro"/>);
112112
must be listed here so Bazel sandboxes them and tracks
113113
them as dependencies for incremental rebuilds
@@ -154,7 +154,7 @@ def ros_xacro(name, src, deps = [], ros_packages = {}, xacro_args = [], visibili
154154
_ros_xacro_rule(
155155
name = name,
156156
src = src,
157-
deps = deps,
157+
data = data,
158158
xacro_args = xacro_args,
159159
xacro_tool = ":" + runner_name,
160160
visibility = visibility,

ros2_example_bazel_installed/ros2_example_xacro/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("@ros2//:xacro.bzl", "ros_xacro")
44
ros_xacro(
55
name = "example",
66
src = "example.urdf.xacro",
7+
data = ["snippet.xacro"],
78
ros_packages = {
89
"my_robot": glob(["urdf/**"]),
910
},

ros2_example_bazel_installed/ros2_example_xacro/example.urdf.xacro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<!-- urdf/robot.urdf.xacro -->
22
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
3+
<!-- Should be able to include `.xacros` via a relative path (data= attribute) -->
4+
<xacro:include filename="snippet.xacro"/>
35
<!-- Should be able to compose with local `.xacros` -->
46
<xacro:include filename="$(find my_robot)/urdf/macros.xacro"/>
57
<!-- Should be able to bring `.xacros` installed in the system (via `realsense2_description` for this example)-->
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0"?>
2+
<!-- A minimal xacro included via a relative path to test the data= attribute. -->
3+
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
4+
<link name="snippet_link"/>
5+
</robot>

ros2_example_bazel_installed/ros2_example_xacro/test/xacro_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ def test_local_package_macros_expanded():
3030
)
3131

3232

33+
def test_relative_include_expanded():
34+
"""A xacro included via a relative path (data=) appears in the output."""
35+
content = _read_urdf()
36+
assert 'name="snippet_link"' in content, (
37+
"Expected snippet_link from snippet.xacro in output:\n" + content
38+
)
39+
40+
3341
if __name__ == "__main__":
3442
test_sim_arg_is_substituted()
3543
test_local_package_macros_expanded()
44+
test_relative_include_expanded()
3645
print("All tests passed.")

0 commit comments

Comments
 (0)