[DRE-commits] [gem2deb] 08/15: dh_ruby --gem-install: Only install files that match a whitelist
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 5e9b077b1a1666893d1d0dbafe2055058430095f
Author: Antonio Terceiro <terceiro at debian.org>
Date: Sat Jan 23 13:09:08 2016 -0200
dh_ruby --gem-install: Only install files that match a whitelist
---
debian/changelog | 4 +++
lib/gem2deb/gem_installer.rb | 34 ++++++++++++----------
test/sample/install_as_gem/CHANGELOG | 0
test/sample/install_as_gem/Gemfile | 0
test/sample/install_as_gem/LICENSE.TXT | 0
test/sample/install_as_gem/MIT-LICENSE | 0
test/sample/install_as_gem/Rakefile | 0
test/sample/install_as_gem/VERSION | 0
test/sample/install_as_gem/spec/.gitkeep | 0
.../install_as_gem/spec/install_as_gem_spec.rb | 0
test/sample/install_as_gem/test/.gitkeep | 0
.../install_as_gem/test/install_as_gem_test.rb | 0
test/unit/gem_installer_test.rb | 18 ++++++++++--
13 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 67b987d..2d56a1f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,10 @@ gem2deb (0.25) UNRELEASED; urgency=medium
when creating new packaging from scratch anymorel.
* gem2deb-test-runner: also set GEM_PATH when running tests. This makes
tests work out of the box when using --gem-install
+ * dh_ruby --gem-install:
+ - Only install files that match a whitelist, to avoid having all the
+ clutter that usually comes in source packages installed to binary
+ packages.
-- 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 cf5c9bd..e894534 100644
--- a/lib/gem2deb/gem_installer.rb
+++ b/lib/gem2deb/gem_installer.rb
@@ -21,6 +21,16 @@ module Gem2Deb
class GemInstaller < Installer
+ INSTALL_WHITELIST = %w[
+ lib
+ app
+ assets
+ vendor
+ templates
+ VERSION
+ VERSION.txt
+ ]
+
def install_files_and_build_extensions
done = false
@@ -32,10 +42,15 @@ module Gem2Deb
ruby = SUPPORTED_RUBY_VERSIONS[rubyver]
tmpdir = Dir.mktmpdir
- # generate gemspec at temporary directory
- gemspec_data = gemspec_data!
- gemspec = File.join(tmpdir, 'gemspec')
+ gemspec_data = load_gemspec_data!
+
+ # remove unwanted files and directories
+ gemspec_data.files.reject! do |entry|
+ !INSTALL_WHITELIST.include?(entry.split('/').first)
+ end
+ # write modified gemspec at temporary directory
+ gemspec = File.join(tmpdir, 'gemspec')
File.open(gemspec, 'w') do |f|
f.write(gemspec_data.to_ruby)
end
@@ -93,17 +108,6 @@ module Gem2Deb
end
end
- # remove debian/ directory that could be installed if gemspec specifies
- # Dir['**/*'] or something equivalent
- debian_dir = File.join(
- destdir_base,
- target_dir,
- 'gems',
- [metadata.name, metadata.version].join('-'),
- 'debian'
- )
- FileUtils.rm_rf(debian_dir)
-
# remove tmpdir
FileUtils.rm_f(tmpdir)
@@ -137,7 +141,7 @@ module Gem2Deb
run(ruby, '-S', 'gem', command, '--config-file', '/dev/null', '--verbose', *args)
end
- def gemspec_data!
+ def load_gemspec_data!
if metadata.gemspec
metadata.gemspec
else
diff --git a/test/sample/install_as_gem/CHANGELOG b/test/sample/install_as_gem/CHANGELOG
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/Gemfile b/test/sample/install_as_gem/Gemfile
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/LICENSE.TXT b/test/sample/install_as_gem/LICENSE.TXT
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/MIT-LICENSE b/test/sample/install_as_gem/MIT-LICENSE
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/Rakefile b/test/sample/install_as_gem/Rakefile
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/VERSION b/test/sample/install_as_gem/VERSION
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/spec/.gitkeep b/test/sample/install_as_gem/spec/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/spec/install_as_gem_spec.rb b/test/sample/install_as_gem/spec/install_as_gem_spec.rb
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/test/.gitkeep b/test/sample/install_as_gem/test/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/test/sample/install_as_gem/test/install_as_gem_test.rb b/test/sample/install_as_gem/test/install_as_gem_test.rb
new file mode 100644
index 0000000..e69de29
diff --git a/test/unit/gem_installer_test.rb b/test/unit/gem_installer_test.rb
index 7a5475c..ea86301 100644
--- a/test/unit/gem_installer_test.rb
+++ b/test/unit/gem_installer_test.rb
@@ -20,8 +20,22 @@ class GemInstallerTest < Gem2DebTestCase
assert_file_exists INSTALLDIR + '/usr/bin/install_as_gem'
end
- should 'not install debian/ directory' do
- assert_no_file_exists installed_path('debian')
+ # unwanted files (first block) and directories (second block)
+ %w[
+ CHANGELOG
+ Gemfile
+ install_as_gem.gemspec
+ LICENSE.TXT
+ MIT-LICENSE
+ Rakefile
+
+ debian
+ spec
+ test
+ ].each do |f|
+ should "not install #{f}" do
+ assert_no_file_exists installed_path(f)
+ end
end
private
--
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