vondruch / rpms / ruby

Forked from rpms/ruby 6 years ago
Clone
a03b2d2
From 37cd8547d23973a7ec23a004ab9b60738d67ada9 Mon Sep 17 00:00:00 2001
117278a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
117278a
Date: Thu, 3 Nov 2011 16:43:05 +0100
a03b2d2
Subject: [PATCH] Add dedicate extensions folder into $LOAD_PATH.
117278a
117278a
---
a03b2d2
 lib/rubygems/basic_specification.rb | 35 ++++++++++++++++++++++++++++++++---
a03b2d2
 lib/rubygems/defaults.rb            | 11 +++++++++++
a03b2d2
 lib/rubygems/ext/builder.rb         |  6 +++++-
a03b2d2
 lib/rubygems/installer.rb           |  1 +
a03b2d2
 lib/rubygems/specification.rb       |  7 +++++++
a03b2d2
 lib/rubygems/uninstaller.rb         |  1 +
a03b2d2
 6 files changed, 57 insertions(+), 4 deletions(-)
a03b2d2
a03b2d2
diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb
a03b2d2
index a10eab3..da3af91 100644
a03b2d2
--- a/lib/rubygems/basic_specification.rb
a03b2d2
+++ b/lib/rubygems/basic_specification.rb
a03b2d2
@@ -51,6 +51,14 @@ class Gem::BasicSpecification
a03b2d2
       File.dirname(loaded_from) == self.class.default_specifications_dir
117278a
   end
117278a
 
117278a
+  ##
117278a
+  # Returns the full path to the exts directory containing this spec's
117278a
+  # gem directory. eg: /usr/local/lib/ruby/1.8/exts
117278a
+
117278a
+  def exts_dir
a03b2d2
+    @exts_dir ||= Gem.default_ext_dir_for(base_dir) || gems_dir
117278a
+  end
117278a
+
a03b2d2
   def find_full_gem_path # :nodoc:
a03b2d2
     # TODO: also, shouldn't it default to full_name if it hasn't been written?
a03b2d2
     path = File.expand_path File.join(gems_dir, full_name)
a03b2d2
@@ -60,6 +68,15 @@ class Gem::BasicSpecification
a03b2d2
 
a03b2d2
   private :find_full_gem_path
a03b2d2
 
a03b2d2
+  def find_full_gem_ext_path # :nodoc:
a03b2d2
+    # TODO: skip for gems without extensions.
a03b2d2
+    path = File.expand_path File.join(exts_dir, full_name)
a03b2d2
+    path.untaint
a03b2d2
+    path if File.directory? path
a03b2d2
+  end
a03b2d2
+
a03b2d2
+  private :find_full_gem_ext_path
a03b2d2
+
117278a
   ##
a03b2d2
   # The full path to the gem (install path + full name).
117278a
 
a03b2d2
@@ -70,6 +87,13 @@ class Gem::BasicSpecification
117278a
   end
117278a
 
117278a
   ##
a03b2d2
+  # The full path to the gem binary extension (install path + full name).
a03b2d2
+
a03b2d2
+  def full_gem_ext_path
a03b2d2
+    @full_gem_ext_path ||= find_full_gem_ext_path
a03b2d2
+  end
a03b2d2
+
a03b2d2
+  ##
a03b2d2
   # Returns the full name (name-version) of this Gem.  Platform information
a03b2d2
   # is included (name-version-platform) if it is specified and not the
a03b2d2
   # default Ruby platform.
a03b2d2
@@ -88,9 +112,12 @@ class Gem::BasicSpecification
a03b2d2
   #
117278a
 
a03b2d2
   def full_require_paths
a03b2d2
-    require_paths.map do |path|
a03b2d2
-      File.join full_gem_path, path
117278a
-    end
a03b2d2
+    require_paths.map do |require_path|
a03b2d2
+      full_gem_paths = [full_gem_path, full_gem_ext_path]
a03b2d2
+      full_gem_paths.compact!
a03b2d2
+
a03b2d2
+      full_gem_paths.map { |path| File.join path, require_path }
a03b2d2
+    end.flatten
117278a
   end
117278a
 
117278a
   ##
a03b2d2
@@ -110,7 +137,9 @@ class Gem::BasicSpecification
a03b2d2
     @loaded_from   = path && path.to_s
a03b2d2
 
a03b2d2
     @full_gem_path = nil
