-
Notifications
You must be signed in to change notification settings - Fork 1
Fix dune path in nested shells #13
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
Fix dune path in nested shells #13
Conversation
0d530f5 to
51f3e01
Compare
505f562 to
6804243
Compare
|
Fixes #10 |
c1525e4 to
363aeaa
Compare
|
@Sudha247 this is now ready for review. Heads up that I replaced the The sed script is |
When starting a shell from an existing shell where the shell config has already been sourced, or when sourcing a shell config for a second time within the same shell session, any opam setup in the shell config will re-insert the bin directory from the current opam switch at the beginning of PATH. Dune's setup logic doesn't re-insert directories already present in PATH as dune may share its bin directory with other programs reliant on the current PATH order. Thus opam's re-initialization will result in any dune executable in the current opam switch taking precedence over the binary distro. To prevent this, the __dune_env function detects when it's called subsequent times in a shell session, and if it succeeded the first time in correctly setting up the environment for the dune binary distribution will remove any opam directories from PATH which precede the first instance of location of the dune binary distro in PATH. Opam bin directories following the location of the binary distro in PATH, as well as all other directories in PATH are left unchanged. Signed-off-by: Stephen Sherratt <[email protected]>
363aeaa to
f3669b4
Compare
Sudha247
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! One question below.
This is a very impressive script and I learnt a lot of new stuff about shell scripting by reviewing these PRs! Thanks for the work. However, I do wonder about the maintenance of the env scripts - we have the same logic coded to four different shells. Future changes need to be cognisant of the fact that the changes should occur in all of the env scripts. Would we benefit from fleshing this out in a meta script and importing it to the various configs? (this is not to block the PR)
| paste -sd ':' -) | ||
| # Only commit the change if it actually fixed the problem. | ||
| if [ "$(PATH=$PATH_MAYBE_FIXED __dune_which)" = "$ROOT/bin/dune" ]; then | ||
| export PATH="$PATH_MAYBE_FIXED" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is __DUNE_SETUP_STATE not being exported here because it's already in success state, and we want to continue it being in the same state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep exactly
It's tricky because these files are |
When starting a shell from an existing shell where the shell config has already been sourced, or when sourcing a shell config for a second time within the same shell session, any opam setup in the shell config will re-insert the bin directory from the current opam switch at the beginning of PATH.
Dune's setup logic doesn't re-insert directories already present in PATH as dune may share its bin directory with other programs reliant on the current PATH order. Thus opam's re-initialization will result in any dune executable in the current opam switch taking precedence over the binary distro.
To prevent this, the __dune_env function detects when it's called subsequent times in a shell session, and if it succeeded the first time in correctly setting up the environment for the dune binary distribution will remove any opam directories from PATH which preceed the first instance of location of the dune binary distro in PATH. Opam bin directories following the location of the binary distro in PATH, as well as all other directories in PATH are left unchanged.