[DRE-commits] [gem2deb] 01/04: gem install: replace whitelist with blacklist

Antonio Terceiro terceiro at moszumanska.debian.org
Tue Dec 6 14:45:55 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 dd25ca1716f7dc656bbd3f270ee6d27f0766bfd6
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Fri Dec 2 11:01:18 2016 -0200

    gem install: replace whitelist with blacklist
    
    Let's trust upstream maintainers, and just not install the things we for
    sure know are not needed: tests, licenses, READMEs, build
    infrastructure, etc.
    
    Maintainers can still whitelist stuff that are really needed by setting
    DH_RUBY_GEM_INSTALL_WHITELIST_APPEND.
---
 bin/dh_ruby                                        | 24 ++++++++++--
 lib/gem2deb/gem_installer.rb                       | 43 +++++++++++++++++-----
 test/sample/install_as_gem/README.md               |  1 +
 test/sample/install_as_gem/VERSION                 |  1 +
 .../sample/install_as_gem/{VERSION => bin/console} |  0
 test/sample/install_as_gem/{VERSION => bin/setup}  |  0
 .../{VERSION => tests/foobar/.gitkeep}             |  0
 test/sample/install_as_gem/whitelisted.md          |  1 +
 test/unit/gem_installer_test.rb                    | 15 ++++++++
 9 files changed, 73 insertions(+), 12 deletions(-)

diff --git a/bin/dh_ruby b/bin/dh_ruby
index 847416e..bdbc0da 100755
--- a/bin/dh_ruby
+++ b/bin/dh_ruby
@@ -239,7 +239,8 @@ Ruby packages will be installed to I</usr/share/rubygems-integration/all>.
 There is an internal whitelist of directories from the source package that need
 to be installed, but we can't possibly know all possibilities: if a package
 needs to install a directory that is not automatically installed, use
-I<DH_RUBY_GEM_INSTALL_WHITELIST_APPEND>.
+I<DH_RUBY_GEM_INSTALL_WHITELIST_APPEND>. If you want to exclude a directory
+from  being installed, use I<DH_RUBY_GEM_INSTALL_BLACKLIST_APPEND>.
 
 =item B<--setuprb>
 
@@ -297,8 +298,25 @@ will I<need> to use DH_RUBY_GEMSPEC to instruct dh_ruby about which one to use.
 
 =item I<DH_RUBY_GEM_INSTALL_WHITELIST_APPEND>.
 
