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