Skip to content

Commit

Permalink
workspace: Add ros_xacro (RobotLocomotion#13022)
Browse files Browse the repository at this point in the history
We plan to use this to manage robot URDFs, especially when the upstream
vendor of the URDFs already stores them in xacro'd form.
  • Loading branch information
jwnimmer-tri authored Apr 9, 2020
1 parent 9c69017 commit 5a151dd
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/workspace/default.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ load("@drake//tools/workspace/pycodestyle:repository.bzl", "pycodestyle_reposito
load("@drake//tools/workspace/pycps:repository.bzl", "pycps_repository")
load("@drake//tools/workspace/python:repository.bzl", "python_repository")
load("@drake//tools/workspace/qdldl:repository.bzl", "qdldl_repository")
load("@drake//tools/workspace/ros_xacro:repository.bzl", "ros_xacro_repository") # noqa
load("@drake//tools/workspace/ruby:repository.bzl", "ruby_repository")
load("@drake//tools/workspace/rules_pkg:repository.bzl", "rules_pkg_repository") # noqa
load("@drake//tools/workspace/rules_python:repository.bzl", "rules_python_repository") # noqa
Expand Down Expand Up @@ -224,6 +225,8 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
python_repository(name = "python")
if "qdldl" not in excludes:
qdldl_repository(name = "qdldl", mirrors = mirrors)
if "ros_xacro" not in excludes:
ros_xacro_repository(name = "ros_xacro", mirrors = mirrors)
if "ruby" not in excludes:
ruby_repository(name = "ruby")
if "rules_pkg" not in excludes:
Expand Down
15 changes: 15 additions & 0 deletions tools/workspace/ros_xacro/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- python -*-

load("//tools/lint:lint.bzl", "add_lint_tests")
load("@drake//tools/skylark:drake_py.bzl", "drake_py_unittest")

drake_py_unittest(
name = "xacro_smoke_test",
data = [
":test/sample.xacro",
":test/sample.xml.expected",
"@ros_xacro//:xacro",
],
)

add_lint_tests()
24 changes: 24 additions & 0 deletions tools/workspace/ros_xacro/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- python -*-

load("@drake//tools/skylark:py.bzl", "py_binary")
load("@drake//tools/workspace:generate_file.bzl", "generate_file")

licenses(["notice"]) # BSD-3-Clause

generate_file(
name = "src/ros_xacro_main.py",
# This is the same as scripts/xacro from upstream, except that we lose the
# unused shebang line and we use a filename that is not subject to import
# path conflicts.
content = "import xacro; xacro.main()",
)

py_binary(
name = "xacro",
main = "src/ros_xacro_main.py",
srcs = ["src/ros_xacro_main.py"] + glob([
"src/xacro/**",
], allow_empty = False),
imports = ["src"],
visibility = ["//visibility:public"],
)
18 changes: 18 additions & 0 deletions tools/workspace/ros_xacro/repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- python -*-

load("@drake//tools/workspace:github.bzl", "github_archive")

def ros_xacro_repository(
name,
mirrors = None):
github_archive(
name = name,
repository = "ros/xacro",
# N.B. Even though 1.13.x series is not the highst-numbered release, we
# are using it here because it aligns with the ROS Melodic version
# released for Ubuntu 18.04.
commit = "1.13.5",
sha256 = "145da225ab360e4d8cb9e2a190ff7427550e65c834919f58989284bc83d8f188", # noqa
build_file = "@drake//tools/workspace/ros_xacro:package.BUILD.bazel",
mirrors = mirrors,
)
5 changes: 5 additions & 0 deletions tools/workspace/ros_xacro/test/sample.xacro
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" ?>
<root xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:property name="diameter" value="2.0"/>
<sphere radius="${diameter/2}"/>
</root>
8 changes: 8 additions & 0 deletions tools/workspace/ros_xacro/test/sample.xml.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- | This document was autogenerated by xacro from tools/workspace/ros_xacro/test/sample.xacro | -->
<!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | -->
<!-- =================================================================================== -->
<root>
<sphere radius="1.0"/>
</root>
22 changes: 22 additions & 0 deletions tools/workspace/ros_xacro/test/xacro_smoke_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
import unittest


class XacroSmokeTest(unittest.TestCase):

def test_simple_file(self):
"""Check that we can run xacro on a simple file and get the expected
post-processed result.
"""
self.maxDiff = None
proc = subprocess.run([
"external/ros_xacro/xacro",
"tools/workspace/ros_xacro/test/sample.xacro",
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.assertEqual(proc.returncode, 0, proc.stderr.decode("utf-8"))
actual = proc.stdout.decode("utf-8")
with open("tools/workspace/ros_xacro/test/sample.xml.expected") as f:
expected = f.read()
# We use an atypical (expected, actual) order here so that the diff
# shown during failure has the correct sense of added vs removed lines.
self.assertMultiLineEqual(expected.strip(), actual.strip())

0 comments on commit 5a151dd

Please sign in to comment.