[DRE-commits] [gem2deb] 10/15: gem installed: implement correct installation of native extensions
Antonio Terceiro
terceiro at moszumanska.debian.org
Sat Jan 23 19:37:36 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to branch master
in repository gem2deb.
commit 61119cafec279601fb3db96fa466184acea11acd
Author: Antonio Terceiro <terceiro at debian.org>
Date: Sat Jan 23 16:39:58 2016 -0200
gem installed: implement correct installation of native extensions
---
debian/changelog | 1 +
lib/gem2deb/gem_installer.rb | 36 +++++++++++++++--------
lib/gem2deb/test_runner.rb | 2 +-
test/integration/gem2deb_test.rb | 8 +++++
test/sample/install_as_gem/debian/control | 2 +-
test/sample/install_as_gem/debian/ruby-tests.rb | 3 ++
test/sample/install_as_gem/ext/extconf.rb | 3 ++
test/sample/install_as_gem/ext/install_as_gem.c | 6 ++++
test/sample/install_as_gem/install_as_gem.gemspec | 1 +
test/unit/gem_installer_test.rb | 12 +++++++-
10 files changed, 59 insertions(+), 15 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 2d56a1f..f7eb51d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -11,6 +11,7 @@ gem2deb (0.25) UNRELEASED; urgency=medium
- Only install files that match a whitelist, to avoid having all the
clutter that usually comes in source packages installed to binary
packages.
+ - Implement correct installation of native extensions
-- Antonio Terceiro <terceiro at debian.org> Sat, 09 Jan 2016 21:00:29 -0200
diff --git a/lib/gem2deb/gem_installer.rb b/lib/gem2deb/gem_installer.rb
index e894534..e770032 100644
--- a/lib/gem2deb/gem_installer.rb
+++ b/lib/gem2deb/gem_installer.rb
@@ -22,6 +22,7 @@ module Gem2Deb
class GemInstaller < Installer
INSTALL_WHITELIST = %w[
+ ext
lib
app
assets
@@ -87,24 +88,35 @@ module Gem2Deb
end
end
- %w[
+
+ FileUtils::Verbose.cd(File.join(destdir_base, target_dir)) do
+ %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
+ ].each do |dir|
+ FileUtils::Verbose.rm_rf(dir)
+ end
- if !metadata.has_native_extensions?
- ext_dir = File.join(destdir_base, target_dir, 'extensions')
- FileUtils::Verbose.rmdir(ext_dir)
- end
+ if metadata.has_native_extensions?
+ run 'find', 'extensions', '-name', 'gem_make.out', '-delete'
+ else
+ FileUtils::Verbose.rm_rf('extensions')
+ end
+
+ FileUtils::Verbose.cd(File.join('gems', "#{metadata.name}-#{metadata.version}")) do
+ # remove source of compiled extensions
+ gemspec_data.extensions.each do |ext|
+ FileUtils::Verbose.rm_rf(File.dirname(ext))
+ end
+
+ # remove duplicated *.so files from lib; they are already installed
+ # to extensions/ in the top level
+ FileUtils::Verbose.rm_f Dir.glob('lib/**/*.so')
- Dir.glob(File.join(destdir_base, target_dir, '**/Makefile')).each do |makefile|
- Dir.chdir(File.dirname(makefile)) do
- run('make distclean || make clean')
+ # remove empty directories inside lib/
+ run 'find', 'lib/', '-type', 'd', '-empty', '-delete'
end
end
diff --git a/lib/gem2deb/test_runner.rb b/lib/gem2deb/test_runner.rb
index 1cae0cb..9bcafd0 100644
--- a/lib/gem2deb/test_runner.rb
+++ b/lib/gem2deb/test_runner.rb
@@ -57,7 +57,7 @@ module Gem2Deb
if self.autopkgtest
nil
else
- (Gem.path + Dir.glob("debian/*/usr/share/rubygems-integration/{all,#{ruby_api_version}}")).join(':')
+ (Gem.path + Dir.glob("debian/*/usr/**/rubygems-integration/{all,#{ruby_api_version}}")).join(':')
end
end
diff --git a/test/integration/gem2deb_test.rb b/test/integration/gem2deb_test.rb
index afc605a..cd93382 100644
--- a/test/integration/gem2deb_test.rb
+++ b/test/integration/gem2deb_test.rb
@@ -88,4 +88,12 @@ class Gem2DebTest < Gem2DebTestCase
end
end
+ self.build_tree('test/sample/install_as_gem') do |dir|
+ context 'using --gem-install' do
+ should 'install' do
+ assert Dir.glob("#{dir}/debian/*/**/*.so").size > 0 , '.so file is installed'
+ end
+ end
+ end
+
end
diff --git a/test/sample/install_as_gem/debian/control b/test/sample/install_as_gem/debian/control
index 8d7d660..98f92c1 100644
--- a/test/sample/install_as_gem/debian/control
+++ b/test/sample/install_as_gem/debian/control
@@ -13,7 +13,7 @@ Testsuite: autopkgtest-pkg-ruby
XS-Ruby-Versions: all
Package: ruby-install-as-gem
-Architecture: all
+Architecture: any
XB-Ruby-Versions: ${ruby:Versions}
Depends: ruby | ruby-interpreter,
${misc:Depends},
diff --git a/test/sample/install_as_gem/debian/ruby-tests.rb b/test/sample/install_as_gem/debian/ruby-tests.rb
new file mode 100644
index 0000000..deaf38f
--- /dev/null
+++ b/test/sample/install_as_gem/debian/ruby-tests.rb
@@ -0,0 +1,3 @@
+require 'install_as_gem'
+require 'install_as_gem/install_as_gem_native'
+puts $LOADED_FEATURES.select { |f| f =~ /install_as_gem/ }
diff --git a/test/sample/install_as_gem/ext/extconf.rb b/test/sample/install_as_gem/ext/extconf.rb
new file mode 100644
index 0000000..ee2c041
--- /dev/null
+++ b/test/sample/install_as_gem/ext/extconf.rb
@@ -0,0 +1,3 @@
+require 'mkmf'
+
+create_makefile('install_as_gem/install_as_gem_native')
diff --git a/test/sample/install_as_gem/ext/install_as_gem.c b/test/sample/install_as_gem/ext/install_as_gem.c
new file mode 100644
index 0000000..e729a71
--- /dev/null
+++ b/test/sample/install_as_gem/ext/install_as_gem.c
@@ -0,0 +1,6 @@
+#include "ruby.h"
+
+void
+Init_install_as_gem_native () {
+ rb_define_module ("InstallAsGemNative");
+}
diff --git a/test/sample/install_as_gem/install_as_gem.gemspec b/test/sample/install_as_gem/install_as_gem.gemspec
index 6fa651d..fd56979 100644
--- a/test/sample/install_as_gem/install_as_gem.gemspec
+++ b/test/sample/install_as_gem/install_as_gem.gemspec
@@ -13,4 +13,5 @@ Gem::Specification.new do |s|
s.files = Dir['**/*']
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
+ s.extensions = 'ext/extconf.rb'
end
diff --git a/test/unit/gem_installer_test.rb b/test/unit/gem_installer_test.rb
index ea86301..a90aa56 100644
--- a/test/unit/gem_installer_test.rb
+++ b/test/unit/gem_installer_test.rb
@@ -30,6 +30,7 @@ class GemInstallerTest < Gem2DebTestCase
Rakefile
debian
+ ext
spec
test
].each do |f|
@@ -38,10 +39,19 @@ class GemInstallerTest < Gem2DebTestCase
end
end
+ should 'install native extension' do
+ so = Dir.glob(INSTALLDIR + '/usr/lib/**/install_as_gem/install_as_gem_native.so')
+ assert_equal 1, so.size, "#{so.inspect} expected to have size 1"
+ end
+
private
def installed_path(file)
- INSTALLDIR + '/usr/share/rubygems-integration/all/gems/install_as_gem-0.0.1/' + file
+ File.join(gem_install_dir, file)
+ end
+
+ def gem_install_dir
+ Dir.glob(INSTALLDIR + '/usr/lib/*/rubygems-integration/*/gems/install_as_gem-0.0.1').first
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