Skip to content

Commit 08ad3bd

Browse files
committed
ruby: rely on postinstall less
1 parent 3dc09b9 commit 08ad3bd

File tree

1 file changed

+35
-43
lines changed

1 file changed

+35
-43
lines changed

Formula/r/ruby.rb

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Ruby < Formula
55
head "https://github.com/ruby/ruby.git", branch: "master"
66

77
stable do
8+
# Consider changing the default of `Gem.default_user_install` to true with Ruby 3.5.
9+
# This may depend on https://github.com/rubygems/rubygems/issues/5682.
810
url "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.2.tar.gz"
911
sha256 "41328ac21f2bfdd7de6b3565ef4f0dd7543354d37e96f157a1552a6bd0eb364b"
1012

@@ -132,37 +134,39 @@ def install
132134
end
133135
end
134136

135-
return if build.head? # Use bundled RubyGems for --HEAD (will be newer)
136-
137-
# This is easier than trying to keep both current & versioned Ruby
138-
# formulae repeatedly updated with Rubygem patches.
139-
resource("rubygems").stage do
140-
ENV.prepend_path "PATH", bin
141-
142-
system bin/"ruby", "setup.rb", "--prefix=#{buildpath}/vendor_gem"
143-
rg_in = lib/"ruby/#{api_version}"
144-
rg_gems_in = lib/"ruby/gems/#{api_version}"
145-
146-
# Remove bundled Rubygem and Bundler
147-
rm_r rg_in/"bundler"
148-
rm rg_in/"bundler.rb"
149-
rm_r Dir[rg_gems_in/"gems/bundler-*"]
150-
rm Dir[rg_gems_in/"specifications/default/bundler-*.gemspec"]
151-
rm_r rg_in/"rubygems"
152-
rm rg_in/"rubygems.rb"
153-
rm bin/"gem"
154-
155-
# Drop in the new version.
156-
rg_in.install Dir[buildpath/"vendor_gem/lib/*"]
157-
(rg_gems_in/"gems").install Dir[buildpath/"vendor_gem/gems/*"]
158-
(rg_gems_in/"specifications/default").install Dir[buildpath/"vendor_gem/specifications/default/*"]
159-
bin.install buildpath/"vendor_gem/bin/gem" => "gem"
160-
(libexec/"gembin").install buildpath/"vendor_gem/bin/bundle" => "bundle"
161-
(libexec/"gembin").install_symlink "bundle" => "bundler"
137+
unless build.head? # Use bundled RubyGems for --HEAD (will be newer)
138+
# This is easier than trying to keep both current & versioned Ruby
139+
# formulae repeatedly updated with Rubygem patches.
140+
resource("rubygems").stage do
141+
ENV.prepend_path "PATH", bin
142+
143+
system bin/"ruby", "setup.rb", "--prefix=#{buildpath}/vendor_gem"
144+
rg_in = lib/"ruby/#{api_version}"
145+
rg_gems_in = lib/"ruby/gems/#{api_version}"
146+
147+
# Remove bundled Rubygem and Bundler
148+
rm_r rg_in/"bundler"
149+
rm rg_in/"bundler.rb"
150+
rm_r Dir[rg_gems_in/"gems/bundler-*"]
151+
rm Dir[rg_gems_in/"specifications/default/bundler-*.gemspec"]
152+
rm_r rg_in/"rubygems"
153+
rm rg_in/"rubygems.rb"
154+
rm bin/"gem"
155+
156+
# Drop in the new version.
157+
rg_in.install Dir[buildpath/"vendor_gem/lib/*"]
158+
(rg_gems_in/"gems").install Dir[buildpath/"vendor_gem/gems/*"]
159+
(rg_gems_in/"specifications/default").install Dir[buildpath/"vendor_gem/specifications/default/*"]
160+
bin.install buildpath/"vendor_gem/bin/gem" => "gem"
161+
bin.install buildpath/"vendor_gem/bin/bundle" => "bundle"
162+
bin.install buildpath/"vendor_gem/bin/bundler" => "bundler"
163+
end
162164
end
163165

164-
# remove all lockfiles in bin folder
165-
rm Dir[bin/"*.lock"]
166+
# Customize rubygems to look/install in the global gem directory
167+
# instead of in the Cellar, making gems last across reinstalls
168+
config_file = lib/"ruby/#{api_version}/rubygems/defaults/operating_system.rb"
169+
config_file.write rubygems_config
166170
end
167171

168172
def post_install
@@ -174,21 +178,9 @@ def post_install
174178
#{rubygems_bindir}/bundler
175179
].select { |file| File.exist?(file) })
176180
rm_r(Dir[HOMEBREW_PREFIX/"lib/ruby/gems/#{api_version}/gems/bundler-*"])
177-
rubygems_bindir.install_symlink Dir[libexec/"gembin/*"]
178-
179-
# Customize rubygems to look/install in the global gem directory
180-
# instead of in the Cellar, making gems last across reinstalls
181-
config_file = lib/"ruby/#{api_version}/rubygems/defaults/operating_system.rb"
182-
config_file.unlink if config_file.exist?
183-
config_file.write rubygems_config(api_version)
184-
185-
# Create the sitedir and vendordir that were skipped during install
186-
%w[sitearchdir vendorarchdir].each do |dir|
187-
mkdir_p `#{bin}/ruby -rrbconfig -e 'print RbConfig::CONFIG["#{dir}"]'`
188-
end
189181
end
190182

191-
def rubygems_config(api_version)
183+
def rubygems_config
192184
<<~RUBY
193185
module Gem
194186
class << self
@@ -205,7 +197,7 @@ def self.default_dir
205197
"lib",
206198
"ruby",
207199
"gems",
208-
"#{api_version}"
200+
RbConfig::CONFIG['ruby_version']
209201
]
210202
211203
@homebrew_path ||= File.join(*path)

0 commit comments

Comments
 (0)