From e356a9cafefd4444f1b77722f5fd02ac0500e008 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Fri, 13 Jun 2014 13:15:19 -0700 Subject: [PATCH] ruby: add rubygems customization, fix postinstall 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 #29982. Closes #29986. --- Library/Formula/ruby.rb | 74 +++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/Library/Formula/ruby.rb b/Library/Formula/ruby.rb index cc2b5da3b4ab..98de87a66814 100644 --- a/Library/Formula/ruby.rb +++ b/Library/Formula/ruby.rb @@ -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 @@ -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 @@ -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