Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of -r/--remap flags where appropriate. #834

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rclcpp/test/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TEST_F(TestNode, get_name_and_namespace) {
}
{
auto options = rclcpp::NodeOptions()
.arguments({"__ns:=/another_ns"});
.arguments({"-r", "__ns:=/another_ns"});
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns", options);
EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/another_ns", node->get_namespace());
Expand Down
7 changes: 4 additions & 3 deletions rclcpp/test/test_node_global_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ class TestNodeWithGlobalArgs : public ::testing::Test
protected:
static void SetUpTestCase()
{
const char * const args[] = {"proc", "--ros-args", "__node:=global_node_name"};
rclcpp::init(3, args);
const char * const args[] = {"proc", "--ros-args", "-r", "__node:=global_node_name"};
const int argc = sizeof(args) / sizeof(const char *);
rclcpp::init(argc, args);
}
};

TEST_F(TestNodeWithGlobalArgs, local_arguments_before_global) {
auto options = rclcpp::NodeOptions()
.arguments({"__node:=local_arguments_test"});
.arguments({"-r", "__node:=local_arguments_test"});

auto node = rclcpp::Node::make_shared("orig_name", options);
EXPECT_STREQ("local_arguments_test", node->get_name());
Expand Down
8 changes: 4 additions & 4 deletions rclcpp/test/test_node_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
TEST(TestNodeOptions, implicit_ros_args) {
rcl_allocator_t allocator = rcl_get_default_allocator();
auto options = rclcpp::NodeOptions(allocator)
.arguments({"__node:=some_node", "__ns:=/some_ns"});
.arguments({"-r", "__node:=some_node", "-r", "__ns:=/some_ns"});

const rcl_node_options_t * rcl_options = options.get_rcl_node_options();
ASSERT_TRUE(rcl_options != nullptr);
Expand All @@ -52,7 +52,7 @@ TEST(TestNodeOptions, implicit_ros_args) {
TEST(TestNodeOptions, explicit_ros_args) {
rcl_allocator_t allocator = rcl_get_default_allocator();
auto options = rclcpp::NodeOptions(allocator)
.arguments({"--ros-args", "__node:=some_node", "__ns:=/some_ns"});
.arguments({"--ros-args", "-r", "__node:=some_node", "-r", "__ns:=/some_ns"});

const rcl_node_options_t * rcl_options = options.get_rcl_node_options();
ASSERT_TRUE(rcl_options != nullptr);
Expand All @@ -77,8 +77,8 @@ TEST(TestNodeOptions, explicit_ros_args) {
TEST(TestNodeOptions, explicit_ros_args_and_non_ros_args) {
rcl_allocator_t allocator = rcl_get_default_allocator();
auto options = rclcpp::NodeOptions(allocator).arguments({
"--non-ros-flag", "--ros-args", "__node:=some_node",
"__ns:=/some_ns", "--", "non-ros-arg"});
"--non-ros-flag", "--ros-args", "-r", "__node:=some_node",
"-r", "__ns:=/some_ns", "--", "non-ros-arg"});

const rcl_node_options_t * rcl_options = options.get_rcl_node_options();
ASSERT_TRUE(rcl_options != nullptr);
Expand Down
7 changes: 5 additions & 2 deletions rclcpp/test/test_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@

TEST(TestUtilities, remove_ros_arguments) {
const char * const argv[] = {
"process_name", "-d", "--ros-args", "__ns:=/foo/bar", "__ns:=/fiz/buz", "--",
"--foo=bar", "--baz"
"process_name",
"-d", "--ros-args",
"-r", "__ns:=/foo/bar",
"-r", "__ns:=/fiz/buz",
"--", "--foo=bar", "--baz"
};
int argc = sizeof(argv) / sizeof(const char *);
auto args = rclcpp::remove_ros_arguments(argc, argv);
Expand Down
9 changes: 8 additions & 1 deletion rclcpp_components/src/component_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,20 @@ ComponentManager::OnLoadNode(
parameters.push_back(rclcpp::Parameter::from_parameter_msg(p));
}

std::vector<std::string> remap_rules {request->remap_rules};
std::vector<std::string> remap_rules;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test checking if passing arguments to the component manager works ok?
If not, it would be good to add one here or in a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one, to some extent, here. I'd rather keep test coverage extension in a separate PR if we want it.

remap_rules.reserve(request->remap_rules.size() * 2);
for (const std::string & rule : request->remap_rules) {
remap_rules.push_back("-r");
remap_rules.push_back(rule);
}

if (!request->node_name.empty()) {
remap_rules.push_back("-r");
remap_rules.push_back("__node:=" + request->node_name);
}

if (!request->node_namespace.empty()) {
remap_rules.push_back("-r");
remap_rules.push_back("__ns:=" + request->node_namespace);
}

Expand Down