Skip to content

Miscellaneous scrapping fixes #378

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

Merged
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
11 changes: 10 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,16 @@ 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, in
# order 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
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
21 changes: 15 additions & 6 deletions bazel_ros2_rules/ros2/resources/ros2bzl/scraping/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
EXTENSION_SUFFIX: Final[str] = sysconfig.get_config_var('EXT_SUFFIX')


def find_package(name: str) -> Tuple[str, str]:
def find_package(name: str) -> Tuple[str, list[str]]:
"""Find a Python package path and top level module path given its `name`."""
dist = importlib.metadata.distribution(name)
top_level = dist.read_text('top_level.txt')
packages = top_level.splitlines()
assert len(packages) == 1
return str(dist._path), str(dist.locate_file(packages[0]))
assert len(packages) >= 1
top_levels = [str(dist.locate_file(package)) for package in packages]
return str(dist._path), top_levels


def get_packages_with_prefixes(prefixes: Optional[Sequence[str]] = None) -> Dict[str, pathlib.Path]:
Expand Down Expand Up @@ -50,9 +51,17 @@ def get_packages_with_prefixes(prefixes: Optional[Sequence[str]] = None) -> Dict
def collect_python_package_properties(name: str, metadata: Dict[str, Any]) -> PyProperties:
"""Collect Python library properties given package `name` and `metadata`."""
properties = PyProperties()
egg_path, top_level = find_package(name)
properties.python_packages = tuple([(egg_path, top_level)])
cc_libraries = glob.glob('{}/**/*.so'.format(top_level), recursive=True)
egg_path, top_levels = find_package(name)
properties.python_packages = tuple(
[(egg_path, top_level) for top_level in top_levels]
)
cc_libraries = sum(
[
glob.glob("{}/**/*.so".format(top_level), recursive=True)
for top_level in top_levels
],
[],
)
if cc_libraries:
cc_libraries.extend(set(
dep for library in cc_libraries
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
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