diff --git a/bazel_ros2_rules/ros2/rosidl.bzl b/bazel_ros2_rules/ros2/rosidl.bzl index 7360d5f4..f017f864 100644 --- a/bazel_ros2_rules/ros2/rosidl.bzl +++ b/bazel_ros2_rules/ros2/rosidl.bzl @@ -399,6 +399,7 @@ def rosidl_c_library( group, interfaces, includes = [], + data = [], deps = [], cc_library_rule = native.cc_library, **kwargs): @@ -411,6 +412,7 @@ def rosidl_c_library( interfaces: interface definition files, only files are allowed includes: optional interface definition includes, both files and filegroups are allowed. + data: optional data dependencies. deps: optional library dependencies. cc_library_rule: optional cc_library() rule override. @@ -460,6 +462,7 @@ def rosidl_c_library( srcs = generated_c_sources, hdrs = generated_c_headers, includes = [include], + data = data, deps = deps, **kwargs ) @@ -469,6 +472,7 @@ def rosidl_cc_library( group, interfaces, includes = [], + data = [], deps = [], cc_library_rule = native.cc_library, **kwargs): @@ -480,6 +484,7 @@ def rosidl_cc_library( group: interface group name (i.e. ROS 2 package name). interfaces: interface definition files. includes: optional interface definition includes. + data: optional data dependencies. deps: optional library dependencies. cc_library_rule: optional cc_library() rule override. @@ -518,6 +523,7 @@ def rosidl_cc_library( name = name, hdrs = generated_cc_headers, includes = [include], + data = data, deps = deps + [ REPOSITORY_ROOT + ":rosidl_runtime_cpp_cc", ], @@ -533,6 +539,7 @@ def rosidl_py_library( interfaces, typesupports, includes = [], + data = [], c_deps = [], py_deps = [], cc_binary_rule = native.cc_binary, @@ -550,6 +557,7 @@ def rosidl_py_library( C typesupport libraries, from typesupport name to library target label. includes: optional interface definition includes. + data: optional data dependencies. c_deps: optional Python C extension dependencies. py_deps: optional Python dependencies. cc_binary_rule: optional cc_binary() rule override. @@ -637,7 +645,7 @@ def rosidl_py_library( name = name, srcs = generated_py_sources, imports = [import_], - data = py_data, + data = data + py_data, deps = py_deps, **kwargs ) @@ -647,6 +655,7 @@ def rosidl_typesupport_fastrtps_cc_library( group, interfaces, includes = [], + data = [], deps = [], cc_binary_rule = native.cc_binary, cc_library_rule = native.cc_library, @@ -659,6 +668,7 @@ def rosidl_typesupport_fastrtps_cc_library( group: interface group name (i.e. ROS 2 package name). interfaces: interface definition files. includes: optional interface definition includes. + data: optional data dependencies. deps: optional library dependencies. cc_binary_rule: optional cc_binary() rule override. cc_library_rule: optional cc_library() rule override. @@ -702,6 +712,7 @@ def rosidl_typesupport_fastrtps_cc_library( cc_binary_rule( name = name, srcs = generated_cc_sources, + data = data, deps = deps + [ _make_private_label(name, "_hdrs"), REPOSITORY_ROOT + ":fastcdr_cc", @@ -719,6 +730,7 @@ def rosidl_typesupport_fastrtps_c_library( group, interfaces, includes = [], + data = [], deps = [], cc_binary_rule = native.cc_binary, cc_library_rule = native.cc_library, @@ -731,6 +743,7 @@ def rosidl_typesupport_fastrtps_c_library( group: interface group name (i.e. ROS 2 package name). interfaces: interface definition files. includes: optional interface definition includes. + data: optional data dependencies. deps: optional library dependencies. cc_binary_rule: optional cc_binary() rule override. cc_library_rule: optional cc_library() rule override. @@ -775,6 +788,7 @@ def rosidl_typesupport_fastrtps_c_library( name = name, srcs = generated_c_sources, linkshared = True, + data = data, deps = deps + [ _make_private_label(name, "_hdrs"), REPOSITORY_ROOT + ":fastcdr_cc", @@ -792,6 +806,7 @@ def rosidl_typesupport_introspection_c_library( group, interfaces, includes = [], + data = [], deps = [], cc_binary_rule = native.cc_binary, cc_library_rule = native.cc_library, @@ -804,6 +819,7 @@ def rosidl_typesupport_introspection_c_library( group: interface group name (i.e. ROS 2 package name). interfaces: interface definition files. includes: optional interface definition includes. + data: optional data dependencies. deps: optional library dependencies. cc_binary_rule: optional cc_binary() rule override. cc_library_rule: optional cc_library() rule override. @@ -849,6 +865,7 @@ def rosidl_typesupport_introspection_c_library( name = name, srcs = generated_c_sources, linkshared = True, + data = data, deps = deps + [ _make_private_label(name, "_hdrs"), REPOSITORY_ROOT + ":rosidl_typesupport_introspection_c_cc", @@ -861,6 +878,7 @@ def rosidl_typesupport_introspection_cc_library( group, interfaces, includes = [], + data = [], deps = [], cc_binary_rule = native.cc_binary, cc_library_rule = native.cc_library, @@ -873,6 +891,7 @@ def rosidl_typesupport_introspection_cc_library( group: interface group name (i.e. ROS 2 package name). interfaces: interface definition files. includes: optional interface definition includes. + data: optional data dependencies. deps: optional library dependencies. cc_binary_rule: optional cc_binary() rule override. cc_library_rule: optional cc_library() rule override. @@ -918,6 +937,7 @@ def rosidl_typesupport_introspection_cc_library( name = name, srcs = generated_cc_sources, linkshared = True, + data = data, deps = deps + [ _make_private_label(name, "_hdrs"), REPOSITORY_ROOT + ":rosidl_runtime_c_cc", @@ -934,6 +954,7 @@ def rosidl_typesupport_c_library( interfaces, typesupports, includes = [], + data = [], deps = [], cc_binary_rule = native.cc_binary, **kwargs): @@ -948,6 +969,7 @@ def rosidl_typesupport_c_library( C typesupport libraries, from typesupport name to library target label. includes: optional interface definition includes + data: optional data dependencies deps: optional library dependencies cc_binary_rule: optional cc_binary() rule override @@ -982,7 +1004,7 @@ def rosidl_typesupport_c_library( srcs = generated_sources, includes = [include], linkshared = True, - data = typesupports.values(), + data = data + typesupports.values(), deps = deps + [ _make_private_label(label, "_hdrs") for label in typesupports.values() @@ -1000,6 +1022,7 @@ def rosidl_typesupport_cc_library( interfaces, typesupports, includes = [], + data = [], deps = [], cc_binary_rule = native.cc_binary, **kwargs): @@ -1014,6 +1037,7 @@ def rosidl_typesupport_cc_library( C++ typesupport libraries, from typesupport name to library target label. includes: optional interface definition includes + data: optional data dependencies deps: optional library dependencies cc_binary_rule: optional cc_binary() rule override @@ -1044,7 +1068,7 @@ def rosidl_typesupport_cc_library( cc_binary_rule( name = name, srcs = generated_cc_sources, - data = typesupports.values(), + data = data + typesupports.values(), includes = [include], linkshared = True, deps = deps + [ @@ -1062,6 +1086,7 @@ def rosidl_typesupport_cc_library( def rosidl_cc_support( name, interfaces, + data, deps, group = None, cc_binary_rule = native.cc_binary, @@ -1075,6 +1100,7 @@ def rosidl_cc_support( Args: name: interface group name, used as prefix for target names interfaces: interface definition files + data: optional data dependencies deps: optional interface group dependencies group: optional interface group name override, useful when target name cannot be forced to match the intended package @@ -1158,6 +1184,7 @@ def rosidl_cc_support( srcs = [ _make_public_label(name, "__rosidl_typesupport_cpp"), ] + typesupports.values(), + data = data, deps = [_make_private_label(name, "__rosidl_cpp")], linkstatic = True, **kwargs @@ -1166,6 +1193,7 @@ def rosidl_cc_support( def rosidl_py_support( name, interfaces, + data, deps, group = None, cc_binary_rule = native.cc_binary, @@ -1180,6 +1208,7 @@ def rosidl_py_support( Args: name: interface group name, used as prefix for target names interfaces: interface definition files + data: optional data dependencies deps: optional interface group dependencies group: optional interface group name override, useful when target name cannot be forced to match the intended package @@ -1277,6 +1306,7 @@ def rosidl_py_support( group = group or name, interfaces = interfaces, includes = [_make_public_label(dep, "_defs") for dep in deps], + data = data, py_deps = [_make_public_label(dep, "_py") for dep in deps], c_deps = [_make_public_label(name, "_c")] + [ _make_public_label(dep, "_c") @@ -1291,6 +1321,7 @@ def rosidl_py_support( def rosidl_interfaces_group( name, interfaces, + data = [], deps = [], group = None, cc_binary_rule = native.cc_binary, @@ -1306,6 +1337,7 @@ def rosidl_interfaces_group( Args: name: interface group name, used as prefix for target names interfaces: interface definition files + data: optional data dependencies deps: optional interface group dependencies group: optional interface group name override, useful when target name cannot be forced to match the intended package @@ -1328,8 +1360,11 @@ def rosidl_interfaces_group( if group != None: name = group + defs_name = _make_public_name(name, "_defs") + data = data + [defs_name] + rosidl_definitions_filegroup( - name = _make_public_name(name, "_defs"), + name = defs_name, group = group or name, interfaces = interfaces, includes = [_make_public_label(dep, "_defs") for dep in deps], @@ -1338,9 +1373,10 @@ def rosidl_interfaces_group( rosidl_cc_support( name, - interfaces, - deps, - group, + interfaces = interfaces, + data = data, + deps = deps, + group = group, cc_binary_rule = cc_binary_rule, cc_library_rule = cc_library_rule, **kwargs @@ -1348,9 +1384,10 @@ def rosidl_interfaces_group( rosidl_py_support( name, - interfaces, - deps, - group, + interfaces = interfaces, + data = data, + deps = deps, + group = group, cc_binary_rule = cc_binary_rule, cc_library_rule = cc_library_rule, py_library_rule = py_library_rule, diff --git a/bazel_ros2_rules/ros2/tools/dload.bzl b/bazel_ros2_rules/ros2/tools/dload.bzl index b2100485..a4192268 100644 --- a/bazel_ros2_rules/ros2/tools/dload.bzl +++ b/bazel_ros2_rules/ros2/tools/dload.bzl @@ -102,11 +102,16 @@ def do_dload_shim(ctx, template, to_list): env_changes["AMENT_PREFIX_PATH"] = ["path-prepend"] if env_changes["AMENT_PREFIX_PATH"][0] != "path-prepend": fail("failed assumption - AMENT_PREFIX_PATH was not prepended to") - env_changes["AMENT_PREFIX_PATH"].extend( - ctx.attr.target[AggregatedAmentIndexes].prefixes, - ) + ament_prefixes = ctx.attr.target[AggregatedAmentIndexes].prefixes + + # Deduplicate entries to avoid hitting 'Argument list too long' errors. + ament_prefixes = depset(ament_prefixes).to_list() + env_changes["AMENT_PREFIX_PATH"].extend(ament_prefixes) envvars = env_changes.keys() + + # TODO(eric.cousineau): Should deduplicate entries for path-prepend and + # path-append. actions = env_changes.values() shim_content = template.format( diff --git a/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel b/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel index 321e4bed..8be86500 100644 --- a/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel +++ b/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel @@ -227,11 +227,12 @@ ros_py_test( srcs = ["test/custom_message_list_test.py"], data = [ # This is the main key. You must provide the generated definitions as - # a dependency. It can come through data as is done here, or via any - # dependency, such as the C++ (*_cc) or Python (*_py) targets. + # a dependency. It can come through data such as the C++ (*_cc) or + # Python (*_py) targets as is done here, or directly via the + # definitions targets (*_defs). # Otherwise, `ros2 interface ...` will indicate the message type is # invalid. - ":ros2_example_apps_msgs_defs", + ":ros2_example_apps_msgs_py", "@ros2", ], main = "test/custom_message_list_test.py",