a03b2d2
+    @full_gem_ext_path = nil
a03b2d2
     @gems_dir      = nil
a03b2d2
+    @exts_dir      = nil
a03b2d2
     @base_dir      = nil
117278a
   end
117278a
 
117278a
diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb
a03b2d2
index 591580b..8ed474f 100644
117278a
--- a/lib/rubygems/defaults.rb
117278a
+++ b/lib/rubygems/defaults.rb
a03b2d2
@@ -111,6 +111,17 @@ module Gem
117278a
   end
117278a
 
117278a
   ##
117278a
+  # Returns binary extensions dir for specified RubyGems base dir or nil
117278a
+  # if such directory cannot be determined.
117278a
+  #
117278a
+  # By default, the binary extensions are located side by side with their
117278a
+  # Ruby counterparts, therefore nil is returned
117278a
+
117278a
+  def self.default_ext_dir_for base_dir
117278a
+    nil
117278a
+  end
117278a
+
117278a
+  ##
3fa8028
   # A wrapper around RUBY_ENGINE const that may not be defined
117278a
 
3fa8028
   def self.ruby_engine
a03b2d2
diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb
a03b2d2
index 8c05723..75d5fc2 100644
a03b2d2
--- a/lib/rubygems/ext/builder.rb
a03b2d2
+++ b/lib/rubygems/ext/builder.rb
a03b2d2
@@ -170,7 +170,7 @@ EOF
a03b2d2
       say "This could take a while..."
a03b2d2
     end
117278a
 
a03b2d2
-    dest_path = File.join @gem_dir, @spec.require_paths.first
a03b2d2
+    dest_path = File.join(@only_install_dir ? @gem_dir : @spec.ext_dir, @spec.require_paths.first)
117278a
 
a03b2d2
     @ran_rake = false # only run rake once
a03b2d2
 
a03b2d2
@@ -181,5 +181,9 @@ EOF
e811eb0
     end
a03b2d2
   end
e811eb0
 
a03b2d2
+  def only_install_dir= only_install_dir
a03b2d2
+    @only_install_dir = only_install_dir
a03b2d2
+  end
a03b2d2
+
a03b2d2
 end
e811eb0
 
929678a
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
a03b2d2
index 261af89..a6aca5d 100644
929678a
--- a/lib/rubygems/installer.rb
929678a
+++ b/lib/rubygems/installer.rb
a03b2d2
@@ -662,6 +662,7 @@ TEXT
a03b2d2
 
a03b2d2
   def build_extensions
a03b2d2
     builder = Gem::Ext::Builder.new spec, @build_args
a03b2d2
+    builder.only_install_dir = @only_install_dir
a03b2d2
 
a03b2d2
     builder.build_extensions
a03b2d2
   end
a03b2d2
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
a03b2d2
index deac343..b630fa3 100644
a03b2d2
--- a/lib/rubygems/specification.rb
a03b2d2
+++ b/lib/rubygems/specification.rb
a03b2d2
@@ -1612,6 +1612,13 @@ class Gem::Specification < Gem::BasicSpecification
a03b2d2
     @executables = Array(value)
a03b2d2
   end
929678a
 
a03b2d2
+  # Returns the full path to this spec's ext directory.
a03b2d2
+  # eg: /usr/local/lib/ruby/1.8/exts/mygem-1.0
a03b2d2
+
a03b2d2
+  def ext_dir
a03b2d2
+    @ext_dir ||= File.expand_path File.join(exts_dir, full_name)
a03b2d2
+  end
a03b2d2
+
a03b2d2
   ##
a03b2d2
   # Sets extensions to +extensions+, ensuring it is an array. Don't
a03b2d2
   # use this, push onto the array instead.
a03b2d2
diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb
a03b2d2
index 143ab6d..f81a23d 100644
a03b2d2
--- a/lib/rubygems/uninstaller.rb
a03b2d2
+++ b/lib/rubygems/uninstaller.rb
a03b2d2
@@ -247,6 +247,7 @@ class Gem::Uninstaller
a03b2d2
       File.writable?(spec.base_dir)
929678a
 
a03b2d2
     FileUtils.rm_rf spec.full_gem_path
a03b2d2
+    FileUtils.rm_rf spec.ext_dir
a03b2d2
 
a03b2d2
     # TODO: should this be moved to spec?... I vote eww (also exists in docmgr)
a03b2d2
     old_platform_name = [spec.name,
929678a
-- 
a03b2d2
1.8.3.1
117278a