Avoid requiring json for chruby activation #2430
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
There's an annoying bug in our chruby activation because of the dependency on the json default gem.
These are the steps to reproduce it:
GEM_HOME
to use~/.gem/ruby/3.3.4
instead of the default~/.gem/ruby/3.3.0
. We perform this correction inside our activation script (in Ruby)-rjson
to require json will also requirestrscan
. This happens before we had a chance to activate the chruby environment, which means it will try to requirestrscan
with aGEM_HOME
still pointing to~/.gem/ruby/3.3.0
, even though the Ruby version is 3.3.4 and chruby would've pointed us to~/.gem/ruby/3.3.4
linked to incompatible Ruby version
error and breaks the activationImplementation
I can't think of another way for fixing this that isn't removing the json dependency. The approach that I took is quite simple: I started printing a separator string, so that we can easily break the pieces that we need from the activation script's result.
Automated Tests
It's not very trivial to write tests for this specific scenario because it would involve installing more than one Ruby version.