Skip to content

Commit

Permalink
ruby@2.2: vendor gem like we do pip for Python
Browse files Browse the repository at this point in the history
  • Loading branch information
DomT4 authored and ilovezfs committed Oct 22, 2017
1 parent fd09c3d commit 3bd1b29
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions Formula/ruby@2.2.rb
Expand Up @@ -3,6 +3,7 @@ class RubyAT22 < Formula
homepage "https://www.ruby-lang.org/"
url "https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.8.tar.xz"
sha256 "37eafc15037396c26870f6a6c5bcd0658d14b46cd5e191a3b56d89dd22d561b0"
revision 1

bottle do
sha256 "39af46430dae6262e5cff3d712de650ba4beec4f8f8947469dc9987e280f2dae" => :high_sierra
Expand All @@ -25,6 +26,26 @@ class RubyAT22 < 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") ? "22" : ""
end

def ruby
"#{bin}/ruby#{program_suffix}"
end

def api_version
"2.2.0"
end

def install
args = %W[
--prefix=#{prefix}
Expand Down Expand Up @@ -71,17 +92,37 @@ def install

# A newer version of ruby-mode.el is shipped with Emacs
elisp.install Dir["misc/*.el"].reject { |f| f == "misc/ruby-mode.el" }

# 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
Expand All @@ -90,16 +131,8 @@ def post_install
mkdir_p rubygems_bindir
end

def abi_version
"2.2.0"
end

def program_suffix
build.with?("suffix") ? "22" : ""
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
Expand All @@ -117,7 +150,7 @@ def self.default_dir
"lib",
"ruby",
"gems",
"#{abi_version}"
"#{api_version}"
]
@default_dir ||= File.join(*path)
Expand Down

0 comments on commit 3bd1b29

Please sign in to comment.