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

Add environment hook for CLASSPATH #27

Merged
merged 1 commit into from
Jul 9, 2021
Merged

Conversation

jacobperron
Copy link
Contributor

This is a quick fix to a problem described in ros2-java/ament_java#9

TL;DR
Jars produced by gradle packages are not added to the CLASSPATH, and so this PR let's colcon handle it.

Maybe this is better suited to go in colcon-ros-gradle, I don't know. But, long-term, I think we should have a standalone Java library that contains helpers for registering ament packages. Such a library can be used by the ament gradle plugin or elsewhere.

@jpace121
Copy link

How likely is this to get merged?

I'm trying to use colcon to build a non-ros mixed language workspace, including some components built with gradle, and this PR was very helpful in getting that working.

@esteve
Copy link
Collaborator

esteve commented Aug 11, 2020

@jacobperron thanks! I agree this should be in colcon-ros-gradle, how hard would it be to port it there?

@ivanpauno
Copy link
Collaborator

@jacobperron thanks! I agree this should be in colcon-ros-gradle, how hard would it be to port it there?

IMHO this patch seems well suited to here, e.g. "colcon python" adds modules to PYTHONPATH in an environment hoook, and not "colcon ros python" (see here).

Anyways, getting this in any of the two works for me 😄 .

@@ -56,14 +58,25 @@ def add_arguments(self, *, parser): # noqa: D102
help='Run a specific task instead of the default task')

async def build(
self, *, additional_hooks=None, skip_hook_creation=False
self, *, additional_hooks=[], skip_hook_creation=False
Copy link
Collaborator

Choose a reason for hiding this comment

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

using an empty list as a default value is generally a problem

https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I've rebased my changes on master and fixed this. PTAL

'classpath_jars', Path(args.install_base), pkg.name,
'CLASSPATH', os.path.join('share', pkg.name, 'java', '*'),
mode='prepend')
additional_hooks += create_environment_hook(
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we also need the directory?
I think that the wildcard is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reading the the docs, I'm lead to believe we need both the path and the wildcard to account for class files AND jars:

A class path entry that contains an asterisk () does not match class files. To match both classes and JAR files in a single directory mydir, use either mydir:mydir/ or mydir/*:mydir. The order chosen determines whether the classes and resources in mydir are loaded before JAR files in mydir or vice versa.

@jacobperron jacobperron merged commit 9dbd651 into master Jul 9, 2021
@delete-merged-branch delete-merged-branch bot deleted the jacob/classpath_hook branch July 9, 2021 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants