|
#!/usr/bin/ruby -w
|
|
#
|
|
# Original gem2deb modified by Greg Sutcliffe <gsutclif@redhat.com> to
|
|
# include option to replace generated debian dir with a stored one
|
|
#
|
|
# Copyright © 2011, Lucas Nussbaum <lucas@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'
|
|
require 'gem2deb/gem2tgz'
|
|
require 'gem2deb/dh_make_ruby'
|
|
require 'optparse'
|
|
|
|
$only_tarball = false
|
|
$only_source_dir = false
|
|
$only_debian_source = false
|
|
$check_build_deps = true
|
|
$debian_subdir = nil
|
|
dh_make_ruby_options = {}
|
|
|
|
optparse = OptionParser.new do |opts|
|
|
opts.on('-h', '--help', 'show gem2deb help') do
|
|
puts opts
|
|
exit
|
|
end
|
|
|
|
opts.on('-v', '--version', 'show gem2deb version') do
|
|
puts "gem2deb version #{Gem2Deb::VERSION}"
|
|
exit
|
|
end
|
|
|
|
opts.on('-t', '--only-tarball', 'stop after creating the tar.gz archive') do
|
|
$only_tarball = true
|
|
end
|
|
|
|
opts.on('-s', '--only-source-dir', 'stop after preparing the Debian source package') do
|
|
$only_source_dir = true
|
|
end
|
|
|
|
opts.on('-S', '--only-debian-source', 'only build source package ; no binary packages') do
|
|
$only_debian_source = true
|
|
end
|
|
|
|
opts.on('-d', '--dont-check-builddeps', 'do not check build dependencies; used for testing') do
|
|
$check_build_deps = false
|
|
end
|
|
|
|
opts.on('-p', '--package PACKAGE', 'specify package name (default: ruby-*)') do |package_name|
|
|
dh_make_ruby_options[:source_package_name] = package_name
|
|
end
|
|
|
|
opts.on('', '--ruby-versions VERSIONS', 'ruby versions to use (default: all)') do |versions|
|
|
dh_make_ruby_options[:ruby_versions] = versions
|
|
end
|
|
|
|
opts.on('', '--debian-subdir DIRECTORY', 'replace autogenerated debian/ build directory with DIRECTORY') do |dir|
|
|
$debian_subdir = dir
|
|
end
|
|
|
|
end
|
|
optparse.parse!
|
|
|
|
if ARGV.length != 1
|
|
puts optparse
|
|
exit(1)
|
|
end
|
|
|
|
gemfile = ARGV[0]
|
|
# Download gem if not available locally
|
|
if not File::exists?(gemfile) and gemfile !~ /.gem$/
|
|
puts "#{gemfile} doesn't seem to exist. Let's try to download it with 'gem fetch #{ARGV[0]}'"
|
|
run("gem fetch #{gemfile}")
|
|
gemfile = Dir::glob("#{gemfile}-*.gem")[0]
|
|
end
|
|
|
|
puts "-- Creating source tarball from #{gemfile} ..."
|
|
tarball = Gem2Deb::Gem2Tgz.convert!(gemfile)
|
|
puts "-- Successfully created #{tarball}"
|
|
|
|
exit(0) if $only_tarball
|
|
|
|
puts
|
|
puts "-- Creating Debian source package from #{tarball} ..."
|
|
dmr = Gem2Deb::DhMakeRuby::new(tarball, dh_make_ruby_options)
|
|
dmr.build
|
|
puts "-- Generated Debian source tree in #{dmr.source_dirname}"
|
|
|
|
unless $debian_subdir.nil?
|
|
puts
|
|
puts "-- Replacing Debian subdir with custom package"
|
|
`rm -rf #{dmr.source_dirname}/debian`
|
|
`cp -r #{$debian_subdir} #{dmr.source_dirname}/debian`
|
|
puts "-- Debian subdir successfully replaced"
|
|
end
|
|
|
|
exit(0) if $only_source_dir
|
|
|
|
puts
|
|
puts "-- Building Debian package ..."
|
|
dmr.buildpackage($only_debian_source, $check_build_deps)
|
|
puts "-- Debian package successfully built!"
|
|
|
|
__END__
|
|
=head1 NAME
|
|
|
|
gem2deb - converts Rubygems' .gem file into Debian package
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
B<gem2deb> [I<OPTIONS>] I<GEMNAME> (to download the gem with I<gem fetch>)
|
|
|
|
B<gem2deb> [I<OPTIONS>] I<GEMFILE> (to use a local .gem file)
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
B<gem2deb> converts the gem into a Debian source package, and then will attempt
|
|
to build it. The process is made of several steps.
|
|
|
|
First, B<gem2deb> converts the gem file to a tar.gz archive containing a
|
|
metadata.yml file with the Gem specification. This is equivalent to what
|
|
B<gem2tgz> does.
|
|
|
|
Then, B<gem2deb> unpacks the tar.gz archive and prepares a Debian source
|
|
package, guess many of the defaults from the files included in the archive, or
|
|
the Gem specification. This is equivalent to what B<dh-make-ruby> does.
|
|
B<gem2deb> cannot determine all parameters for obvious reasons. It is recommended
|
|
to search for the "FIXME" string in the I<debian/> directory.
|
|
The generated Debian source package uses B<dh_ruby> to build the package.
|
|
|
|
Finally, B<gem2deb> tries to build the source and binary packages using
|
|
B<dpkg-buildpackage>.
|
|
|
|
=head1 OPTIONS
|
|
|
|
=over
|
|
|
|
=item B<-t>, B<--only-tarball>
|
|
|
|
Stop after creating the tar.gz archive.
|
|
|
|
=item B<-s>, B<--only-source-dir>
|
|
|
|
Stop after preparing the Debian source package directory (do not attempt to
|
|
build the package).
|
|
|
|
=item B<-S>, B<--only-debian-source>
|
|
|
|
Only build a Debian source package (do not build binary packages).
|
|
|
|
=item B<-p PACKAGE>, B<--package PACKAGE>
|
|
|
|
Specify package name (default: ruby-*).
|
|
Passed to dh-make-ruby. See B<dh-make-ruby(1)>.
|
|
|
|
=item B<--ruby-versions VERSIONS>
|
|
|
|
Ruby versions to build the package for (default: all).
|
|
Passed to dh-make-ruby. See B<dh-make-ruby(1)>.
|
|
|
|
=item B<-h>, B<--help>
|
|
|
|
Displays B<gem2deb> usage information.
|
|
|
|
=item B<-v>, B<--version>
|
|
|
|
Displays B<gem2deb> version information.
|
|
|
|
=back
|
|
|
|
=head1 HOW THE .GEM -> .TGZ CONVERSION WORKS
|
|
|
|
A gem named I<mygem-0.1.0.gem> is converted in a tarball with
|
|
(approximately) the following steps:
|
|
|
|
mkdir mygem-0.1.0
|
|
cd mygem-0.1.0
|
|
tar xfm /absolute/path/to/mygem-0.1.0.gem
|
|
tar xzfm data.tar.gz
|
|
zcat metadata.gz > metadata.yml
|
|
rm -f data.tar.gz metadata.gz
|
|
cd ..
|
|
tar czf mygem-0.1.0.tar.gz mygem-0.1.0
|
|
rm -rf mygem-0.1.0
|
|
|
|
The generated tarball has the following properties:
|
|
|
|
=over
|
|
|
|
=item Files
|
|
|
|
It contains all the files the gem contains.
|
|
|
|
=item Metadata
|
|
|
|
It contains the gem metadata ends up in a file named ``metadata.yml`` inside
|
|
the I<mygem-0.1.0> directory.
|
|
|
|
=back
|
|
|
|
=head1 SEE ALSO
|
|
|
|
L<B<dh_ruby>>(1)
|
|
|
|
=head1 COPYRIGHT AND AUTHORS
|
|
|
|
Copyright (c) 2011, Lucas Nussbaum <lucas@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/>.
|