b8524a
From ec90622235ae19b28a327cb50a10e0311e8f3d71 Mon Sep 17 00:00:00 2001
b8524a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
b8524a
Date: Thu, 3 Nov 2011 16:43:05 +0100
b8524a
Subject: [PATCH 1/8] Add dedicate extensions folder into $LOAD_PATH.
b8524a
b8524a
---
b8524a
 lib/rubygems/specification.rb | 32 ++++++++++++++++++++++++++++++--
b8524a
 1 file changed, 30 insertions(+), 2 deletions(-)
b8524a
b8524a
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
b8524a
index cabdf8d..87b14d2 100644
b8524a
--- a/lib/rubygems/specification.rb
b8524a
+++ b/lib/rubygems/specification.rb
b8524a
@@ -1269,6 +1269,12 @@ class Gem::Specification
b8524a
       File.join full_gem_path, path
b8524a
     end
b8524a
 
b8524a
+    unless extensions.empty?
b8524a
+      paths += require_paths.map do |path|
b8524a
+        File.join ext_dir, path
b8524a
+      end
b8524a
+    end
b8524a
+
b8524a
     # gem directories must come after -I and ENV['RUBYLIB']
b8524a
     insert_index = Gem.load_path_insert_index
b8524a
 
b8524a
@@ -1389,11 +1395,16 @@ class Gem::Specification
b8524a
 
b8524a
   def contains_requirable_file? file
b8524a
     root     = full_gem_path
b8524a
+    ext      = ext_dir
b8524a
     suffixes = Gem.suffixes
b8524a
 
b8524a
     require_paths.any? do |lib|
b8524a
-      base = "#{root}/#{lib}/#{file}"
b8524a
-      suffixes.any? { |suf| File.file? "#{base}#{suf}" }
b8524a
+      base = ["#{root}/#{lib}/#{file}"]
b8524a
+      base << "#{ext}/#{lib}/#{file}" unless extensions.empty?
b8524a
+
b8524a
+      base.any? do |path|
b8524a
+        suffixes.any? { |suf| File.file? "#{path}#{suf}" }
b8524a
+      end
b8524a
     end
b8524a
   end
b8524a
 
b8524a
@@ -1691,6 +1699,23 @@ class Gem::Specification
b8524a
   end
b8524a
 
b8524a
   ##
b8524a
+  # Returns the full path to this spec's ext directory.
b8524a
+  # eg: /usr/local/lib/ruby/1.8/exts/mygem-1.0
b8524a
+
b8524a
+  def ext_dir
b8524a
+    @gem_dir ||= File.expand_path File.join(exts_dir, full_name)
b8524a
+  end
b8524a
+
b8524a
+  ##
b8524a
+  # Returns the full path to the exts directory containing this spec's
b8524a
+  # gem directory. eg: /usr/local/lib/ruby/1.8/exts
b8524a
+
b8524a
+  def exts_dir
b8524a
+    # TODO: this logic seems terribly broken, but tests fail if just base_dir
b8524a
+    @exts_dir ||= File.join(loaded_from && base_dir || Gem.dir, "exts")
b8524a
+  end
b8524a
+
b8524a
+  ##
b8524a
   # Deprecated and ignored, defaults to true.
b8524a
   #
b8524a
   # Formerly used to indicate this gem was RDoc-capable.
b8524a
-- 
b8524a
1.8.1.2
b8524a
b8524a
b8524a
From e42819f32fc5d935f7e7189ec4be8bdab0a2cf3f Mon Sep 17 00:00:00 2001
b8524a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
b8524a
Date: Wed, 16 Nov 2011 13:26:48 +0100
b8524a
Subject: [PATCH 2/8] Use spec's ext dir for extension installation.
b8524a
b8524a
---
b8524a
 lib/rubygems/installer.rb     | 2 +-
b8524a
 lib/rubygems/specification.rb | 7 +++----
b8524a
 2 files changed, 4 insertions(+), 5 deletions(-)
