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 5 commits into
base: main
Choose a base branch
from

Conversation

gergondet-woven
Copy link

@gergondet-woven gergondet-woven commented Feb 4, 2025

Hello drake-ros maintainers,

Thank you for making this project available. We have been using it to build our software for the past months and we have built up a number of patches that we hope can be useful to everyone.

This PR is the first I'm opening and it contains 4 small patches related to various edge cases in the workspace scrapping that we have encountered.

Below is a short summary of the individual patches, I am happy to submit separate PRs if you prefer.

P1: Remove elements that have a condition attribute on ROS1

This is used by a number of packages that are trying to support both versions at the same time.

This patch is actually part of #336 we actually had our own patch that does pretty much the same thing (including packages that have the $ROS_VERSION == 2 condition instead of excluding the $ROS_VERSION == 1). However, that PR incorporates more changes this particular fix is not available on main yet so I hope it's ok to bring it in with this PR.

P2: Fix an issue with some Python packages that have multiple entries in the egg top_level.txt (seen in `launch_testing for example)

P3: Fix an issue with CMake's JSON where libraries' paths are escaped under some conditions (for example if the workspace path has a ~ character)

P4: Include *.inc files in C++ headers of library, afaik, only the domain_bridge package uses this extension

Thanks again for making bazel_ros2_rules and I'm looking forward to your feedback.


This change is Reviewable

Some Python packages (e.g. launch_testing) have multiple entries in
top_level.txt, with this commit they should be hanlded correctly.
When the workspace path has ~ characters (and possibly others), the JSON
output by CMake will be a quoted string, e.g.

```
"lib": "\"/some/ws~~path/libfoo.so\""
```

The extract path will be `"/some/ws~~path/libfoo.so"` instead of
`/some/ws~~path/libfoo.so` and the former will not be treated as path
down the line.
This is used in the domain_bridge package.
@zachfang
Copy link

@IanTheEngineer I assigned you as the reviewer for now just to ensure it's on our radar. Feel free to delegate otherwise.

Copy link
Member

@IanTheEngineer IanTheEngineer left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I kicked off the CI for completeness, but the failures do not necessarily indicate that something is amiss with your PR. I will run some tests locally overnight and report back.

Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion


bazel_ros2_rules/ros2/resources/cmake_tools/file_api.py line 72 at r1 (raw file):

                    self.link_flags.append(fragment['fragment'])
                elif fragment['role'] == 'libraries':
                    # In the generated JSON a library can be in quotes (to escape some characters?)

Nit: We try to wrap lines at 80 characters whenever possible. This applies to the other files in the PR as well.

@gergondet-woven
Copy link
Author

Hello @IanTheEngineer

Thanks for the feedback.

We try to wrap lines at 80 characters whenever possible. This applies to the other files in the PR as well.

Sorry about that, I have pushed an extra commit to wrap all lines here under 80 columns.

Copy link
Member

@IanTheEngineer IanTheEngineer left a comment

Choose a reason for hiding this comment

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

I took another pass looking through the changes this evening. This looks quite good. I have a couple small questions and nits below. Thank you for iterating on this.

Reviewed 5 of 5 files at r2, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @gergondet-woven)


bazel_ros2_rules/ros2/resources/ros2bzl/scraping/ament_python.py line 17 at r2 (raw file):

    top_level = dist.read_text('top_level.txt')
    top_level = top_level.rstrip('\n')
    return str(dist._path), "\n".join(

Nit: Consider storing this string in a variable and returning that for readability. Also, consider adding a comment as to what this is fixing.


bazel_ros2_rules/ros2/resources/ros2bzl/templates.py line 156 at r2 (raw file):

        sandbox(top_level_i)
        for _, top_level in properties.python_packages
        for top_level_i in top_level.split("\n")

Nit: This nested list comprehension is quite clever, but somewhat hard to understand at a glance. Consider breaking it up for readability.


bazel_ros2_rules/ros2/resources/ros2bzl/scraping/metadata.py line 15 at r2 (raw file):

                    elements_to_remove.append((parent, child))
                else:
                    child.attrib.pop("condition")

Nit: Consider conforming to the single quote string convention used by the rest of the file.


bazel_ros2_rules/ros2/resources/ros2bzl/scraping/metadata.py line 15 at r2 (raw file):

                    elements_to_remove.append((parent, child))
                else:
                    child.attrib.pop("condition")

Looking at the ElementTree iter documentation, it states that the behavior is undefined when iterating over a tree if it is then modified.

Would child.attrib.pop('condition') be considered a modification to the tree structure?


bazel_ros2_rules/ros2/resources/cmake_tools/file_api.py line 76 at r2 (raw file):

                    # 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

This comment block is fantastic for conveying the issue and fix. Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants