-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Describe the problem as clearly as you can
When running bundle exec ruby ..., I would like to set RUBYOPT=-rlogger environment variable only for the launched subprocess, in order to workaround some issue with older gems that assume logger is loaded by default.
If I run RUBYOPT=-rlogger bundle exec ruby ... it also export the variable for bundler, which can easily cause an expected crash for bundle exec command (explained down below).
The workaround is to wrap the child command with a shell setting the environment variable, like bundle exec sh -c 'RUBYOPT=-rlogger exec ruby ...'. However, this method is ugly and does not work cross-platform, because we cannot expect sh to be installed on Windows.
I would like to have support for this new syntax similar to how posix shell works:
bundle exec RUBYOPT=-rlogger ruby ...It should export environment variables only for the child process but not bundle command itself.
Alternatively, a --env flag for bundle exec would also be good, if the shell like syntax is considered to be convoluted.
Did you try upgrading rubygems & bundler?
Yes.
Post steps to reproduce the problem
# Gemfile
source 'https://rubygems.org'
gem 'logger'
gem 'rake'Which command did you run?
RUBYOPT=-rlogger bundle exec rakeThis crashes with the following error:
bundler: failed to load command: rake (/Users/edward/Developer/github/ruby-test/vendor/bundle/ruby/3.4.0/bin/rake)
/opt/homebrew/Cellar/ruby/3.4.4/lib/ruby/3.4.0/bundler/runtime.rb:317:in 'Bundler::Runtime#check_for_activated_spec!': You have already activated logger 1.6.4, but your Gemfile requires logger 1.7.0. Since logger is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports logger as a default gem. (Gem::LoadError)
To be clear, the goal is not to fix the crash mentioned above, as the crash is actually expected due to exactly what the error message was saying. The feature request is to have a way to easily set environment variable only for the child process that's launching but not on the bundle parent process. It would not only solve the specific crash mentioned above, but also provide a safer way to set environment variables in general that it won't pollute the environment of bundler itself.