Skip to content
Browse files

Avoid the need for dependency loops

  * pure-Ruby library code is duplicated in native packages
  * if there is a ruby-foo-common package, the pure-Ruby libraries are
    installed in it instead.
  * programs are installed in either ruby-foo-common (if present), or in
    the first binary package otherwise.
  • Loading branch information...
1 parent 765e7da commit 90112545fdfb7c78a03f3836c08ab949925b7e85 @terceiro committed Feb 28, 2011
View
72 lib/gem2deb/dhruby.rb
@@ -54,8 +54,6 @@ class DhRuby
def initialize
@verbose = true
@bindir = '/usr/bin'
- @prefix = nil
- @libdir = '/usr/lib/ruby/vendor_ruby'
end
def clean
@@ -89,13 +87,13 @@ def test
def install(argv)
puts "Entering dh_ruby --install" if @verbose
+ packages_to_install_programs_in.each do |package|
+ install_files('bin', find_files('bin'), File.join(destdir_for(package), @bindir), 755) if File::directory?('bin')
+ end
- # assume all Ruby files will be installed in the first package listed in
- # debian/control, which should be ruby-foo OR foo
- @prefix = destdir_for(packages.first)
-
- install_files('bin', find_files('bin'), @bindir, 755) if File::directory?('bin')
- install_files('lib', find_files('lib'), @libdir, 644) if File::directory?('lib')
+ packages_to_install_libraries_in.each do |package|
+ install_files('lib', find_files('lib'), File.join(destdir_for(package), libdir_for(package)), 644) if File::directory?('lib')
+ end
packages.each do |package|
# handle extensions
@@ -242,12 +240,12 @@ def find_files(dir, accept_pattern=nil)
end
def install_files(src, list, dest, mode)
- run "install -d #{@prefix + '/' + dest}"
+ run "install -d #{dest}"
list.each do |fname|
if File::directory?(src + '/' + fname)
- run "install -d #{@prefix + '/' + dest + '/' + fname}"
+ run "install -d #{dest + '/' + fname}"
else
- run "install -m#{mode} #{src + '/' + fname} #{@prefix + '/' + dest + '/' + fname}"
+ run "install -m#{mode} #{src + '/' + fname} #{dest + '/' + fname}"
end
end
end
@@ -297,5 +295,57 @@ def atomic_rewrite(path, &block)
def packages
@packages ||= `dh_listpackages`.split
end
+
+ def packages_to_install_libraries_in
+ if single_package?
+ packages
+ else
+ if has_common_package?
+ common_packages
+ else
+ native_packages
+ end
+ end
+ end
+
+ def packages_to_install_programs_in
+ if single_package?
+ packages
+ else
+ if has_common_package?
+ common_packages
+ else
+ packages.first
+ end
+ end
+ end
+
+ def single_package?
+ packages.size == 1
+ end
+
+ def has_common_package?
+ common_packages.size > 0
+ end
+
+ def common_packages
+ @common_packages ||= packages.grep /ruby-.*-common/
+ end
+
+ def native_packages
+ @native_packages ||= packages.select { |pkg| ruby_version_for(pkg) != 'ruby' }
+ end
+
+ def libdir_for(package)
+ case ruby_version_for(package)
+ when 'ruby1.8'
+ '/usr/lib/ruby/vendor_ruby/1.8'
+ when 'ruby1.9.1'
+ '/usr/lib/ruby/vendor_ruby/1.9.1'
+ else
+ '/usr/lib/ruby/vendor_ruby'
+ end
+ end
+
end
end
View
4 test/helper/samples.rb
@@ -18,5 +18,9 @@ module Samples
SIMPLE_TGZ_NAME = 'simpletgz'
SIMPLE_TGZ_DIRNAME = SIMPLE_TGZ_NAME + '-0.0.1'
SIMPLE_TGZ = File.join(SAMPLE_DIR, "#{SIMPLE_TGZ_NAME}/pkg/#{SIMPLE_TGZ_DIRNAME}.tgz")
+
+ 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")
end
end
View
22 test/sample/simplemixed/Rakefile
@@ -0,0 +1,22 @@
+require 'rubygems'
+require 'rake/gempackagetask'
+
+spec = Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.summary = "Simple native extension used to test dh_ruby"
+ s.name = 'simplemixed'
+ s.version = '1.2.3'
+ s.requirements << 'none'
+ s.require_path = 'ext'
+ s.extensions << 'ext/simplemixed/extconf.rb'
+ #s.autorequire = 'rake'
+ s.files = Dir.glob('{bin,ext,lib}/**/*')
+ s.description = <<EOF
+simplemixed is a simple mixed library (both pure-Ruby and native extension) that is used to test dh_ruby.
+EOF
+end
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_zip = false
+ pkg.need_tar = false
+end
View
3 test/sample/simplemixed/bin/simplemixed
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+puts "I am a program installed by simplemixed"
View
2 test/sample/simplemixed/ext/simplemixed/extconf.rb
@@ -0,0 +1,2 @@
+require 'mkmf'
+create_makefile('simplemixed')
View
5 test/sample/simplemixed/ext/simplemixed/simplemixed.c
@@ -0,0 +1,5 @@
+#include "ruby.h"
+
+void Init_simplemixed() {
+ rb_define_module("SimpleMixed");
+}
View
1 test/sample/simplemixed/lib/simplemixed.rb
@@ -0,0 +1 @@
+require 'simplemixed.so'
View
BIN test/sample/simplemixed/pkg/simplemixed-1.2.3.gem
Binary file not shown.
View
53 test/unit/dh_ruby_test.rb
@@ -1,4 +1,6 @@
require 'test_helper'
+require 'gem2deb/gem2tgz'
+require 'gem2deb/dh-make-ruby'
require 'gem2deb/dhruby'
require 'rbconfig'
@@ -8,6 +10,7 @@ class DhRubyTest < Gem2DebTestCase
build(SIMPLE_GEM, SIMPLE_GEM_DIRNAME)
build(SIMPLE_PROGRAM, SIMPLE_PROGRAM_DIRNAME)
build(SIMPLE_EXTENSION, SIMPLE_EXTENSION_DIRNAME)
+ build(SIMPLE_MIXED, SIMPLE_MIXED_DIRNAME)
end
context 'installing simplegem' do
@@ -58,6 +61,56 @@ class DhRubyTest < Gem2DebTestCase
end
end
+ context 'mixed packages (both pure-Ruby and native library code)' do
+ should 'install Ruby libraries into single package' do
+ dh_ruby = Gem2Deb::DhRuby.new
+ dh_ruby.stubs(:packages).returns(['ruby-foo'])
+ assert_equal ['ruby-foo'], dh_ruby.send(:packages_to_install_libraries_in)
+ end
+
+ should 'install Ruby libraries in native packages' do
+ dh_ruby = Gem2Deb::DhRuby.new
+ dh_ruby.stubs(:packages).returns(['ruby-foo', 'ruby1.8-foo', 'ruby1.9.1-foo'])
+ assert_equal ['ruby1.8-foo', 'ruby1.9.1-foo'], dh_ruby.send(:packages_to_install_libraries_in)
+ end
+
+ should 'install Ruby code in ruby-foo-common package if it is present' do
+ dh_ruby = Gem2Deb::DhRuby.new
+ dh_ruby.stubs(:packages).returns(['ruby-foo', 'ruby1.8-foo', 'ruby1.9.1-foo', 'ruby-foo-common'])
+ assert_equal ['ruby-foo-common'], dh_ruby.send(:packages_to_install_libraries_in)
+ end
+
+ should 'install programs in single package' do
+ dh_ruby = Gem2Deb::DhRuby.new
+ dh_ruby.stubs(:packages).returns(['ruby-foo'])
+ assert_equal ['ruby-foo'], dh_ruby.send(:packages_to_install_programs_in)
+ end
+
+ should 'install programs in common package if present' do
+ dh_ruby = Gem2Deb::DhRuby.new
+ dh_ruby.stubs(:packages).returns(['ruby-foo', 'ruby1.8-foo', 'ruby1.9.1-foo', 'ruby-foo-common'])
+ assert_equal ['ruby-foo-common'], dh_ruby.send(:packages_to_install_programs_in)
+ end
+
+ should 'duplicate pure-Ruby code in native packages' do
+ assert_installed SIMPLE_MIXED_DIRNAME, 'ruby1.8-simplemixed', '/usr/lib/ruby/vendor_ruby/1.8/simplemixed.rb'
+ assert_installed SIMPLE_MIXED_DIRNAME, 'ruby1.9.1-simplemixed', '/usr/lib/ruby/vendor_ruby/1.9.1/simplemixed.rb'
+ end
+
+ end
+
+ context 'calculating libdir for each package' do
+ {
+ 'ruby-foo' => '/usr/lib/ruby/vendor_ruby',
+ 'ruby1.8-foo' => '/usr/lib/ruby/vendor_ruby/1.8',
+ 'ruby1.9.1-foo' => '/usr/lib/ruby/vendor_ruby/1.9.1',
+ }.each do |package,path|
+ should "install Ruby code for #{package} at #{path}" do
+ assert_equal path, Gem2Deb::DhRuby.new.send(:libdir_for, package)
+ end
+ end
+ end
+
protected
def assert_installed(gem_dirname, package, path)

0 comments on commit 9011254

Please sign in to comment.
Something went wrong with that request. Please try again.