b8524a
b8524a
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
b8524a
index 780a88b..854c177 100644
b8524a
--- a/lib/rubygems/installer.rb
b8524a
+++ b/lib/rubygems/installer.rb
b8524a
@@ -656,7 +656,7 @@ TEXT
b8524a
       say "This could take a while..."
b8524a
     end
b8524a
 
b8524a
-    dest_path = File.join gem_dir, spec.require_paths.first
b8524a
+    dest_path = spec.ext_dir
b8524a
     ran_rake = false # only run rake once
b8524a
 
b8524a
     spec.extensions.each do |extension|
b8524a
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
b8524a
index 87b14d2..492ddbe 100644
b8524a
--- a/lib/rubygems/specification.rb
b8524a
+++ b/lib/rubygems/specification.rb
b8524a
@@ -1706,16 +1706,15 @@ class Gem::Specification
b8524a
   # eg: /usr/local/lib/ruby/1.8/exts/mygem-1.0
b8524a
 
b8524a
   def ext_dir
b8524a
-    @gem_dir ||= File.expand_path File.join(exts_dir, full_name)
b8524a
+    @ext_dir ||= File.join exts_dir, full_name, require_paths.first
b8524a
   end
b8524a
 
b8524a
   ##
b8524a
   # Returns the full path to the exts directory containing this spec's
b8524a
-  # gem directory. eg: /usr/local/lib/ruby/1.8/exts
b8524a
+  # gem directory. eg: /usr/local/lib/ruby/1.8/gems
b8524a
 
b8524a
   def exts_dir
b8524a
-    # TODO: this logic seems terribly broken, but tests fail if just base_dir
b8524a
-    @exts_dir ||= File.join(loaded_from && base_dir || Gem.dir, "exts")
b8524a
+    @exts_dir ||= gems_dir
b8524a
   end
b8524a
 
b8524a
   ##
b8524a
-- 
b8524a
1.8.1.2
b8524a
b8524a
b8524a
From 0e9dd0655111f7dda805233c79a3771459d9a66a Mon Sep 17 00:00:00 2001
b8524a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
b8524a
Date: Wed, 16 Nov 2011 14:52:16 +0100
b8524a
Subject: [PATCH 3/9] Simplify the extending of $LOAD_PATH for binary gems.
b8524a
b8524a
---
b8524a
 lib/rubygems/specification.rb | 11 +++++------
b8524a
 1 file changed, 5 insertions(+), 6 deletions(-)
b8524a
b8524a
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
b8524a
index 492ddbe..c703827 100644
b8524a
--- a/lib/rubygems/specification.rb
b8524a
+++ b/lib/rubygems/specification.rb
b8524a
@@ -1269,11 +1269,7 @@ class Gem::Specification
b8524a
       File.join full_gem_path, path
b8524a
     end
b8524a
 
b8524a
-    unless extensions.empty?
b8524a
-      paths += require_paths.map do |path|
b8524a
-        File.join ext_dir, path
b8524a
-      end
b8524a
-    end
b8524a
+    paths << ext_dir unless extensions.empty? || paths.include?(ext_dir)
b8524a
 
b8524a
     # gem directories must come after -I and ENV['RUBYLIB']
b8524a
     insert_index = Gem.load_path_insert_index
b8524a
@@ -1714,7 +1710,10 @@ class Gem::Specification
b8524a
   # gem directory. eg: /usr/local/lib/ruby/1.8/gems
b8524a
 
b8524a
   def exts_dir
b8524a
-    @exts_dir ||= gems_dir
b8524a
+    @exts_dir ||= begin
b8524a
+      dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
b8524a
+      dirs ? File.join(dirs.last[:ext_dir], 'exts') : gems_dir
b8524a
+    end
b8524a
   end
b8524a
 
b8524a
   ##
b8524a
-- 
b8524a
1.8.1.2
b8524a
b8524a
b8524a
From 9a8556c609e800d0dbd24af416d613f2e82f323c Mon Sep 17 00:00:00 2001
b8524a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
b8524a
Date: Fri, 9 Dec 2011 16:31:04 +0100
b8524a
Subject: [PATCH 4/8] Fix the binary extension search path construction.
b8524a
b8524a
---
b8524a
 lib/rubygems/installer.rb     | 2 +-
