diff --git a/MODULE.bazel b/MODULE.bazel
index 2703f24b..c90d50dd 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -23,6 +23,11 @@ bazel_dep(name = "sqlite3", version = "3.42.0.bcr.1")
bazel_dep(name = "tinyxml", version = "2.6.2")
bazel_dep(name = "tinyxml2", version = "10.0.0")
bazel_dep(name = "websocketpp", version = "0.8.2.bcr.3")
+bazel_dep(name = "xacro", version = "2.0.12", repo_name = "ros2_xacro")
+#local_path_override(
+# module_name = "xacro",
+# path = "../xacro",
+#)
bazel_dep(name = "yaml-cpp", version = "0.8.0")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
bazel_dep(name = "zstd", version = "1.5.6")
@@ -170,7 +175,6 @@ use_repo(
"ros2_unique_identifier_msgs",
"ros2_urdfdom",
"ros2_urdfdom_headers",
- "ros2_xacro",
"ros2cli",
"rules_ros2_config_clang",
)
diff --git a/examples/foxglove_bridge/BUILD.bazel b/examples/foxglove_bridge/BUILD.bazel
index 5e5624e3..75681472 100644
--- a/examples/foxglove_bridge/BUILD.bazel
+++ b/examples/foxglove_bridge/BUILD.bazel
@@ -1,6 +1,6 @@
load("@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", "ros2_cpp_binary")
load("@com_github_mvukov_rules_ros2//ros2:launch.bzl", "ros2_launch")
-load("@com_github_mvukov_rules_ros2//ros2:xacro.bzl", "xacro")
+load("@ros2_xacro//bazel:defs.bzl", "xacro_file")
load(
"@com_github_mvukov_rules_ros2//third_party:expand_template.bzl",
"expand_template",
@@ -17,9 +17,9 @@ ros2_cpp_binary(
)
# Creates a URDF representation from the given xacro file.
-xacro(
+xacro_file(
name = "sam_bot",
- srcs = ["sam_bot.xacro"],
+ src = "sam_bot.urdf.xacro",
)
expand_template(
diff --git a/examples/foxglove_bridge/sam_bot.xacro b/examples/foxglove_bridge/sam_bot.urdf.xacro
similarity index 100%
rename from examples/foxglove_bridge/sam_bot.xacro
rename to examples/foxglove_bridge/sam_bot.urdf.xacro
diff --git a/repositories/repositories.bzl b/repositories/repositories.bzl
index 5d84e4a1..4033ca2c 100644
--- a/repositories/repositories.bzl
+++ b/repositories/repositories.bzl
@@ -234,6 +234,14 @@ def ros2_workspace_repositories():
],
)
+ maybe(
+ http_archive,
+ name = "ros2_xacro",
+ sha256 = "6df0d44af8a6bf9f23f0536ce167a0cd7b4c01281100dfea7e17d504363b424d",
+ strip_prefix = "xacro-2.0.13",
+ urls = ["https://github.com/ros/xacro/archive/refs/tags/2.0.13.tar.gz"],
+ )
+
def ros2_repositories():
"""Import ROS 2 repositories."""
@@ -267,15 +275,6 @@ def ros2_repositories():
urls = ["https://github.com/foxglove/ros-foxglove-bridge/archive/refs/tags/0.7.9.tar.gz"],
)
- maybe(
- http_archive,
- name = "ros2_xacro",
- build_file = "@com_github_mvukov_rules_ros2//repositories:xacro.BUILD.bazel",
- sha256 = "a8802a5b48f7479bae1238e822ac4ebb47660221eb9bc40a608e899d60f3f7e4",
- strip_prefix = "xacro-2.0.9",
- urls = ["https://github.com/ros/xacro/archive/refs/tags/2.0.9.tar.gz"],
- )
-
# Version copied from https://github.com/ros2/orocos_kdl_vendor/blob/0.2.5/orocos_kdl_vendor/CMakeLists.txt#L58.
maybe(
http_archive,
diff --git a/repositories/xacro.BUILD.bazel b/repositories/xacro.BUILD.bazel
deleted file mode 100644
index 4fb1e309..00000000
--- a/repositories/xacro.BUILD.bazel
+++ /dev/null
@@ -1,45 +0,0 @@
-""" Builds xacro.
-"""
-
-load("@rules_python//python:defs.bzl", "py_binary", "py_library")
-load("@rules_ros2_pip_deps//:requirements.bzl", "requirement")
-
-py_library(
- name = "xacro",
- srcs = glob(["xacro/*.py"]),
- visibility = ["//visibility:public"],
- deps = [
- "@ros2_ament_index//:ament_index_python",
- requirement("pyyaml"),
- ],
-)
-
-genrule(
- name = "main",
- outs = ["main.py"],
- cmd = """cat > $@ << EOL
-import argparse
-import contextlib
-import sys
-
-import xacro
-
-parser = argparse.ArgumentParser()
-parser.add_argument('--output', type=str, required=True)
-args, xacro_args = parser.parse_known_args()
-
-with open(args.output, 'w', encoding='utf-8') as stream:
- with contextlib.redirect_stdout(stream):
- sys.argv = sys.argv[:1] + xacro_args
- xacro.main()
-EOL
-""",
-)
-
-py_binary(
- name = "app",
- srcs = [":main"],
- main = "main.py",
- visibility = ["//visibility:public"],
- deps = [":xacro"],
-)
diff --git a/ros2/BUILD.bazel b/ros2/BUILD.bazel
index 94ef6863..fd9a53c9 100644
--- a/ros2/BUILD.bazel
+++ b/ros2/BUILD.bazel
@@ -28,7 +28,6 @@ exports_files([
"test.bzl",
"test.py.tpl",
"topic.bzl",
- "xacro.bzl",
])
string_flag(
diff --git a/ros2/test/xacro/BUILD.bazel b/ros2/test/xacro/BUILD.bazel
index c20fedbc..660bb223 100644
--- a/ros2/test/xacro/BUILD.bazel
+++ b/ros2/test/xacro/BUILD.bazel
@@ -1,25 +1,28 @@
load("@rules_python//python:defs.bzl", "py_test")
-load("//ros2:xacro.bzl", "xacro")
+load("@ros2_xacro//bazel:defs.bzl", "xacro_file")
-xacro(
+xacro_file(
name = "test_urdf",
- srcs = ["test.xacro"],
+ src = "test.urdf.xacro",
)
-xacro(
+xacro_file(
+ name = "sample1",
+ src = "sample1.urdf.xacro",
+)
+
+xacro_file(
name = "test_include",
- srcs = [
- "sample1.xacro",
- ],
- main = "sample2.xacro",
+ src = "sample2.urdf.xacro",
+ deps = ["sample1"],
)
-xacro(
+xacro_file(
name = "test_with_params",
- srcs = [
+ data = [
"params.yaml",
],
- main = "test_with_params.xacro",
+ src = "test_with_params.urdf.xacro",
)
py_test(
diff --git a/ros2/test/xacro/sample1.xacro b/ros2/test/xacro/sample1.urdf.xacro
similarity index 100%
rename from ros2/test/xacro/sample1.xacro
rename to ros2/test/xacro/sample1.urdf.xacro
diff --git a/ros2/test/xacro/sample2.xacro b/ros2/test/xacro/sample2.urdf.xacro
similarity index 100%
rename from ros2/test/xacro/sample2.xacro
rename to ros2/test/xacro/sample2.urdf.xacro
diff --git a/ros2/test/xacro/test.xacro b/ros2/test/xacro/test.urdf.xacro
similarity index 100%
rename from ros2/test/xacro/test.xacro
rename to ros2/test/xacro/test.urdf.xacro
diff --git a/ros2/test/xacro/test_with_params.xacro b/ros2/test/xacro/test_with_params.urdf.xacro
similarity index 100%
rename from ros2/test/xacro/test_with_params.xacro
rename to ros2/test/xacro/test_with_params.urdf.xacro
diff --git a/ros2/test/xacro/tests.py b/ros2/test/xacro/tests.py
index d61242a2..98035d11 100644
--- a/ros2/test/xacro/tests.py
+++ b/ros2/test/xacro/tests.py
@@ -21,7 +21,7 @@ def test_urdf(self):
"""
- self._check('ros2/test/xacro/test_urdf/model.urdf', expected_xml)
+ self._check('ros2/test/xacro/test_urdf.urdf', expected_xml)
def test_include(self):
expected_xml = """
@@ -29,7 +29,7 @@ def test_include(self):
"""
- self._check('ros2/test/xacro/test_include/model.urdf', expected_xml)
+ self._check('ros2/test/xacro/test_include.urdf', expected_xml)
def test_with_params(self):
expected_xml = """
@@ -37,7 +37,7 @@ def test_with_params(self):
"""
- self._check('ros2/test/xacro/test_with_params/model.urdf', expected_xml)
+ self._check('ros2/test/xacro/test_with_params.urdf', expected_xml)
if __name__ == '__main__':
diff --git a/ros2/xacro.bzl b/ros2/xacro.bzl
deleted file mode 100644
index 3a7c9f34..00000000
--- a/ros2/xacro.bzl
+++ /dev/null
@@ -1,50 +0,0 @@
-""" Defines a rule for transforming xacro files to a UDRF.
-"""
-
-def _xacro_impl(ctx):
- output = ctx.actions.declare_file(ctx.attr.name + "/model.urdf")
- srcs = ctx.files.srcs
- main = ctx.files.main
-
- if len(main) == 0:
- main = [srcs[0]]
- elif main not in srcs:
- srcs = srcs + main
-
- args = ctx.actions.args()
- args.add_all(ctx.attr.args)
- args.add_all(main)
- args.add(output, format = "--output=%s")
-
- ctx.actions.run(
- inputs = srcs,
- outputs = [output],
- executable = ctx.executable._xacro,
- arguments = [args],
- mnemonic = "Ros2Xacro",
- progress_message = "Generating URDF for %{label}",
- )
- return [
- DefaultInfo(
- files = depset([output]),
- ),
- ]
-
-xacro = rule(
- attrs = {
- "srcs": attr.label_list(
- allow_files = [".xacro", ".yaml"],
- mandatory = True,
- ),
- "main": attr.label(
- allow_files = [".xacro"],
- ),
- "args": attr.string_list(),
- "_xacro": attr.label(
- default = Label("@ros2_xacro//:app"),
- executable = True,
- cfg = "exec",
- ),
- },
- implementation = _xacro_impl,
-)