summaryrefslogtreecommitdiff
path: root/post-bundle-install.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2021-03-18 10:26:11 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2021-03-18 10:35:51 -0700
commit2d88d96b2cfeabd9eaa5350a1f8b90e54632923c (patch)
tree5c86b235c9a011fdb5993f34ca91df3fedddea04 /post-bundle-install.rb
parent12265fccc388abe416d89e1f06df546d6b024747 (diff)
downloadchef-2d88d96b2cfeabd9eaa5350a1f8b90e54632923c.tar.gz
ruby 3.0 fixes and post-bundle-install hook
Mostly this is all fixes necessary for ruby 3.0 There's the addition of the appbundle hook which lets us better pull git gems into appbundler Note carefully how after adding the post-bundle-install.rb that trying to pre appbundle-update ohai pulls in chef/chef as bundle installed git gem which fails to install so we go back to only using one appbundle-update on chef/chef and removing the chef/ohai one (which may fix other bugs). Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'post-bundle-install.rb')
-rw-r--r--post-bundle-install.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/post-bundle-install.rb b/post-bundle-install.rb
new file mode 100644
index 0000000000..f0db5d50b0
--- /dev/null
+++ b/post-bundle-install.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+gem_home = Gem.paths.home
+
+puts "fixing bundle installed gems in #{gem_home}"
+
+# Install gems from git repos. This makes the assumption that there is a <gem_name>.gemspec and
+# you can simply gem build + gem install the resulting gem, so nothing fancy. This does not use
+# rake install since we need --conservative --minimal-deps in order to not install duplicate gems.
+#
+Dir["#{gem_home}/bundler/gems/*"].each do |gempath|
+ matches = File.basename(gempath).match(/(.*)-[A-Fa-f0-9]{12}/)
+ next unless matches
+
+ gem_name = matches[1]
+ next unless gem_name
+
+ puts "re-installing #{gem_name}..."
+
+ # we can't use "commmand" or "bundle" or "gem" DSL methods here since those are lazy and we need to run commands immediately
+ # (this is like a shell_out inside of a ruby_block in core chef, you don't use an execute resource inside of a ruby_block or
+ # things get really weird and unexpected)
+ Dir.chdir(gempath) do
+ system("gem build #{gem_name}.gemspec") or raise "gem build failed"
+ system("gem install #{gem_name}*.gem --conservative --minimal-deps --no-document") or raise "gem install failed"
+ end
+end