[DRE-commits] [SCM] gem2deb.git branch, master, updated. 0.4.0-9-gabd9703

Antonio Terceiro terceiro at debian.org
Sun Jun 2 15:19:20 UTC 2013


The following commit has been merged in the master branch:
commit 4932be1657356b2083af88d9b226372a4557afc3
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Sat Jun 1 22:21:11 2013 -0300

    Fix native extensions support for multi-binary packages

diff --git a/lib/gem2deb/extension_builder.rb b/lib/gem2deb/extension_builder.rb
index 667315a..8f3522e 100644
--- a/lib/gem2deb/extension_builder.rb
+++ b/lib/gem2deb/extension_builder.rb
@@ -66,26 +66,26 @@ module Gem2Deb
       end
     end
 
-    def self.build_all_extensions(destdir)
-      all_extensions.each do |extension|
+    def self.build_all_extensions(root, destdir)
+      all_extensions(root).each do |extension|
         ext = new(extension)
         ext.clean
         ext.build_and_install(destdir)
       end
     end
 
-    def self.all_extensions
-      @metadata ||= Gem2Deb::Metadata.new('.')
+    def self.all_extensions(root)
+      @metadata ||= Gem2Deb::Metadata.new(root)
       @metadata.native_extensions
     end
   end
 end
 
 if $PROGRAM_NAME == __FILE__
-  if ARGV.length == 1
-    Gem2Deb::ExtensionBuilder.build_all_extensions(ARGV.first)
+  if ARGV.length == 2
+    Gem2Deb::ExtensionBuilder.build_all_extensions(*ARGV)
   else
-    puts "usage: #{File.basename($PROGRAM_NAME)} DESTDIR"
+    puts "usage: #{File.basename($PROGRAM_NAME)} ROOT DESTDIR"
     exit(1)
   end
 end
diff --git a/lib/gem2deb/installer.rb b/lib/gem2deb/installer.rb
index ea40bc0..7034844 100644
--- a/lib/gem2deb/installer.rb
+++ b/lib/gem2deb/installer.rb
@@ -33,7 +33,7 @@ module Gem2Deb
       if metadata.has_native_extensions?
         ruby_versions.each do |rubyver|
           puts "Building extension for #{rubyver} ..." if verbose
-          run("#{SUPPORTED_RUBY_VERSIONS[rubyver]} -I#{LIBDIR} #{EXTENSION_BUILDER} #{destdir_base}")
+          run("#{SUPPORTED_RUBY_VERSIONS[rubyver]} -I#{LIBDIR} #{EXTENSION_BUILDER} #{root} #{destdir_base}")
 
           # Remove duplicate files installed by rubygems in the arch dir
           # This is a hack to workaround a problem in rubygems
diff --git a/lib/gem2deb/metadata.rb b/lib/gem2deb/metadata.rb
index ca44527..fa1f8b2 100644
--- a/lib/gem2deb/metadata.rb
+++ b/lib/gem2deb/metadata.rb
@@ -21,18 +21,14 @@ module Gem2Deb
   class Metadata
 
     attr_reader :gemspec
+    attr_reader :source_dir
+    attr_reader :root
 
-    attr_reader :native_extensions
-
-    def initialize(directory)
-      @source_dir = File.expand_path(directory)
-      Dir.chdir(directory) do
+    def initialize(root)
+      @source_dir = File.expand_path(root)
+      @root = root
+      Dir.chdir(source_dir) do
         load_gemspec
-        if gemspec
-          initialize_from_gemspec
-        else
-          initialize_without_gemspec
-        end
       end
     end
 
@@ -40,6 +36,20 @@ module Gem2Deb
       native_extensions.size > 0
     end
 
+    def native_extensions
+      @native_extensions ||=
+        if gemspec
+          gemspec.extensions
+        else
+          Dir.chdir(source_dir) do
+            list = []
+            list += Dir.glob('**/extconf.rb')
+            list += Dir.glob('ext/**/{configure,Rakefile}')
+            list
+          end
+        end.map { |ext| File.join(root, ext) }
+    end
+
     def name
       @name ||= gemspec && gemspec.name || read_name_from(source_dir)
     end
@@ -70,8 +80,6 @@ module Gem2Deb
 
     protected
 
-    attr_reader :source_dir
-
     def load_gemspec
       if File.exists?('metadata.yml')
         @gemspec = YAML.load_file('metadata.yml')
@@ -89,14 +97,6 @@ module Gem2Deb
       end
     end
 
