[DRE-commits] [SCM] gem2deb.git branch, master, updated. 09814c81604454c8f02e01c95c890e340d544bce

Antonio Terceiro terceiro at softwarelivre.org
Fri Apr 8 08:17:16 UTC 2011


The following commit has been merged in the master branch:
commit 09814c81604454c8f02e01c95c890e340d544bce
Author: Antonio Terceiro <terceiro at softwarelivre.org>
Date:   Fri Apr 8 01:10:28 2011 -0700

    Support running dh-make-ruby over a directory

diff --git a/bin/dh-make-ruby b/bin/dh-make-ruby
index e9390bf..221c79a 100755
--- a/bin/dh-make-ruby
+++ b/bin/dh-make-ruby
@@ -47,9 +47,9 @@ if ARGV.length != 1
   exit(1)
 end
 
-tarball = ARGV[0]
+input = ARGV[0]
 
-dmr = Gem2Deb::DhMakeRuby::new(tarball, options)
+dmr = Gem2Deb::DhMakeRuby::new(input, options)
 dmr.build
 
 __END__
@@ -59,12 +59,13 @@ dh-make-ruby - build Debian source package from Ruby library
 
 =head1 USAGE
 
-B<dh-make-ruby> [I<OPTIONS>] I<TARBALL>
+B<dh-make-ruby> [I<OPTIONS>] I<TARBALL>|I<DIRECTORY>
 
 =head1 DESCRIPTION
 
 B<dh-make-ruby> will create a basic Debian source package from a tarball named
-I<TARBALL> generated with B<gem2tgz>.
+I<TARBALL> generated with B<gem2tgz>, or from a I<DIRECTORY> containing Ruby
+code and metadata in a .gemspec file.
 
 =head1 OPTIONS
 
diff --git a/lib/gem2deb/dh_make_ruby.rb b/lib/gem2deb/dh_make_ruby.rb
index 328ca2b..fcbc48c 100644
--- a/lib/gem2deb/dh_make_ruby.rb
+++ b/lib/gem2deb/dh_make_ruby.rb
@@ -1,3 +1,4 @@
+# vim: ts=2 sw=2 expandtab
 # -*- coding: utf-8 -*-
 # Copyright © 2011, Lucas Nussbaum <lucas at debian.org>
 # 
@@ -51,14 +52,35 @@ module Gem2Deb
 
     attr_accessor :ruby_versions
 
-    def initialize(tarball, options = {})
-      self.source_tarball_name = File.basename(tarball)
-      self.orig_tarball_dir = File.dirname(tarball)
+    attr_accessor :input_directory
 
+    def initialize(input, options = {})
+      initialize_from_options(options)
+      if File.directory?(input)
+        initialize_from_directory(input)
+      else
+        initialize_from_tarball(input)
+      end
+    end
+
+    def initialize_from_options(options)
       self.ruby_versions = 'all'
       options.each do |attr,value|
         self.send("#{attr}=", value)
       end
+    end
+
+    def initialize_from_directory(directory)
+      self.input_directory = directory
+      read_metadata(directory)
+      self.gem_name = metadata.gemspec.name
+      self.gem_version = metadata.gemspec.version.to_s
+      self.source_package_name ||= gem_name_to_source_package_name(gem_name)
+    end
+
+    def initialize_from_tarball(tarball)
+      self.source_tarball_name = File.basename(tarball)
+      self.orig_tarball_dir = File.dirname(tarball)
 
       if source_tarball_name =~ /^(.*)_(.*).orig.tar.gz$/
         self.gem_name = $1
@@ -68,13 +90,17 @@ module Gem2Deb
       elsif source_tarball_name =~ /^(.*)-(.*).tar.gz$/
         self.gem_name = $1
         self.gem_version = $2
-        self.source_package_name ||= 'ruby-' + gem_name.gsub(/^ruby[-_]|[-_]ruby$/, '')
+        self.source_package_name ||= gem_name_to_source_package_name(gem_name)
         self.orig_tarball_name = "#{source_package_name}_#{gem_version}.orig.tar.gz"
       else
         raise "Could not determine gem name and version from tarball #{source_tarball_name}"
       end
     end
 
+    def gem_name_to_source_package_name(gem_name)
+      'ruby-' + gem_name.gsub(/^ruby[-_]|[-_]ruby$/, '')
+    end
+
     def gem_dirname
       [gem_name, gem_version].join('-')
     end
@@ -96,25 +122,33 @@ module Gem2Deb
     end
 
     def build
-      Dir.chdir(orig_tarball_dir) do
-        create_orig_tarball
-        extract
-        Dir.chdir(source_dirname) do
-          read_upstream_source_info
-          create_debian_boilerplates
-          other_files
-          test_suite
+      if input_directory
+        build_in_directory(input_directory)
+      else
+        Dir.chdir(orig_tarball_dir) do
+          create_orig_tarball
+          extract
+          build_in_directory(source_dirname)
         end
       end
     end
