-
Notifications
You must be signed in to change notification settings - Fork 18
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
Environment setup can collide when .dsv files and scripts change the same env var #103
Comments
When prepending values to an env var we aim to not have a trailing separator. The rational is that in the past there were cases where consumers of the env vars didn't support that case. A sourced script can perform the correct prepending. But the command generated for a dsv type like
it will (since the env var was not set before) generate a line like:
which will overwrite the change of the sourced script. |
Just throwing out an idea, what if we always prepend and then do a post-processing step to check that all env vars that were set do not have a trailing |
Should that post processing happen in the shell or in Python? The former would need to be implemented in all primary shells ( How does the post-processing determine which env vars to check? Preferably without needing to discover all Should the post-processing distinguish which trailing separators are actually coming from the "always prepending" or blindly remove them (potentially altering values unintentionally)? |
I guess the former seems like the way to go performance-wise.
We could store this information in a temporary environment variable (which is just a list of all variables prepended to via dsv commands). Note, this could be unset at the end of the post-processing script to avoid environment pollution.
I'm not sure, but maybe it's safest to just remove the trailing separator if and only it is the only character (ie. if the contents of the variable are longer than one character, do nothing). |
That might still break (poorly written) code which isn't capable of handling a trailing separator. |
We know what the first prepended value should be if nothing else was prepended before the first .dsv file was processed. A best effort approach could be to compare the suffix with what we might expect to be there, and if they're equal, remove the trailing separator. |
That sounds like a promising approach 👍 |
I'll try to implement this in colcon first and see how it goes. |
This resolves an issue where environment variables can collid if modified by both .dsv files and scripts. For more detail see ament/ament_package#103 The solution is to always prepend, which will avoid overwriting a variable if previously set by a script. Then we introduce a cleanup command for each variable prepended to in order to remove a possible trailing separator. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
I took a slightly different approach in colcon/colcon-core#254, Instead of setting an environment variable to track changes in the shell scripts, I've done this tracking in Python and appended commands for cleanup. |
* Always prepend with a trailing separator This resolves an issue where environment variables can collid if modified by both .dsv files and scripts. For more detail see ament/ament_package#103 The solution is to always prepend, which will avoid overwriting a variable if previously set by a script. Then we introduce a cleanup command for each variable prepended to in order to remove a possible trailing separator. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Add batch command for trailing separator cleanup Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Address review * Rename operation to "remove trailing separator" * Make the format string definition optional * Simplify logic to remove a trailing separator if it exists (not caring about the last value) Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Minor cleanup Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Declare and document FORMAT_STR_REMOVE_TRAILING_SEPARATOR Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Simplify template logic Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Print cleanup commands directly instead of maintain list Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Add comment explaining change Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Only cleanup for variables initially set by the Python script Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Fix lint and clarify expand documentation Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Fixes #103 Resolves the issue where environment variables can collide if they are modified by both .dsv files and scripts. See the connected issue for more detail. The solution is to always prepend to environment variables to avoid potentially overwriting a value set from another script. To avoid a trailing separator we introduce a cleanup command that is run for each variable prepended to. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
* Always prepend with a trailing separator Fixes #103 Resolves the issue where environment variables can collide if they are modified by both .dsv files and scripts. See the connected issue for more detail. The solution is to always prepend to environment variables to avoid potentially overwriting a value set from another script. To avoid a trailing separator we introduce a cleanup command that is run for each variable prepended to. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
The new performance enhancements that involve preparing the environment in Python (#89) can subtly collide with packages that provide environments hooks as shell scripts (instead of the newer .dsv files). This can happen because the Python code is unaware any environment changes that might occur when sourcing arbitrary shell scripts.
In particular, I ran into this issue while updating ROS 2 Java packages to work with Dashing.
In an attempt to use .dsv files for setting the CLASSPATH variable, I ran into an issue that CLASSPATH previously set by ament_cmake packages are overwritten by the .dsv file-based implementation (e.g. rcljava's JARs are missing from CLASSPATH since they are appended via shell scripts earlier in the topological ordering of packages).
The text was updated successfully, but these errors were encountered: