Skip to content

Commit f5d08b9

Browse files
committed
Update rclrs vendor_interfaces.py script
This updates the vendor_interfaces.py script to also vendor in the action_msgs and unique_identifier_msgs packages. The script is modified to always use a list of package names rather than hard-coding the package names everywhere.
1 parent dad5a51 commit f5d08b9

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

rclrs/vendor_interfaces.py

100644100755
Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,71 @@
1-
# This script produces the `vendor` module inside `rclrs` by copying
2-
# the generated code for the `rosgraph_msgs` and `rcl_interfaces` packages and
3-
# its dependency `builtin_interfaces` and adjusting the submodule paths in the
4-
# code.
1+
#!/usr/bin/env python3
2+
# This script produces the `vendor` module inside `rclrs` by copying the
3+
# generated code for the `rosgraph_msgs`, `rcl_interfaces`, and `action_msgs`
4+
# packages and their dependencies `builtin_interfaces` and
5+
# `unique_identifier_msgs` and adjusting the submodule paths in the code.
56
# If these packages, or the `rosidl_generator_rs`, get changed, you can
67
# update the `vendor` module by running this script.
7-
# The purpose is to avoid an external dependency on `rcl_interfaces`, which
8-
# is not published on crates.io.
8+
# The purpose is to avoid an external dependency on these message packages,
9+
# which are not published on crates.io.
910

1011
import argparse
1112
from pathlib import Path
1213
import shutil
1314
import subprocess
1415

16+
vendored_packages = [
17+
"action_msgs",
18+
"builtin_interfaces",
19+
"rcl_interfaces",
20+
"rosgraph_msgs",
21+
"unique_identifier_msgs",
22+
]
23+
1524
def get_args():
16-
parser = argparse.ArgumentParser(description='Vendor the rcl_interfaces, builtin_interfaces and rosgraph_msgs packages into rclrs')
25+
parser = argparse.ArgumentParser(description='Vendor message packages into rclrs')
1726
parser.add_argument('install_base', metavar='install_base', type=Path,
1827
help='the install base (must have non-merged layout)')
1928
return parser.parse_args()
2029

21-
def adjust(pkg, text):
22-
text = text.replace('builtin_interfaces::', 'crate::vendor::builtin_interfaces::')
23-
text = text.replace('rcl_interfaces::', 'crate::vendor::rcl_interfaces::')
24-
text = text.replace('rosgraph_msgs::', 'crate::vendor::rosgraph_msgs::')
25-
text = text.replace('crate::msg', f'crate::vendor::{pkg}::msg')
26-
text = text.replace('crate::srv', f'crate::vendor::{pkg}::srv')
30+
def adjust(current_package, text):
31+
for pkg in vendored_packages:
32+
text = text.replace(f'{pkg}::', f'crate::vendor::{pkg}::')
33+
text = text.replace('crate::msg', f'crate::vendor::{current_package}::msg')
34+
text = text.replace('crate::srv', f'crate::vendor::{current_package}::srv')
35+
text = text.replace('crate::action', f'crate::vendor::{current_package}::action')
2736
return text
2837

2938
def copy_adjusted(pkg, src, dst):
3039
dst.write_text(adjust(pkg, src.read_text()))
3140
subprocess.check_call(['rustfmt', str(dst)])
3241

33-
mod_contents = """//! Created by {}
34-
#![allow(dead_code)]
35-
#![allow(clippy::derive_partial_eq_without_eq)]
36-
37-
pub mod builtin_interfaces;
38-
pub mod rcl_interfaces;
39-
pub mod rosgraph_msgs;
40-
""".format(Path(__file__).name)
41-
4242
def main():
4343
args = get_args()
4444
assert args.install_base.is_dir(), "Install base does not exist"
45-
assert (args.install_base / 'builtin_interfaces').is_dir(), "Install base does not contain builtin_interfaces"
46-
assert (args.install_base / 'rcl_interfaces').is_dir(), "Install base does not contain rcl_interfaces"
47-
assert (args.install_base / 'rosgraph_msgs').is_dir(), "Install base does not contain rosgraph_msgs"
45+
for pkg in vendored_packages:
46+
assert (args.install_base / pkg).is_dir(), f"Install base does not contain {pkg}"
4847
rclrs_root = Path(__file__).parent
4948
vendor_dir = rclrs_root / 'src' / 'vendor'
5049
if vendor_dir.exists():
5150
shutil.rmtree(vendor_dir)
52-
for pkg in ['builtin_interfaces', 'rcl_interfaces', 'rosgraph_msgs']:
51+
for pkg in vendored_packages:
5352
src = args.install_base / pkg / 'share' / pkg / 'rust' / 'src'
5453
dst = vendor_dir / pkg
5554
dst.mkdir(parents=True)
5655
copy_adjusted(pkg, src / 'msg.rs', dst / 'msg.rs')
5756
if (src / 'srv.rs').is_file():
5857
copy_adjusted(pkg, src / 'srv.rs', dst / 'srv.rs')
58+
if (src / 'action.rs').is_file():
59+
copy_adjusted(pkg, src / 'action.rs', dst / 'action.rs')
5960
copy_adjusted(pkg, src / 'lib.rs', dst / 'mod.rs') # Rename lib.rs to mod.rs
60-
(vendor_dir / 'mod.rs').write_text(mod_contents)
61-
6261

62+
mod_contents = "//! Created by {}\n".format(Path(__file__).name)
63+
mod_contents += "#![allow(dead_code)]\n"
64+
mod_contents += "#![allow(clippy::derive_partial_eq_without_eq)]\n"
65+
mod_contents += "\n"
66+
for pkg in vendored_packages:
67+
mod_contents += f"pub mod {pkg};\n"
68+
(vendor_dir / 'mod.rs').write_text(mod_contents)
6369

6470
if __name__ == '__main__':
6571
main()

0 commit comments

Comments
 (0)