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

Miscellaneous scrapping fixes #378

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion bazel_ros2_rules/ros2/resources/cmake_tools/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ def __init__(self, target_file: Path):
if fragment['role'] == 'flags':
self.link_flags.append(fragment['fragment'])
elif fragment['role'] == 'libraries':
self.link_libraries.append(fragment['fragment'])
# In the generated JSON a library can be in quotes (to escape some characters?)
# This escaping creates problem down the line ("/usr/lib/libfoo.so" is *not* a path)
# We remove the escaping here so they can be treated normally
link_library = fragment['fragment']
if link_library.startswith('"') and link_library.endswith('"'):
link_library = link_library.strip('"')
self.link_libraries.append(link_library)
elif fragment['role'] == 'libraryPath':
self.link_search_paths.append(fragment['fragment'])
elif fragment['role'] == 'frameworkPath':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def find_python_package(name):
dist = distribution(name)
top_level = dist.read_text('top_level.txt')
top_level = top_level.rstrip('\n')
return str(dist._path), str(dist.locate_file(top_level))
return str(dist._path), '\n'.join([str(dist.locate_file(top_level_i)) for top_level_i in top_level.split('\n')])


def collect_ament_python_package_properties(name, metadata):
Expand Down
17 changes: 17 additions & 0 deletions bazel_ros2_rules/ros2/resources/ros2bzl/scraping/metadata.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import os
import xml.etree.ElementTree as ET

# Remove elements that have a condition attribute on ROS1
def remove_ros1_elements(root):
ros1_condition_value = "$ROS_VERSION == 1"
elements_to_remove = []

for parent in root.iter():
for child in list(parent):
if "condition" in child.attrib:
if child.get('condition') == ros1_condition_value :
elements_to_remove.append((parent, child))
else :
child.attrib.pop("condition")

for parent, child in elements_to_remove:
parent.remove(child)

def parse_package_xml(path_to_package_xml):
tree = ET.parse(path_to_package_xml)

remove_ros1_elements(tree.getroot())

depends = set([
tag.text for tag in tree.findall('./depend')
])
Expand Down
2 changes: 1 addition & 1 deletion bazel_ros2_rules/ros2/resources/ros2bzl/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def configure_package_py_library(
target_name = py_name(name, metadata)
eggs = [sandbox(egg_path) for egg_path, _ in properties.python_packages]
tops = [
sandbox(top_level) for _, top_level in properties.python_packages]
sandbox(top_level_i) for _, top_level in properties.python_packages for top_level_i in top_level.split("\n")]
imports = [os.path.dirname(egg) for egg in eggs]

template = 'templates/package_py_library.bazel.tpl'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cc_library(
name = @name@,
srcs = @srcs@,
hdrs = glob(["{}/**/*.h*".format(x) for x in @headers@], allow_empty = True),
hdrs = glob(["{}/**/*.h*".format(x) for x in @headers@] + ["{}/**/*.inc".format(x) for x in @headers@], allow_empty = True),
includes = @includes@,
copts = @copts@,
defines = @defines@,
Expand Down