[DRE-commits] [gem2deb] 04/05: dh-make-ruby: map gems to packages with apt-file
Antonio Terceiro
terceiro at moszumanska.debian.org
Sat Feb 21 22:33:49 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 a746035005334a8fdbefbdfa402b8c56fcd7185e
Author: Antonio Terceiro <terceiro at debian.org>
Date: Sat Feb 21 20:30:26 2015 -0200
dh-make-ruby: map gems to packages with apt-file
---
debian/changelog | 2 ++
lib/gem2deb/dh_make_ruby.rb | 46 ++++++++++++++++++++++++++++++++++++++-------
2 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 09bda51..f188fb9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,8 @@ gem2deb (0.12) UNRELEASED; urgency=medium
* dh_ruby: if debian/dh_ruby.{mk,rake} exists, call {make,rake} on it during
the build. See docs in dh_ruby(1)
+ * dh-make-ruby: use a cache based on the output of apt-file to map gem names
+ to Debian package names when generating dependencies.
-- Antonio Terceiro <terceiro at debian.org> Sat, 21 Feb 2015 18:38:18 -0200
diff --git a/lib/gem2deb/dh_make_ruby.rb b/lib/gem2deb/dh_make_ruby.rb
index e220c5c..c5cae0c 100644
--- a/lib/gem2deb/dh_make_ruby.rb
+++ b/lib/gem2deb/dh_make_ruby.rb
@@ -61,6 +61,8 @@ module Gem2Deb
attr_accessor :extra_build_dependencies
def initialize(input, options = {})
+ generate_or_update_gem_to_package_data
+
initialize_from_options(options)
if File.directory?(input)
initialize_from_directory(input)
@@ -104,16 +106,46 @@ module Gem2Deb
end
end
- GEM_TO_PACKAGE = {
- 'rake' => 'rake',
- 'rails' => 'rails',
- }
-
def gem_name_to_source_package_name(gem_name)
- map = GEM_TO_PACKAGE
- map[gem_name] || 'ruby-' + gem_name.gsub(/^ruby[-_]|[-_]ruby$/, '')
+ @gem_to_package[gem_name] || 'ruby-' + gem_name.gsub(/^ruby[-_]|[-_]ruby$/, '')
end
+ def generate_or_update_gem_to_package_data
+ if Gem2Deb.testing
+ @gem_to_package = { 'rake' => 'rake', 'rails' => 'rails' }
+ return
+ end
+
+ if !File.exists?('/usr/bin/apt-file')
+ puts "E: apt-file not found. Please install the package apt-file"
+ exit 1
+ end
+
+ cache_dir = File.join(ENV['HOME'], '.cache', 'gem2deb')
+ FileUtils.mkdir_p(cache_dir)
+ cache = File.join(cache_dir, 'gem_to_packages.yaml')
+
+ if File.exists?(cache)
+ stat = File.stat(cache)
+ update = (Time.now.to_i - stat.mtime.to_i) > (60*60*24) # keep cache for 24h
+ else
+ update = true
+ end
+
+ if update
+ if system('apt-file search /usr/share/rubygems-integration/ > ' + cache + '.new')
+ system('sed', '-i', '-e', 's#/.*/##; s/-[0-9.]\+.gemspec//', cache + '.new')
+ FileUtils.mv(cache + '.new', cache)
+ else
+ puts 'E: dh-make-ruby needs an up-to-date apt-file cache in order to map gem names to package names'
+ exit $?.exitstatus
+ end
+ end
+
+ @gem_to_package = YAML.load_file(cache).invert
+ end
+
+
def gem_dirname
[gem_name, gem_version].join('-')
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