With the present build system (ament), is there a way for me to specify some code that might get ran with the setup scripts? I just need to add some additional environment variables at the moment. In other words, I want to add a new package to my repos file that needs no real compile but simply adds additional environment variables set when sourcing in local_setup.bash.
You’re looking for the
ament_environment_hooks macro, which is similar to catkin’s
An example usage could be the
.bat files the opensplice_cmake_module package uses to set e.g.
This approach will work just fine for me. Thanks guys.
One follow-up question: are environment variables exported through the ament_environment_hooks mechanism exported and available for dependent builds to utilize as part of a long build chain? Or are they only set when explicitly sourcing in the setup script files?
They are available at build time and run time. There is an open issue to have the option to have a separate build and run time set of hooks:
They are available at build time…
To clarify one thing in that regard: it appears that data provided through environment hooks are available at build time only to packages explicitly specifying a build dependency in their package.xml upon the hook provider package.
Yes, that’s intentional. It also happens transitively, so if A defines a hook, B depends on A, and C depends on just B, then C will still see the side effect of the hook in A despite not directly depending on A.
I wasn’t seeing the transitive behavior in my testing. I had expected that, but I don’t think it works at the moment.
In the environment used to
build a package the following packages are being sourced before: the direct
build dependencies and of those all recursive
A package specific local_setup file from the install space will source the following packages: all direct
test dependencies are being sourced.
Thanks. Adding a build_export node on my intermediate package appears to fix the issue I was seeing.