Skip to content

Commit

Permalink
ruby: add rubygems customization, fix postinstall
Browse files Browse the repository at this point in the history
This configures rubygems to install all gems into a public, non-versioned
directory by default - both gems and their binaries. (This means that
users no longer need /usr/local/opt/ruby/bin in their PATH.)

This means that we no longer have to monkey with gem directories at all
in postinstall. Bundled gems will be symlinked into this location.

Fixes Homebrew#29982.
Closes Homebrew#29986.
  • Loading branch information
mistydemeo committed Jun 13, 2014
1 parent 989cc40 commit e356a9c
Showing 1 changed file with 61 additions and 13 deletions.
74 changes: 61 additions & 13 deletions Library/Formula/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Ruby < Formula
homepage 'https://www.ruby-lang.org/'
url "http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.bz2"
sha256 "6948b02570cdfb89a8313675d4aa665405900e27423db408401473f30fc6e901"
revision 1
revision 2

bottle do
sha1 "9feba2200305e8750c26f83d562b900d31978905" => :mavericks
Expand Down Expand Up @@ -60,14 +60,19 @@ def install
system "./configure", *args
system "make"
system "make install"

# Customize rubygems to look/install in the global gem directory
# instead of in the Cellar, making gems last across reinstalls
(lib/"ruby/2.1.0/rubygems/defaults/operating_system.rb").write rubygems_config
end

def post_install
# Preserve gem, site, and vendor folders on upgrade/reinstall
# by placing them in HOMEBREW_PREFIX and sym-linking
# Preserve site and vendor folders on upgrade/reinstall
# by placing them in HOMEBREW_PREFIX and symlinking
ruby_lib = HOMEBREW_PREFIX/"lib/ruby"

["gems", "site_ruby", "vendor_ruby"].each do |name|
# These directories are empty on install
["site_ruby", "vendor_ruby"].each do |name|
link = lib/"ruby"/name
real = ruby_lib/name

Expand All @@ -76,18 +81,61 @@ def post_install
real.mkpath

link.unlink if link.exist?
link.symlink real
link.make_symlink real
end
end

def caveats; <<-EOS.undent
By default, gem installed executables will be placed into:
#{opt_bin}
You may want to add this to your PATH. After upgrades, you can run
gem pristine --all --only-executables
to restore binstubs for installed gems.
def rubygems_config; <<-EOS.undent
module Gem
def self.default_dir
path = [
"#{HOMEBREW_PREFIX}",
"lib",
"ruby",
"gems",
"2.1.0"
]
@default_dir ||= File.join(*path)
end
def self.private_dir
path = if defined? RUBY_FRAMEWORK_VERSION then
[
File.dirname(RbConfig::CONFIG['sitedir']),
'Gems',
RbConfig::CONFIG['ruby_version']
]
elsif RbConfig::CONFIG['rubylibprefix'] then
[
RbConfig::CONFIG['rubylibprefix'],
'gems',
RbConfig::CONFIG['ruby_version']
]
else
[
RbConfig::CONFIG['libdir'],
ruby_engine,
'gems',
RbConfig::CONFIG['ruby_version']
]
end
@private_dir ||= File.join(*path)
end
def self.default_path
if Gem.user_home && File.exist?(Gem.user_home)
[user_dir, default_dir, private_dir]
else
[default_dir, private_dir]
end
end
def self.default_bindir
"#{HOMEBREW_PREFIX}/bin"
end
end
EOS
end

Expand Down

0 comments on commit e356a9c

Please sign in to comment.