CHEF-37444: add ~/.chef/ruby/VERSION/gems to GEM_PATH for dynamic plugin loading - #1963
Open
sanghinitin wants to merge 1 commit into
Open
CHEF-37444: add ~/.chef/ruby/VERSION/gems to GEM_PATH for dynamic plugin loading#1963sanghinitin wants to merge 1 commit into
sanghinitin wants to merge 1 commit into
Conversation
…gin loading
- binstub_patch.rb: inject Gem.user_dir (~/.gem/ruby/VERSION) and
~/.chef/ruby/RUBY_API_VERSION/gems into GEM_PATH ahead of existing
paths so gems installed via `gem install` or `chef gem install`
are immediately visible to the ohai binstub.
- habitat/plan.sh, habitat/aarch64-darwin/plan.sh: expand the runtime
wrapper's GEM_PATH to four entries:
1. $pkg_prefix/vendor (ohai's vendored deps, flat)
2. $pkg_prefix/vendor/ruby/VERSION (bundler-nested deps, e.g. train-core)
3. ~/.gem/ruby/VERSION (standard `gem install` target)
4. ~/.chef/ruby/VERSION/gems (`chef gem install` target)
ruby_gem_version is now derived from the packaged Ruby's on-disk
lib/ruby/gems/ directory instead of executing `ruby -e`, which
could silently fail during Habitat's do_install phase and leave the
version segment empty. Falls back to 3.4.0 with a build_line warning.
- habitat/plan.ps1: inject binstub_patch.rb into Windows binstubs after
appbundler generates them, using the same require-rubygems insertion
point used on Linux/macOS.
Signed-off-by: nitin sanghi <nsanghi@progress.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Ohai plugins installed via
chef gem installland in~/.chef/ruby/<RUBY_API_VERSION>/gems, but this path was never added to the runtimeGEM_PATH. As a result, any gem installed that way was invisible to the packaged ohai binary even after re-running the binstub.This PR fixes the issue by expanding
GEM_PATHin three places: the Ruby binstub patch, and both the Linux/macOS and Windows Habitat wrappers.Root Cause Evidence
$ gem info some-ohai-plugin some-ohai-plugin (x.y.z) Installed at: /Users/nsanghi/.chef/ruby/3.4.0/gems # → not in GEM_PATH → LoadError at runtimeChanges Made
binstub_patch.rb
GEM_PATHassignment.GEM_PATH:$pkg_prefix/vendor— ohai vendored deps (flat layout)Gem.user_dir→~/.gem/ruby/VERSION— standardgem installtarget~/.chef/ruby/RUBY_API_VERSION/gems—chef gem installtarget.uniqso paths are never duplicated when the block runs twice.habitat/plan.sh & habitat/aarch64-darwin/plan.sh
GEM_PATHentries:$pkg_prefix/vendor— flat vendor tree$pkg_prefix/vendor/ruby/VERSION— bundler-nested tree (train-core etc.)${HOME}/.gem/ruby/VERSION— standard gem install${HOME}/.chef/ruby/VERSION/gems— chef gem installruby_gem_versionis now derived from the packaged Ruby's on-disklib/ruby/gems/directory viabasenameinstead of executingruby -e. The latter can silently fail duringdo_install(runtime lib paths are not yet set up), producing an empty version string that corrupts allGEM_PATHentries. Falls back to3.4.0with abuild_linewarning if the glob still yields nothing.habitat/plan.ps1
appbundler.batgenerates Windows binstubs, injectsbinstub_patch.rbimmediately after therequire "rubygems"line in each binstub — the same insertion point used on Linux/macOS.Verification
After
hab pkg build .andhab pkg install:This work was completed with AI assistance following Progress AI policies