ruby@2.0: vendor gem like we do pip for Python

This commit is contained in:
Dominyk Tiller 2017-10-18 22:40:23 +01:00 committed by ilovezfs
parent bfdf8853e4
commit bd90259df7

View file

@ -3,7 +3,7 @@ class RubyAT20 < Formula
homepage "https://www.ruby-lang.org/"
url "https://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p648.tar.bz2"
sha256 "087ad4dec748cfe665c856dbfbabdee5520268e94bb81a1d8565d76c3cc62166"
revision 1
revision 2
bottle do
sha256 "f7337fa641d1e7a345d2ae693bc98ff47e2d109321d0d9224007a9fed827acd6" => :high_sierra
@ -26,6 +26,26 @@ class RubyAT20 < Formula
depends_on "openssl"
depends_on :x11 if build.with? "tcltk"
# This should be kept in sync with the main Ruby formula
# but a revision bump should not be forced every update
# unless there are security fixes in that Rubygems release.
resource "rubygems" do
url "https://rubygems.org/rubygems/rubygems-2.6.14.tgz"
sha256 "406a45d258707f52241843e9c7902bbdcf00e7edc3e88cdb79c46659b47851ec"
end
def program_suffix
build.with?("suffix") ? "20" : ""
end
def ruby
"#{bin}/ruby#{program_suffix}"
end
def api_version
"2.0.0"
end
def install
args = %W[
--prefix=#{prefix}
@ -67,17 +87,37 @@ class RubyAT20 < Formula
system "make"
system "make", "install"
# This is easier than trying to keep both current & versioned Ruby
# formulae repeatedly updated with Rubygem patches.
resource("rubygems").stage do
ENV.prepend_path "PATH", bin
system ruby, "setup.rb", "--prefix=#{buildpath}/vendor_gem"
rg_in = lib/"ruby/#{api_version}"
# Remove bundled Rubygem version.
rm_rf rg_in/"rubygems"
rm_f rg_in/"rubygems.rb"
rm_f rg_in/"ubygems.rb"
rm_f bin/"gem#{program_suffix}"
# Drop in the new version.
(rg_in/"rubygems").install Dir[buildpath/"vendor_gem/lib/rubygems/*"]
rg_in.install buildpath/"vendor_gem/lib/rubygems.rb"
rg_in.install buildpath/"vendor_gem/lib/ubygems.rb"
bin.install buildpath/"vendor_gem/bin/gem" => "gem#{program_suffix}"
end
end
def post_install
# Customize rubygems to look/install in the global gem directory
# instead of in the Cellar, making gems last across reinstalls
config_file = lib/"ruby/#{abi_version}/rubygems/defaults/operating_system.rb"
config_file = lib/"ruby/#{api_version}/rubygems/defaults/operating_system.rb"
config_file.unlink if config_file.exist?
config_file.write rubygems_config
# Create the sitedir and vendordir that were skipped during install
ruby="#{bin}/ruby#{program_suffix}"
%w[sitearchdir vendorarchdir].each do |dir|
mkdir_p `#{ruby} -rrbconfig -e 'print RbConfig::CONFIG["#{dir}"]'`
end
@ -86,16 +126,8 @@ class RubyAT20 < Formula
mkdir_p rubygems_bindir
end
def abi_version
"2.0.0"
end
def program_suffix
build.with?("suffix") ? "20" : ""
end
def rubygems_bindir
"#{HOMEBREW_PREFIX}/lib/ruby/gems/#{abi_version}/bin"
"#{HOMEBREW_PREFIX}/lib/ruby/gems/#{api_version}/bin"
end
def rubygems_config; <<~EOS
@ -113,7 +145,7 @@ class RubyAT20 < Formula
"lib",
"ruby",
"gems",
"#{abi_version}"
"#{api_version}"
]
@default_dir ||= File.join(*path)