b8524a
 lib/rubygems/specification.rb | 4 ++--
b8524a
 2 files changed, 3 insertions(+), 3 deletions(-)
b8524a
b8524a
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
b8524a
index 854c177..f1f2ad7 100644
b8524a
--- a/lib/rubygems/installer.rb
b8524a
+++ b/lib/rubygems/installer.rb
b8524a
@@ -656,7 +656,7 @@ TEXT
b8524a
       say "This could take a while..."
b8524a
     end
b8524a
 
b8524a
-    dest_path = spec.ext_dir
b8524a
+    dest_path = File.join spec.ext_dir, spec.require_paths.first
b8524a
     ran_rake = false # only run rake once
b8524a
 
b8524a
     spec.extensions.each do |extension|
b8524a
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
b8524a
index c703827..fa9ea6e 100644
b8524a
--- a/lib/rubygems/specification.rb
b8524a
+++ b/lib/rubygems/specification.rb
b8524a
@@ -1269,7 +1269,7 @@ class Gem::Specification
b8524a
       File.join full_gem_path, path
b8524a
     end
b8524a
 
b8524a
-    paths << ext_dir unless extensions.empty? || paths.include?(ext_dir)
b8524a
+    paths << File.join(ext_dir, require_paths.first) unless extensions.empty? || (ext_dir == full_gem_path)
b8524a
 
b8524a
     # gem directories must come after -I and ENV['RUBYLIB']
b8524a
     insert_index = Gem.load_path_insert_index
b8524a
@@ -1702,7 +1702,7 @@ class Gem::Specification
b8524a
   # eg: /usr/local/lib/ruby/1.8/exts/mygem-1.0
b8524a
 
b8524a
   def ext_dir
b8524a
-    @ext_dir ||= File.join exts_dir, full_name, require_paths.first
b8524a
+    @ext_dir ||= File.join exts_dir, full_name
b8524a
   end
b8524a
 
b8524a
   ##
b8524a
-- 
b8524a
1.8.1.2
b8524a
b8524a
b8524a
From 476c2f90cc6f5f490858f253a9b23eb19d53d2fc Mon Sep 17 00:00:00 2001
b8524a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
b8524a
Date: Tue, 13 Dec 2011 12:14:54 +0100
b8524a
Subject: [PATCH 5/8] Remove binary extensions during uninstall.
b8524a
b8524a
---
b8524a
 lib/rubygems/uninstaller.rb | 1 +
b8524a
 1 file changed, 1 insertion(+)
b8524a
b8524a
diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb
b8524a
index d672b9d..5c31a0c 100644
b8524a
--- a/lib/rubygems/uninstaller.rb
b8524a
+++ b/lib/rubygems/uninstaller.rb
b8524a
@@ -246,6 +246,7 @@ class Gem::Uninstaller
b8524a
       File.writable?(spec.base_dir)
b8524a
 
b8524a
     FileUtils.rm_rf spec.full_gem_path
b8524a
+    FileUtils.rm_rf spec.ext_dir
b8524a
 
b8524a
     # TODO: should this be moved to spec?... I vote eww (also exists in docmgr)