-When using --gem-install, this variable adds files and directories to the list
-of files that need to be installed.
+When using --gem-install, this variable adds B<files> to the list of files that
+need to be installed. Entries must be separated by spaces, and can be either
+exact filenames, of glob expressions (e.g. I<*.txt>, I<foo/*>).
+
+Directories cannot be added directly, only files. If you want to include an
+entire directory, say I<foo>, use a glob expression like I<foo/*>.
+
+Note that by default all top-level files are automatically blacklisted, except
+I<VERSION*> which is used by some packages. If you need a top-level file to be
+installed, you need to whitelist it.
+
+=item I<DH_RUBY_GEM_INSTALL_BLACKLIST_APPEND>.
+
+When using --gem-install, this variable adds files to the list of files that
+SHOULD NOT be installed. Entries must be separated by spaces, and must be
+either specific filenames, or glob expressions (e.g. I<*.txt>).
+
+Directories cannot be blacklisted directly. To blacklist an entire directory,
+use a glob expression such as I<foo/*>.
 
 =back
 
diff --git a/lib/gem2deb/gem_installer.rb b/lib/gem2deb/gem_installer.rb
index 74229ed..6e91f44 100644
--- a/lib/gem2deb/gem_installer.rb
+++ b/lib/gem2deb/gem_installer.rb
@@ -21,17 +21,29 @@ module Gem2Deb
 
   class GemInstaller < Installer
 
+    INSTALL_BLACKLIST = %w[
+      bin/console
+      bin/setup
+      debian/*
+      features/*
+      gemfiles/*
+      spec/*
+      test/*
+      tests/*
+    ] + ENV.fetch('DH_RUBY_GEM_INSTALL_BLACKLIST_APPEND', '').split
+
     INSTALL_WHITELIST = %w[
-      ext
-      lib
-      app
-      assets
-      vendor
-      templates
-      VERSION
-      VERSION.txt
+      VERSION*
     ] + ENV.fetch('DH_RUBY_GEM_INSTALL_WHITELIST_APPEND', '').split
 
+    def whitelist
+      INSTALL_WHITELIST
+    end
+
+    def blacklist
+      INSTALL_BLACKLIST
+    end
+
     def install_files_and_build_extensions
       done = false
 
@@ -50,7 +62,20 @@ module Gem2Deb
 
         # remove unwanted files and directories
         gemspec_data.files.reject! do |entry|
-          !INSTALL_WHITELIST.include?(entry.split('/').first)
+          if whitelist.any? { |incl| File.fnmatch(incl, entry) }
+            false # whitelisted, don't reject
+          else
+            if !entry.index('/')
+              true # exclude all top-level files by default
+            else
+              # reject if blacklisted
+              blacklist.any? { |exclude| File.fnmatch(exclude, entry) }
+            end
+          end
+        end
+
+        gemspec_data.executables.reject! do |prog|
+          ['console', 'setup'].include?(prog)
         end
 
         # write modified gemspec at temporary directory
diff --git a/test/sample/install_as_gem/README.md b/test/sample/install_as_gem/README.md
new file mode 100644
index 0000000..51cb127
--- /dev/null
+++ b/test/sample/install_as_gem/README.md
@@ -0,0 +1 @@
+SHOULD NOT BE INSTALLED
diff --git a/test/sample/install_as_gem/VERSION b/test/sample/install_as_gem/VERSION
index e69de29..8acdd82 100644
--- a/test/sample/install_as_gem/VERSION
+++ b/test/sample/install_as_gem/VERSION
@@ -0,0 +1 @@
+0.0.1
diff --git a/test/sample/install_as_gem/VERSION b/test/sample/install_as_gem/bin/console
similarity index 100%
copy from test/sample/install_as_gem/VERSION
copy to test/sample/install_as_gem/bin/console
diff --git a/test/sample/install_as_gem/VERSION b/test/sample/install_as_gem/bin/setup
similarity index 100%
copy from test/sample/install_as_gem/VERSION
copy to test/sample/install_as_gem/bin/setup
diff --git a/test/sample/install_as_gem/VERSION b/test/sample/install_as_gem/tests/foobar/.gitkeep
similarity index 100%
copy from test/sample/install_as_gem/VERSION
copy to test/sample/install_as_gem/tests/foobar/.gitkeep
diff --git a/test/sample/install_as_gem/whitelisted.md b/test/sample/install_as_gem/whitelisted.md
new file mode 100644
index 0000000..e6ab894
--- /dev/null
+++ b/test/sample/install_as_gem/whitelisted.md
@@ -0,0 +1 @@
+SHOULD BE INSTALLED
diff --git a/test/unit/gem_installer_test.rb b/test/unit/gem_installer_test.rb
index d211b0d..55f4364 100644
--- a/test/unit/gem_installer_test.rb
+++ b/test/unit/gem_installer_test.rb
@@ -9,6 +9,9 @@ class GemInstallerTest < Gem2DebTestCase
   one_time_setup do
     gem_installer = Gem2Deb::GemInstaller.new('ruby-install-as-gem', PKGDIR)
     gem_installer.destdir_base = INSTALLDIR
+
+    orig_whitelist = gem_installer.whitelist
+    gem_installer.stubs(:whitelist).returns(orig_whitelist + ['whitelisted.md'])
     silently { gem_installer.install_files_and_build_extensions }
   end
 
@@ -28,17 +31,29 @@ class GemInstallerTest < Gem2DebTestCase
     LICENSE.TXT
     MIT-LICENSE
     Rakefile
+    README.md
+    bin/setup
+    bin/console
 
     debian
     ext
     spec
     test
+    tests
   ].each do |f|
     should "not install #{f}" do
       assert_no_file_exists installed_path(f)
     end
   end
 
+  should 'install VERSION' do
+    assert_file_exists installed_path("VERSION")
+  end
+
+  should 'install whitelisted file' do
+    assert_file_exists installed_path("whitelisted.md")
+  end
+
   should 'install native extension' do
     so = Dir.glob(INSTALLDIR + '/usr/lib/**/install_as_gem/install_as_gem_native.so')
     assert_equal Gem2Deb::SUPPORTED_RUBY_VERSIONS.keys.size, so.size, "#{so.inspect} expected to have size 1"

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