[DRE-commits] [gem2deb] 02/02: checkpoint
Antonio Terceiro
terceiro at moszumanska.debian.org
Wed Nov 26 14:20:48 UTC 2014
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to branch install-as-gem
in repository gem2deb.
commit ce98c503a4b890fd5ff706173b2faa25c4f35342
Author: Antonio Terceiro <terceiro at debian.org>
Date: Wed Oct 15 15:53:44 2014 -0300
checkpoint
---
TODO.otl | 2 +
bin/dh_ruby | 5 +
.../Debian/Debhelper/Buildsystem/rubygems.pm | 53 +++++++++++
lib/gem2deb/gem_installer.rb | 105 +++++++++++++++++++++
lib/gem2deb/test_runner.rb | 10 ++
5 files changed, 175 insertions(+)
diff --git a/TODO.otl b/TODO.otl
new file mode 100644
index 0000000..eb8870e
--- /dev/null
+++ b/TODO.otl
@@ -0,0 +1,2 @@
+install C extensions to /usr/lib/rubygems-integration
+run make clean on installed dirs to remove .so's from "source" path
diff --git a/bin/dh_ruby b/bin/dh_ruby
index 484fee8..287d6dd 100755
--- a/bin/dh_ruby
+++ b/bin/dh_ruby
@@ -18,6 +18,7 @@
require 'gem2deb'
require 'gem2deb/dh_ruby'
require 'gem2deb/setup_rb_installer'
+require 'gem2deb/gem_installer'
require 'optparse'
include Gem2Deb
@@ -33,6 +34,10 @@ optparse = OptionParser.new do |opts|
engine.installer_class = Gem2Deb::SetupRbInstaller
end
+ opts.on('--gem-install', 'install files as a gem') do
+ engine.installer_class = Gem2Deb::GemInstaller
+ end
+
opts.on('-v', '--version', 'show dh_ruby version') do
puts "dh_ruby version #{Gem2Deb::VERSION}"
exit
diff --git a/debhelper7/Debian/Debhelper/Buildsystem/rubygems.pm b/debhelper7/Debian/Debhelper/Buildsystem/rubygems.pm
new file mode 100644
index 0000000..6aa1519
--- /dev/null
+++ b/debhelper7/Debian/Debhelper/Buildsystem/rubygems.pm
@@ -0,0 +1,53 @@
+# A debhelper build system class for building Ruby projects as gems.
+#
+# Copyright: © 2014 Antonio Terceiro
+# License: GPL-2+
+# Strongly based on other build systems. Thanks!
+
+package Debian::Debhelper::Buildsystem::rubygems;
+
+use strict;
+use base 'Debian::Debhelper::Buildsystem';
+
+sub DESCRIPTION {
+ "Ruby (Gem2Deb/Rubygems)"
+}
+
+sub check_auto_buildable {
+ my $this=shift;
+ return (-e $this->get_sourcepath("metadata.yml")) ? 1 : 0;
+}
+
+sub new {
+ my $class=shift;
+ my $this=$class->SUPER::new(@_);
+ $this->enforce_in_source_building();
+ return $this;
+}
+
+sub configure {
+ my $this=shift;
+ $this->doit_in_sourcedir("dh_ruby", "--gem-install", "--configure", @_);
+}
+
+sub build {
+ my $this=shift;
+ $this->doit_in_sourcedir("dh_ruby", "--gem-install", "--build", @_);
+}
+
+sub test {
+ my $this=shift;
+ $this->doit_in_sourcedir("dh_ruby", "--gem-install", "--test", @_);
+}
+
+sub install {
+ my $this=shift;
+ $this->doit_in_sourcedir("dh_ruby", "--gem-install", "--install", @_);
+}
+
+sub clean {
+ my $this=shift;
+ $this->doit_in_sourcedir("dh_ruby", "--gem-install", "--clean", @_);
+}
+
+1
diff --git a/lib/gem2deb/gem_installer.rb b/lib/gem2deb/gem_installer.rb
new file mode 100644
index 0000000..a189ae5
--- /dev/null
+++ b/lib/gem2deb/gem_installer.rb
@@ -0,0 +1,105 @@
+# Copyright © 2014, Antonio Terceiro <terceiro at debian.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require 'gem2deb/installer'
+require 'tmpdir'
+
+module Gem2Deb
+
+ class GemInstaller < Installer
+
+ def install_files_and_build_extensions
+ done = false
+
+ ruby_versions.each do |rubyver|
+ if done && !metadata.has_native_extensions?
+ break
+ end
+
+ ruby = SUPPORTED_RUBY_VERSIONS[rubyver]
+ tmpdir = Dir.mktmpdir
+
+ # generate gemspec at temporary directory
+ gemspec_data = gemspec_data!
+ gemspec = File.join(tmpdir, 'gemspec')
+
+ File.open(gemspec, 'w') do |f|
+ f.write(gemspec_data.to_ruby)
+ end
+
+ # build .gem
+ Dir.chdir(root) do
+ gem(ruby, 'build', gemspec)
+ FileUtils.mv(Dir.glob('*.gem').first, tmpdir)
+ end
+
+ # install .gem
+ gempkg = Dir.glob(File.join(tmpdir, '*.gem')).first
+ target_dir = rubygems_integration_target(rubyver)
+ gem(
+ ruby,
+ 'install',
+ '--local',
+ '--ignore-dependencies',
+ '--install-dir', File.join(destdir_base, target_dir),
+ gempkg
+ )
+
+ Dir.glob(File.join(target_dir, '**/Makefile')).each do |makefile|
+ Dir.chdir(File.dirname(makefile)) do
+ run('make distclean || make clean')
+ end
+ end
+
+ # remove tmpdir
+ FileUtils.rm_f(tmpdir)
+
+ done = true
+ end
+ end
+
+ class NoGemspec < Exception
+ def initialize(root)
+ super("No gemspec found at #{root}")
+ end
+ end
+
+ protected
+
+ def rubygems_integration_target(rubyver)
+ if metadata.has_native_extensions?
+ arch = RbConfig::CONFIG['arch']
+ api_version = Gem2Deb::RUBY_API_VERSION[rubyver]
+ "/usr/lib/#{arch}/rubygems-integration/#{api_version}"
+ else
+ "/usr/share/rubygems-integration/all"
+ end
+ end
+
+ def gem(ruby, command, *args)
+ run(ruby, '-S', 'gem', command, '--config-file', '/dev/null', '--verbose', *args)
+ end
+
+ def gemspec_data!
+ if metadata.gemspec
+ metadata.gemspec
+ else
+ raise NoGemspec.new(root)
+ end
+ end
+
+ end
+
+end
diff --git a/lib/gem2deb/test_runner.rb b/lib/gem2deb/test_runner.rb
index 67dbe8c..377ba95 100644
--- a/lib/gem2deb/test_runner.rb
+++ b/lib/gem2deb/test_runner.rb
@@ -48,6 +48,14 @@ module Gem2Deb
dirs
end
+ def gem_path
+ if autopkgtest
+ []
+ else
+ Dir.glob('debian/*/usr/**/rubygems-integration/*')
+ end
+ end
+
# Override in subclasses
def run_tests
end
@@ -68,12 +76,14 @@ module Gem2Deb
def run_ruby(*cmd)
rubylib = load_path.join(':')
+ gempath = gem_path.join(':')
cmd.unshift(rubyver)
if $VERBOSE
print "RUBYLIB=#{rubylib} "
puts cmd.map { |part| part =~ /['"]/ ? part.inspect : part }.join(' ')
end
ENV['RUBYLIB'] = (ENV['RUBYLIB'] ? ENV['RUBYLIB'] + ':' : '') + rubylib
+ ENV['GEM_PATH'] = (ENV['GEM_PATH'] ? ENV['GEM_PATH'] + ':' : '') + gempath
if autopkgtest
move_away 'lib'
move_away 'ext'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/gem2deb.git
More information about the Pkg-ruby-extras-commits
mailing list