b8524a
     old_platform_name = [spec.name,
b8524a
-- 
b8524a
1.8.1.2
b8524a
b8524a
b8524a
From 35dc17e86f701fe1be80d98ace79735c535fd570 Mon Sep 17 00:00:00 2001
b8524a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
b8524a
Date: Tue, 13 Dec 2011 14:27:14 +0100
b8524a
Subject: [PATCH 6/8] Avoid dependency on customized operating_system.rb.
b8524a
b8524a
---
b8524a
 lib/rubygems/defaults.rb      | 11 +++++++++++
b8524a
 lib/rubygems/specification.rb |  5 +----
b8524a
 2 files changed, 12 insertions(+), 4 deletions(-)
b8524a
b8524a
diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb
b8524a
index ea84e5c..b221954 100644
b8524a
--- a/lib/rubygems/defaults.rb
b8524a
+++ b/lib/rubygems/defaults.rb
b8524a
@@ -103,6 +103,17 @@ module Gem
b8524a
   end
b8524a
 
b8524a
   ##
b8524a
+  # Returns binary extensions dir for specified RubyGems base dir or nil
b8524a
+  # if such directory cannot be determined.
b8524a
+  #
b8524a
+  # By default, the binary extensions are located side by side with their
b8524a
+  # Ruby counterparts, therefore nil is returned
b8524a
+
b8524a
+  def self.default_ext_dir_for base_dir
b8524a
+    nil
b8524a
+  end
b8524a
+
b8524a
+  ##
b8524a
   # A wrapper around RUBY_ENGINE const that may not be defined
b8524a
 
b8524a
   def self.ruby_engine
b8524a
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
b8524a
index fa9ea6e..2b10499 100644
b8524a
--- a/lib/rubygems/specification.rb
b8524a
+++ b/lib/rubygems/specification.rb
b8524a
@@ -1710,10 +1710,7 @@ class Gem::Specification
b8524a
   # gem directory. eg: /usr/local/lib/ruby/1.8/gems
b8524a
 
b8524a
   def exts_dir
b8524a
-    @exts_dir ||= begin
b8524a
-      dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
b8524a
-      dirs ? File.join(dirs.last[:ext_dir], 'exts') : gems_dir
b8524a
-    end
b8524a
+    @exts_dir ||= Gem.default_ext_dir_for(base_dir) || gems_dir
b8524a
   end
b8524a
 
b8524a
   ##
b8524a
-- 
b8524a
1.8.1.2
b8524a
b8524a
b8524a
From 0937c0b0a3c2ed08ab5b0875f7f95e24157525c2 Mon Sep 17 00:00:00 2001
b8524a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
b8524a
Date: Thu, 7 Feb 2013 13:07:34 +0100
b8524a
Subject: [PATCH 7/8] Fix binary extensions installation when --install-dir is
b8524a
 specified.
b8524a
b8524a
---
b8524a
 lib/rubygems/installer.rb | 2 +-
b8524a
 1 file changed, 1 insertion(+), 1 deletion(-)
b8524a
b8524a
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
b8524a
index f1f2ad7..e1577fc 100644
b8524a
--- a/lib/rubygems/installer.rb
b8524a
+++ b/lib/rubygems/installer.rb
b8524a
@@ -656,7 +656,7 @@ TEXT
b8524a
       say "This could take a while..."
b8524a
     end
b8524a
 
b8524a
-    dest_path = File.join spec.ext_dir, spec.require_paths.first
b8524a
+    dest_path = File.join(options[:install_dir] ? gem_dir : spec.ext_dir, spec.require_paths.first)
b8524a
     ran_rake = false # only run rake once
b8524a
 
b8524a
     spec.extensions.each do |extension|
b8524a
-- 
b8524a
1.8.1.2
b8524a
b8524a
b8524a
From 062a11c59731f5875d5a8821a212c8a41cb84577 Mon Sep 17 00:00:00 2001
b8524a
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
b8524a
Date: Fri, 15 Feb 2013 17:07:07 +0100
b8524a
Subject: [PATCH 8/8] Use correct option.
b8524a
b8524a
---
b8524a
 lib/rubygems/installer.rb | 2 +-
b8524a
 1 file changed, 1 insertion(+), 1 deletion(-)
b8524a
b8524a
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
b8524a
index e1577fc..1492c68 100644
b8524a
--- a/lib/rubygems/installer.rb
b8524a
+++ b/lib/rubygems/installer.rb
b8524a
@@ -656,7 +656,7 @@ TEXT
b8524a
       say "This could take a while..."
b8524a
     end
b8524a
 
b8524a
-    dest_path = File.join(options[:install_dir] ? gem_dir : spec.ext_dir, spec.require_paths.first)
b8524a
+    dest_path = File.join(@install_dir ? gem_dir : spec.ext_dir, spec.require_paths.first)
b8524a
     ran_rake = false # only run rake once
b8524a
 
b8524a
     spec.extensions.each do |extension|
b8524a
-- 
b8524a
1.8.1.2
b8524a