[DRE-commits] [gem2deb] 02/05: add experimental support for installing packages as gems

Antonio Terceiro terceiro at moszumanska.debian.org
Fri Nov 13 16:37:58 UTC 2015


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to branch master
in repository gem2deb.

commit cb0a384e178323ea0cfb03eb1053358b7de7ba42
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Wed Nov 11 14:56:35 2015 -0200

    add experimental support for installing packages as gems
---
 bin/dh_ruby                  |  12 ++++
 debian/changelog             |   1 +
 lib/gem2deb/gem_installer.rb | 138 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+)

diff --git a/bin/dh_ruby b/bin/dh_ruby
index 805f5f6..527555f 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'
 require 'shellwords'
 include Gem2Deb
@@ -43,6 +44,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
@@ -217,6 +222,13 @@ Displays B<dh_ruby> usage information.
 
 Displays B<dh_ruby> version information.
 
+=item B<--gem-install>
+
+This option indicates that the build should use the B<gem> command to install
+the files, instead of the homegrown installer. Native packages will be
+installed to I</usr/lib/$ARCH/rubygems-integration/$RUBY_VERSION>, while pure
+Ruby packages will be installed to I</usr/share/rubygems-integration/all>.
+
 =item B<--setuprb>
 
 This option indicates that the build should use I<setup.rb> rather
diff --git a/debian/changelog b/debian/changelog
index 61ef996..9e52022 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ gem2deb (0.23) UNRELEASED; urgency=medium
 
   * dh_ruby:
     - take parameters from the $DH_RUBY environment variable
+    - add experimental support for installing packages as gems.
 
  -- Antonio Terceiro <terceiro at debian.org>  Wed, 11 Nov 2015 14:50:13 -0200
 
diff --git a/lib/gem2deb/gem_installer.rb b/lib/gem2deb/gem_installer.rb
new file mode 100644
index 0000000..b72cc30
--- /dev/null
+++ b/lib/gem2deb/gem_installer.rb
@@ -0,0 +1,138 @@
+# Copyright © 2015, 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
+        ENV['make'] = 'make V=1'
+        gempkg = Dir.glob(File.join(tmpdir, '*.gem')).first
+        target_dir = rubygems_integration_target(rubyver)
+        gem(
+          ruby,
+          'install',
+          '--local',
+          '--verbose',
+          '--no-rdoc',
+          '--no-ri',
+          '--ignore-dependencies',
+          '--install-dir', File.join(destdir_base, target_dir),
+          gempkg
+        )
+
+        # Install binaries to /usr/bin
+        programs = Dir.glob(File.join(destdir_base, target_dir, 'bin/*'))
+        if !programs.empty?
+          bindir = File.join(destdir_base, 'usr/bin')
+          FileUtils::Verbose.mkdir_p bindir
+          programs.each do |prog|
+            FileUtils::Verbose.mv(prog, bindir)
+          end
+        end
+
+        %w[
+          bin
+          build_info
+          cache
+          doc
+        ].each do |dir|
+          final_dir = File.join(destdir_base, target_dir, dir)
+          FileUtils::Verbose.rm_rf(final_dir)
+        end
+
+        if !metadata.has_native_extensions?
+          ext_dir = File.join(destdir_base, target_dir, 'extensions')
+          FileUtils::Verbose.rmdir(ext_dir)
+        end
+
+        Dir.glob(File.join(destdir_base, 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
+
+    def install_gemspec
+      # noop; regular installation already installs a gemspec
+    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

-- 
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