-    def initialize_from_gemspec
-      @native_extensions = gemspec.extensions
-    end
-
-    def initialize_without_gemspec
-      @native_extensions = Dir.glob('**/extconf.rb') + Dir.glob('ext/**/{configure,Rakefile}')
-    end
-
     # FIXME duplicated logic (see below)
     def read_name_from(directory)
       return nil if directory.nil?
diff --git a/test/integration/gem2deb_test.rb b/test/integration/gem2deb_test.rb
index d937a9c..a71ffac 100644
--- a/test/integration/gem2deb_test.rb
+++ b/test/integration/gem2deb_test.rb
@@ -68,6 +68,10 @@ class Gem2DebTest < Gem2DebTestCase
       should 'support installing upstream CHANGELOG in multibinary package' do
         assert_file_exists "#{dir}/debian/ruby-bar/usr/share/doc/ruby-bar/changelog.gz"
       end
+
+      should 'support native extensions' do
+        assert Dir.glob("#{dir}/debian/ruby-baz/**/baz.so").size > 0, 'baz.so not found!!!'
+      end
     end
   end
 
diff --git a/test/sample/multibinary/baz/ext/baz/baz.c b/test/sample/multibinary/baz/ext/baz/baz.c
new file mode 100644
index 0000000..dfc5541
--- /dev/null
+++ b/test/sample/multibinary/baz/ext/baz/baz.c
@@ -0,0 +1,13 @@
+#include "ruby.h"
+
+VALUE method_answer42(VALUE module, VALUE self);
+
+void Init_baz() {
+  VALUE BAZ = rb_define_module("BAZ");
+  rb_define_module_function(BAZ, "answer42", method_answer42, 0);
+  rb_define_const(BAZ, "Hello_world", rb_str_new2("Hello World"));
+}
+
+VALUE method_answer42(VALUE module, VALUE self) {
+	return INT2NUM(42);
+}
diff --git a/test/sample/multibinary/baz/ext/baz/extconf.rb b/test/sample/multibinary/baz/ext/baz/extconf.rb
new file mode 100644
index 0000000..fffd9ce
--- /dev/null
+++ b/test/sample/multibinary/baz/ext/baz/extconf.rb
@@ -0,0 +1,2 @@
+require 'mkmf'
+create_makefile('baz')
diff --git a/test/sample/multibinary/debian/control b/test/sample/multibinary/debian/control
index 21aaf5e..78638a7 100644
--- a/test/sample/multibinary/debian/control
+++ b/test/sample/multibinary/debian/control
@@ -25,3 +25,11 @@ XB-Ruby-Versions: ${ruby:Versions}
 Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter
 Description: FIXME
  <insert long description, indented with spaces>
+
+Package: ruby-baz
+X-DhRuby-Root: baz
+Architecture: all
+XB-Ruby-Versions: ${ruby:Versions}
+Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter
+Description: FIXME
+ <insert long description, indented with spaces>
diff --git a/test/unit/extension_builder_test.rb b/test/unit/extension_builder_test.rb
index bcb5f24..78f1211 100644
--- a/test/unit/extension_builder_test.rb
+++ b/test/unit/extension_builder_test.rb
@@ -12,7 +12,7 @@ class ExtensionBuilderTest < Gem2DebTestCase
     FileUtils.cp_r(File.join('test/sample/', gem), target_dir)
     Dir.chdir(target_dir) do
       silence_stream STDOUT do
-        Gem2Deb::ExtensionBuilder.build_all_extensions(package)
+        Gem2Deb::ExtensionBuilder.build_all_extensions('.', "debian/#{package}")
       end
     end
   end
diff --git a/test/unit/metadata_test.rb b/test/unit/metadata_test.rb
index 332afdd..cbc72f0 100644
--- a/test/unit/metadata_test.rb
+++ b/test/unit/metadata_test.rb
@@ -101,5 +101,26 @@ class MetaDataTest < Gem2DebTestCase
 
   end
 
+  context 'on multi-binary source packages' do
+
+    setup do
+      Dir.chdir('test/sample/multibinary') do
+        @metadata = Gem2Deb::Metadata.new('baz')
+      end
+    end
+
+    should 'get the right path for extensions without a gemspec' do
+      assert_equal ['baz/ext/baz/extconf.rb'], @metadata.native_extensions
+    end
+
+    should 'get the right path to extensions with a gemspec' do
+      @gemspec = mock
+      @metadata.stubs(:gemspec).returns(@gemspec)
+      @gemspec.expects(:extensions).returns(['path/to/extconf.rb'])
+      assert_equal ['baz/path/to/extconf.rb'], @metadata.native_extensions
+    end
+
+  end
+
 end
 

-- 
gem2deb.git



More information about the Pkg-ruby-extras-commits mailing list