gem2rpm 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +11 -0
- data/LICENSE +16 -0
- data/README +88 -0
- data/bin/gem2rpm +107 -0
- data/lib/gem2rpm.rb +147 -0
- data/rubygem-gem2rpm.spec +55 -0
- metadata +53 -0
data/AUTHORS
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem2Spec - Convert a ruby gem to a RPM spec file.
|
2
|
+
Copyright (C) 2005 David Lutterkort
|
3
|
+
|
4
|
+
This program and entire repository is free software; you can
|
5
|
+
redistribute it and/or modify it under the terms of the GNU
|
6
|
+
General Public License as published by the Free Software
|
7
|
+
Foundation; either version 2 of the License, or any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program; if not, write to the Free Software
|
16
|
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
data/README
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
This package is a first attempt at converting ruby gems to rpm's. Because
|
2
|
+
of the differences between the two packaging schemes, it is impossible to
|
3
|
+
come up with a completely automated way of doing the conversion, but the
|
4
|
+
spec files produced by this package should be good enough for most
|
5
|
+
pure-ruby gems. I wouldn't put too much hope into automating the gem->rpm
|
6
|
+
process for gems with binary code such as database drivers. But even for
|
7
|
+
those, gem2rpm provides a good starting point for the packaging gems as
|
8
|
+
RPM's.
|
9
|
+
|
10
|
+
Installation
|
11
|
+
============
|
12
|
+
|
13
|
+
Download the ruby gem or an RPM (TODO: more detail)
|
14
|
+
|
15
|
+
Usage
|
16
|
+
=====
|
17
|
+
|
18
|
+
Run 'gem2rpm --help' for options
|
19
|
+
|
20
|
+
At its simplest, download a gem (let's call that file GEM) and run
|
21
|
+
gem2rpm $GEM
|
22
|
+
|
23
|
+
This will print an rpm spec file based on the information contained in the
|
24
|
+
gem's spec file. In general, it is necessary to edit the generated spec
|
25
|
+
file because the gem is missing some important information that is
|
26
|
+
customarily provided in rpm's, most notably the license and the changelog.
|
27
|
+
|
28
|
+
Rather than editing the generated specfile, edit the template from which
|
29
|
+
the specfile is generated. This will make it easier to update the RPM when
|
30
|
+
a new version of the Gem becomes available.
|
31
|
+
|
32
|
+
To support this process, it is recommended to first save the default
|
33
|
+
template somewhere:
|
34
|
+
gem2rpm -T > rubygem-GEM.spec.template
|
35
|
+
|
36
|
+
Now, edit the template and then run gem2rpm to generate the spec file
|
37
|
+
using the edited template:
|
38
|
+
gem2rpm -t rubygem-GEM.spec.template > rubygem-GEM.spec
|
39
|
+
|
40
|
+
With that, you can now build your RPM as ususal. When a new version of the
|
41
|
+
gem becomes available, you should edit the saved template and rerun
|
42
|
+
gem2rpm over it.
|
43
|
+
|
44
|
+
Template Details
|
45
|
+
================
|
46
|
+
|
47
|
+
The template is a standard erb file; there are three main variables
|
48
|
+
available in the template file:
|
49
|
+
|
50
|
+
format - The Gem::Format for the gem
|
51
|
+
spec - The Gem::Specification for the gem (the same as format.spec)
|
52
|
+
|
53
|
+
Conventions
|
54
|
+
===========
|
55
|
+
|
56
|
+
A typical source RPM for a gem should consist of three files: the gem file
|
57
|
+
itself, the template for the spec file and the spec file. To ensure that
|
58
|
+
the template will be included in the source RPM, it must be listed as one
|
59
|
+
of the sources in the spec file.
|
60
|
+
|
61
|
+
The resulting rpms should follow the naming convention 'rubygem-$GEM'
|
62
|
+
where GEM is the name of the packaged gem. The default template also makes
|
63
|
+
sure that the resulting package provides 'ruby($GEM)', according to general
|
64
|
+
packaging conventions for scripting languages.
|
65
|
+
|
66
|
+
Gem Limitiations
|
67
|
+
================
|
68
|
+
|
69
|
+
Gem has some important limitations that make it next to impossible to
|
70
|
+
fully automate the gem -> rpm conversion process. Amongst them are
|
71
|
+
|
72
|
+
- No license field
|
73
|
+
- No changelog
|
74
|
+
- No distinction between build and install time (important for gems with
|
75
|
+
binary components)
|
76
|
+
- Because of its nature as a separate packaging system, gems can not
|
77
|
+
capture dependencies on non-gem system components, e.g., the ruby
|
78
|
+
PostgreSQL driver can not properly describe its build- and
|
79
|
+
runtime-dependencies on the various pieces of the PostgreSQL database
|
80
|
+
|
81
|
+
See also
|
82
|
+
========
|
83
|
+
|
84
|
+
Fedora ruby and rubygem packaging guidelines:
|
85
|
+
http://fedoraproject.org/wiki/Packaging/Ruby
|
86
|
+
|
87
|
+
Project website
|
88
|
+
http://rubyforge.org/projects/gem2rpm/
|
data/bin/gem2rpm
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
$:.push(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
5
|
+
|
6
|
+
require 'gem2rpm'
|
7
|
+
require 'optparse'
|
8
|
+
require 'rubygems/format'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
opts = OptionParser.new("#{$0} [OPTIONS] GEMFILE")
|
12
|
+
opts.separator(" Convert ruby Gems to source RPMs and specfiles")
|
13
|
+
opts.separator(" Uses a template to generate the RPM specfile")
|
14
|
+
opts.separator(" from the Gem spec")
|
15
|
+
|
16
|
+
template_file = nil
|
17
|
+
output_file = nil
|
18
|
+
srpm = false
|
19
|
+
deps = false
|
20
|
+
nongem = false
|
21
|
+
|
22
|
+
opts.on("-T", "--default-template", "Print the default template") do |val|
|
23
|
+
puts Gem2Rpm::TEMPLATE
|
24
|
+
exit 0
|
25
|
+
end
|
26
|
+
opts.on("-t", "--template TEMPLATE", "Use TEMPLATE for the specfile") do |val|
|
27
|
+
template_file = val
|
28
|
+
end
|
29
|
+
opts.on("-v", "--version", "Print gem2rpm's version and exit") do
|
30
|
+
puts Gem2Rpm::VERSION
|
31
|
+
exit 0
|
32
|
+
end
|
33
|
+
opts.on("-o", "--output FILE", "Send the specfile to FILE") do |val|
|
34
|
+
output_file = val
|
35
|
+
end
|
36
|
+
opts.on("-s", "--srpm", "Create a source RPM") do |val|
|
37
|
+
srpm = true
|
38
|
+
end
|
39
|
+
opts.on("-d", "--dependencies", "Print the dependencies of the gem") do |val|
|
40
|
+
deps = true
|
41
|
+
end
|
42
|
+
opts.on("-n", "--nongem", "Generate a subpackage for non-gem use") do |val|
|
43
|
+
nongem = true
|
44
|
+
end
|
45
|
+
rest = opts.permute(ARGV)
|
46
|
+
|
47
|
+
if rest.size != 1
|
48
|
+
$stderr.puts "Missing GEMFILE"
|
49
|
+
$stderr.puts opts
|
50
|
+
exit(1)
|
51
|
+
end
|
52
|
+
gemfile = rest[0]
|
53
|
+
|
54
|
+
template = nil
|
55
|
+
if template_file.nil?
|
56
|
+
template = Gem2Rpm::TEMPLATE
|
57
|
+
else
|
58
|
+
begin
|
59
|
+
f = open(template_file, "r")
|
60
|
+
rescue Errno::ENOENT
|
61
|
+
$stderr.puts "Could not open template #{template_file}. Aborting"
|
62
|
+
exit(1)
|
63
|
+
end
|
64
|
+
template = f.read
|
65
|
+
f.close
|
66
|
+
end
|
67
|
+
|
68
|
+
srpmdir = nil
|
69
|
+
gemname = nil
|
70
|
+
srpmdir = nil
|
71
|
+
specfile = nil
|
72
|
+
if srpm
|
73
|
+
gemname = Gem::Format.from_file_by_path(gemfile).spec.name
|
74
|
+
srpmdir = `/bin/mktemp -t -d gem2rpm-#{gemname}.XXXXXX`.chomp
|
75
|
+
specfile = File::join(srpmdir, "rubygem-#{gemname}.spec")
|
76
|
+
if output_file.nil?
|
77
|
+
output_file = specfile
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Produce a specfile
|
82
|
+
if output_file.nil?
|
83
|
+
Gem2Rpm::convert(gemfile, template, $stdout, nongem) unless deps
|
84
|
+
else
|
85
|
+
begin
|
86
|
+
out = open(output_file, "w")
|
87
|
+
Gem2Rpm::convert(gemfile, template, out, nongem)
|
88
|
+
ensure
|
89
|
+
out.close()
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Create a source RPM
|
94
|
+
if srpm
|
95
|
+
unless File::exist?(specfile)
|
96
|
+
FileUtils::copy(output_file, specfile)
|
97
|
+
end
|
98
|
+
FileUtils::copy(gemfile, srpmdir)
|
99
|
+
|
100
|
+
system("rpmbuild -bs --nodeps --define '_sourcedir #{srpmdir}' --define '_srcrpmdir #{Dir::pwd}' #{specfile}")
|
101
|
+
end
|
102
|
+
|
103
|
+
if deps
|
104
|
+
Gem::Format.from_file_by_path(gemfile).spec.dependencies.each do |dep|
|
105
|
+
puts "rubygem(#{dep.name}) #{dep.version_requirements.to_rpm}"
|
106
|
+
end
|
107
|
+
end
|
data/lib/gem2rpm.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'socket'
|
3
|
+
require 'rubygems/format'
|
4
|
+
require 'rubygems/remote_installer'
|
5
|
+
|
6
|
+
# Extend String with a word_wrap method, which we use in the ERB template
|
7
|
+
# below. Taken with modification from the word_wrap method in ActionPack.
|
8
|
+
# Text::Format does the smae thing better.
|
9
|
+
class String
|
10
|
+
def word_wrap(line_width = 80)
|
11
|
+
gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Gem
|
16
|
+
class Requirement
|
17
|
+
def to_rpm
|
18
|
+
result = to_s
|
19
|
+
if result == "> 0.0.0"
|
20
|
+
return ""
|
21
|
+
else
|
22
|
+
return result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module Gem2Rpm
|
29
|
+
Gem2Rpm::VERSION = "0.5.0"
|
30
|
+
|
31
|
+
def Gem2Rpm.convert(fname, template=TEMPLATE, out=$stdout, nongem=true)
|
32
|
+
format = Gem::Format.from_file_by_path(fname)
|
33
|
+
spec = format.spec
|
34
|
+
spec.description ||= spec.summary
|
35
|
+
dummy, download_path = Gem::RemoteInstaller.new.find_gem_to_install(spec.name, "=#{spec.version}")
|
36
|
+
download_path += "/gems/" if download_path.to_s != ""
|
37
|
+
template = ERB.new(template, 0, '<>')
|
38
|
+
out.puts template.result(binding)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the email address of the packager (i.e., the person running
|
42
|
+
# gem2spec). Taken from RPM macros if present, constructed from system
|
43
|
+
# username and hostname otherwise.
|
44
|
+
def Gem2Rpm.packager()
|
45
|
+
packager = `rpm --eval '%{packager}'`.chomp
|
46
|
+
if packager == '' or packager == '%{packager}'
|
47
|
+
packager = "#{Etc::getpwnam(Etc::getlogin).gecos} <#{Etc::getlogin}@#{Socket::gethostname}>"
|
48
|
+
end
|
49
|
+
packager
|
50
|
+
end
|
51
|
+
|
52
|
+
TEMPLATE =
|
53
|
+
%q{# Generated from <%= File::basename(format.gem_path) %> by gem2rpm -*- rpm-spec -*-
|
54
|
+
%define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
|
55
|
+
%define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
|
56
|
+
%define gemname <%= spec.name %>
|
57
|
+
%define geminstdir %{gemdir}/gems/%{gemname}-%{version}
|
58
|
+
|
59
|
+
Summary: <%= spec.summary.gsub(/\.$/, "") %>
|
60
|
+
Name: rubygem-%{gemname}
|
61
|
+
|
62
|
+
Version: <%= spec.version %>
|
63
|
+
Release: 1%{?dist}
|
64
|
+
Group: Development/Languages
|
65
|
+
License: Ruby License/GPL
|
66
|
+
URL: <%= spec.homepage %>
|
67
|
+
Source0: <%= download_path %>%{gemname}-%{version}.gem
|
68
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(%{__id_u} -n)
|
69
|
+
Requires: rubygems
|
70
|
+
<% for d in spec.dependencies %>
|
71
|
+
Requires: rubygem(<%= d.name %>) <%= d.version_requirements.to_rpm %>
|
72
|
+
<% end %>
|
73
|
+
BuildRequires: rubygems
|
74
|
+
<% if spec.extensions.empty? %>
|
75
|
+
BuildArch: noarch
|
76
|
+
<% end %>
|
77
|
+
Provides: rubygem(%{gemname}) = %{version}
|
78
|
+
|
79
|
+
%description
|
80
|
+
<%= spec.description.to_s.chomp.word_wrap(78) + "\n" %>
|
81
|
+
|
82
|
+
<% if nongem %>
|
83
|
+
%package -n ruby-%{gemname}
|
84
|
+
Summary: <%= spec.summary.gsub(/\.$/, "") %>
|
85
|
+
Group: Development/Languages
|
86
|
+
Requires: rubygem(%{gemname}) = %{version}
|
87
|
+
<% spec.files.select{ |f| spec.require_paths.include?(File::dirname(f)) }.reject { |f| f =~ /\.rb$/ }.collect { |f| File::basename(f) }.each do |p| %>
|
88
|
+
Provides: ruby(<%= p %>) = %{version}
|
89
|
+
<% end %>
|
90
|
+
%description -n ruby-%{gemname}
|
91
|
+
<%= spec.description.to_s.chomp.word_wrap(78) + "\n" %>
|
92
|
+
<% end # if nongem %>
|
93
|
+
|
94
|
+
%prep
|
95
|
+
|
96
|
+
%build
|
97
|
+
|
98
|
+
%install
|
99
|
+
%{__rm} -rf %{buildroot}
|
100
|
+
mkdir -p %{buildroot}%{gemdir}
|
101
|
+
<% rdoc_opt = spec.has_rdoc ? "--rdoc " : "" %>
|
102
|
+
gem install --local --install-dir %{buildroot}%{gemdir} --force <%= rdoc_opt %>%{SOURCE0}
|
103
|
+
<% unless spec.executables.empty? %>
|
104
|
+
mkdir -p %{buildroot}/%{_bindir}
|
105
|
+
mv %{buildroot}%{gemdir}/bin/* %{buildroot}/%{_bindir}
|
106
|
+
rmdir %{buildroot}%{gemdir}/bin
|
107
|
+
find %{buildroot}%{geminstdir}/bin -type f | xargs chmod a+x
|
108
|
+
<% end %>
|
109
|
+
<% if nongem %>
|
110
|
+
mkdir -p %{buildroot}%{ruby_sitelib}
|
111
|
+
<% spec.files.select{ |f| spec.require_paths.include?(File::dirname(f)) }.each do |p| %>
|
112
|
+
ln -s %{gemdir}/gems/%{gemname}-%{version}/<%= p %> %{buildroot}%{ruby_sitelib}
|
113
|
+
<% end %>
|
114
|
+
<% end # if nongem %>
|
115
|
+
|
116
|
+
%clean
|
117
|
+
%{__rm} -rf %{buildroot}
|
118
|
+
|
119
|
+
%files
|
120
|
+
%defattr(-, root, root)
|
121
|
+
<% for f in spec.executables %>
|
122
|
+
%{_bindir}/<%= f %>
|
123
|
+
<% end %>
|
124
|
+
%{gemdir}/gems/%{gemname}-%{version}/
|
125
|
+
<% if spec.has_rdoc %>
|
126
|
+
%doc %{gemdir}/doc/%{gemname}-%{version}
|
127
|
+
<% end %>
|
128
|
+
<% for f in spec.extra_rdoc_files %>
|
129
|
+
%doc %{geminstdir}/<%= f %>
|
130
|
+
<% end %>
|
131
|
+
%{gemdir}/cache/%{gemname}-%{version}.gem
|
132
|
+
%{gemdir}/specifications/%{gemname}-%{version}.gemspec
|
133
|
+
|
134
|
+
<% if nongem %>
|
135
|
+
%files -n ruby-%{gemname}
|
136
|
+
%{ruby_sitelib}/*
|
137
|
+
<% end # if nongem %>
|
138
|
+
|
139
|
+
%changelog
|
140
|
+
* <%= Time.now.strftime("%a %b %d %Y") %> <%= packager %> - <%= spec.version %>-1
|
141
|
+
- Initial package
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
# Local Variables:
|
146
|
+
# ruby-indent-level: 2
|
147
|
+
# End:
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated from gem2rpm-0.4.1.gem by gem2rpm -*- rpm-spec -*-
|
2
|
+
%define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
|
3
|
+
%define gemname gem2rpm
|
4
|
+
%define geminstdir %{gemdir}/gems/%{gemname}-%{version}
|
5
|
+
|
6
|
+
Summary: Generate rpm specfiles from gems
|
7
|
+
Name: rubygem-%{gemname}
|
8
|
+
|
9
|
+
Version: 0.4.2
|
10
|
+
Release: 1%{?dist}
|
11
|
+
Group: Development/Languages
|
12
|
+
License: GPL
|
13
|
+
URL: http://people.redhat.com/dlutter/gem2rpm.html
|
14
|
+
Source0: %{gemname}-%{version}.gem
|
15
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(%{__id_u} -n)
|
16
|
+
Requires: rubygems
|
17
|
+
BuildRequires: rubygems
|
18
|
+
BuildArch: noarch
|
19
|
+
Provides: rubygem(gem2rpm) = %{version}
|
20
|
+
|
21
|
+
%description
|
22
|
+
Generate source rpms and rpm spec files from a Ruby Gem. The spec file
|
23
|
+
tries to follow the gem as closely as possible
|
24
|
+
|
25
|
+
%prep
|
26
|
+
|
27
|
+
%build
|
28
|
+
|
29
|
+
%install
|
30
|
+
%{__rm} -rf %{buildroot}
|
31
|
+
mkdir -p %{buildroot}%{gemdir}
|
32
|
+
gem install --local --install-dir %{buildroot}%{gemdir} --force %{SOURCE0}
|
33
|
+
mkdir -p %{buildroot}/%{_bindir}
|
34
|
+
mv %{buildroot}%{gemdir}/bin/* %{buildroot}/%{_bindir}
|
35
|
+
rmdir %{buildroot}%{gemdir}/bin
|
36
|
+
find %{buildroot}%{geminstdir}/bin -type f | xargs chmod a+x
|
37
|
+
|
38
|
+
%clean
|
39
|
+
%{__rm} -rf %{buildroot}
|
40
|
+
|
41
|
+
%files
|
42
|
+
%defattr(-, root, root)
|
43
|
+
%{_bindir}/gem2rpm
|
44
|
+
%{gemdir}/gems/%{gemname}-%{version}/
|
45
|
+
%doc %{geminstdir}/README
|
46
|
+
%doc %{geminstdir}/LICENSE
|
47
|
+
%{gemdir}/cache/%{gemname}-%{version}.gem
|
48
|
+
%{gemdir}/specifications/%{gemname}-%{version}.gemspec
|
49
|
+
|
50
|
+
%changelog
|
51
|
+
* Tue Mar 6 2007 David Lutterkort <dlutter@redhat.com> - 0.4.2-1
|
52
|
+
- New version
|
53
|
+
|
54
|
+
* Fri Feb 23 2007 David Lutterkort <dlutter@redhat.com> - 0.4.1-1
|
55
|
+
- Initial (selfpackaged) version
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: gem2rpm
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.5.0
|
7
|
+
date: 2007-07-12 00:00:00 -07:00
|
8
|
+
summary: Generate rpm specfiles from gems
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: gem2rpm-devel@rubyforge.org
|
12
|
+
homepage: http://rubyforge.org/projects/gem2rpm/
|
13
|
+
rubyforge_project:
|
14
|
+
description: Generate source rpms and rpm spec files from a Ruby Gem. The spec file tries to follow the gem as closely as possible
|
15
|
+
autorequire:
|
16
|
+
default_executable: gem2rpm
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- David Lutterkort
|
31
|
+
files:
|
32
|
+
- bin/gem2rpm
|
33
|
+
- lib/gem2rpm.rb
|
34
|
+
- LICENSE
|
35
|
+
- README
|
36
|
+
- rubygem-gem2rpm.spec
|
37
|
+
- AUTHORS
|
38
|
+
test_files: []
|
39
|
+
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- AUTHORS
|
44
|
+
- README
|
45
|
+
- LICENSE
|
46
|
+
executables:
|
47
|
+
- gem2rpm
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
dependencies: []
|
53
|
+
|