+
+    def build_in_directory(directory)
+      Dir.chdir(directory) do
+        read_upstream_source_info
+        create_debian_boilerplates
+        other_files
+        test_suite
+      end
+    end
     
     def read_upstream_source_info
-      read_metadata
+      read_metadata('.')
       initialize_binary_package
     end
 
-    def read_metadata
-      self.metadata = Gem2Deb::Metadata.new('.')
+    def read_metadata(directory)
+      @metadata ||= Gem2Deb::Metadata.new(directory)
     end
 
     def initialize_binary_package
@@ -154,7 +188,7 @@ module Gem2Deb
     def create_debian_boilerplates
       FileUtils.mkdir_p('debian')
       unless File.exists?('debian/changelog')
-        run "dch --create --empty --fromdirname 'Initial release (Closes: #nnnn)'"
+        run "dch --create --empty --package #{source_package_name} --newversion #{gem_version} 'Initial release (Closes: #nnnn)'"
       end
       templates.each do |template|
         FileUtils.mkdir_p(template.directory)
diff --git a/test/helper/samples.rb b/test/helper/samples.rb
index 2cb3427..f77d520 100644
--- a/test/helper/samples.rb
+++ b/test/helper/samples.rb
@@ -26,5 +26,7 @@ class Gem2DebTestCase
     SIMPLE_MIXED_NAME     = 'simplemixed'
     SIMPLE_MIXED_DIRNAME  = SIMPLE_MIXED_NAME + '-1.2.3'
     SIMPLE_MIXED          = File.join(SAMPLE_DIR, "#{SIMPLE_MIXED_NAME}/pkg/#{SIMPLE_MIXED_DIRNAME}.gem")
+
+    SIMPLE_GIT            = File.join(SAMPLE_DIR, 'simplegit')
   end
 end
diff --git a/test/sample/simplegit/lib/simplegit.rb b/test/sample/simplegit/lib/simplegit.rb
new file mode 100644
index 0000000..9061722
--- /dev/null
+++ b/test/sample/simplegit/lib/simplegit.rb
@@ -0,0 +1,3 @@
+module Simplegit
+  # Your code goes here...
+end
diff --git a/test/sample/simplegit/lib/simplegit/version.rb b/test/sample/simplegit/lib/simplegit/version.rb
new file mode 100644
index 0000000..26532d6
--- /dev/null
+++ b/test/sample/simplegit/lib/simplegit/version.rb
@@ -0,0 +1,3 @@
+module Simplegit
+  VERSION = "0.0.1"
+end
diff --git a/test/sample/simplegit/simplegit.gemspec b/test/sample/simplegit/simplegit.gemspec
new file mode 100644
index 0000000..8f8ce4e
--- /dev/null
+++ b/test/sample/simplegit/simplegit.gemspec
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "simplegit/version"
+
+Gem::Specification.new do |s|
+  s.name        = "simplegit"
+  s.version     = Simplegit::VERSION
+  s.platform    = Gem::Platform::RUBY
+  s.authors     = ["Antonio Terceiro"]
+  s.email       = ["terceiro at softwarelivre.org"]
+  s.homepage    = ""
+  s.summary     = %q{Simple gem faking code from git}
+  s.description = %q{This gem is used to test the case where dh-make-ruby is called on a directory}
+
+  s.rubyforge_project = "simplegit"
+
+  s.files = %w[
+    lib
+    lib/simplegit.rb
+    lib/simplegit
+    lib/simplegit/version.rb
+    Rakefile
+    simplegit.gemspec
+  ]
+  s.require_paths = ["lib"]
+end
diff --git a/test/unit/dh_make_ruby_test.rb b/test/unit/dh_make_ruby_test.rb
index 2ae1b0a..5bc9a3b 100644
--- a/test/unit/dh_make_ruby_test.rb
+++ b/test/unit/dh_make_ruby_test.rb
@@ -73,6 +73,27 @@ class DhMakeRubyTest < Gem2DebTestCase
     end
   end
 
+  TEST_SIMPLE_GIT = File.join(tmpdir, 'simplegit')
+  one_time_setup do
+    FileUtils.cp_r(SIMPLE_GIT, TEST_SIMPLE_GIT)
+    Gem2Deb::DhMakeRuby.new(TEST_SIMPLE_GIT).build
+  end
+
+  context 'running dh-make-ruby against a directory' do
+    should 'get the package name correctly' do
+      assert_equal ['ruby-simplegit'], Dir.chdir(TEST_SIMPLE_GIT) { packages }
+    end
+    should 'get the version name correctly' do
+      assert_equal 'Version: 0.0.1', Dir.chdir(TEST_SIMPLE_GIT) { `dpkg-parsechangelog | grep Version:`.strip }
+    end
+    should 'create debian/control' do
+      assert_file_exists File.join(TEST_SIMPLE_GIT, 'debian/control')
+    end
+    should 'create debian/rules' do
+      assert_file_exists File.join(TEST_SIMPLE_GIT, 'debian/rules')
+    end
+  end
+
   protected
 
   def packages

-- 
gem2deb.git



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