Skip to content

Commit

Permalink
Avoid the need for dependency loops
Browse files Browse the repository at this point in the history
  * 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
terceiro committed Feb 28, 2011
1 parent 765e7da commit 9011254
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 11 deletions.
72 changes: 61 additions & 11 deletions lib/gem2deb/dhruby.rb
Expand Up @@ -54,8 +54,6 @@ class DhRuby
def initialize
@verbose = true
@bindir = '/usr/bin'
@prefix = nil
@libdir = '/usr/lib/ruby/vendor_ruby'
end

def clean
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/helper/samples.rb
Expand Up @@ -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
22 changes: 22 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions test/sample/simplemixed/bin/simplemixed
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby

puts "I am a program installed by simplemixed"
2 changes: 2 additions & 0 deletions test/sample/simplemixed/ext/simplemixed/extconf.rb
@@ -0,0 +1,2 @@
require 'mkmf'
create_makefile('simplemixed')
5 changes: 5 additions & 0 deletions test/sample/simplemixed/ext/simplemixed/simplemixed.c
@@ -0,0 +1,5 @@
#include "ruby.h"

void Init_simplemixed() {
rb_define_module("SimpleMixed");
}
1 change: 1 addition & 0 deletions test/sample/simplemixed/lib/simplemixed.rb
@@ -0,0 +1 @@
require 'simplemixed.so'
Binary file not shown.
53 changes: 53 additions & 0 deletions 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'

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9011254

Please sign in to comment.