Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

bundle exec's "with_original_env" doesn't preserve PATH #4251

Closed
njam opened this issue Jan 30, 2016 · 7 comments
Closed

bundle exec's "with_original_env" doesn't preserve PATH #4251

njam opened this issue Jan 30, 2016 · 7 comments

Comments

@njam
Copy link
Contributor

njam commented Jan 30, 2016

I'm looking for a way to restore the original environment PATH inside a ruby script executed with bundle exec <script>. I understand Bundler.with_original_env ( and Bundler.with_clean_env) should provide this functionality.

It seems to me though that the PATH is not correctly preserved when running bundle exec, because lib/bundler.rb is loaded twice during such an execution (once when running the bundle binary, and once when executing the script with Kernel.exec('<script>') in cli/exec.rb).
Therefore Bundler.ORIGINAL_ENV is overwritten twice, and can't be restored to the original value.

To illustrate I've added a spec about this here (which fails): njam@8871e41

I think the only way to pass along the original environment to the sub process is by setting yet another environment variable. Maybe bundler should store the environment serialized in BUNDLE_ORIGINAL_ENV, and then load it from there if present?

Is this interpretation correct, or am I using the code wrong?

@njam
Copy link
Contributor Author

njam commented Jan 30, 2016

In #2369 I can find:

when you use bundle exec ruby, the "original" environment is the one created by bundle exec.

On the other hand the bundle exec docu says:

Any subshells created inside the block will be given the environment present before Bundler was activated.

There's an implementation to pass along the original environment in another environment variable _BUNDLER_ORIGINAL_ENV in #2390. But there were problems about the encoding to use (json not available?). Is this still the case?

@indirect
Copy link
Member

Thanks for the report! It looks like this is a bug. The intention is that PATH be restored to what it was when bundle exec was called.

@segiddins
Copy link
Member

@indirect isn't this what BUNDLER_ORIG_MANPATH does for man? If so, we could probably use that logic for PATH as well

@segiddins
Copy link
Member

@njam can you check if #4256 fixes things for you?

homu added a commit that referenced this issue Jan 31, 2016
Preserve PATH in with_clean_env

Closes #4251? Not sure.
homu added a commit that referenced this issue Feb 1, 2016
Preserve PATH in with_clean_env

Closes #4251? Not sure.
@homu homu closed this as completed in #4256 Feb 1, 2016
@njam
Copy link
Contributor Author

njam commented Feb 1, 2016

Unfortunately not completely.
It looks good to store the original PATH In _ORIGINAL_PATH, but then I think we need to somehow restore it in with_original_env? The original path never makes it into ORIGINAL_ENV.

You can check by running this spec: njam@8871e41

@indirect indirect reopened this Feb 3, 2016
@indirect
Copy link
Member

indirect commented Feb 3, 2016

@segiddins sounds like we maybe want to pull in that spec?

@segiddins
Copy link
Member

Go ahead @indirect

homu added a commit that referenced this issue Feb 15, 2016
Refactor path/environment preserver, make it always preserve the PATH

Closes #4251

@segiddins @indirect @RochesterinNYC wdyt?
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants