gem2rpm 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -17,14 +17,25 @@ Usage
17
17
 
18
18
  Run 'gem2rpm --help' for options
19
19
 
20
- At its simplest, download a gem (let's call that file GEM) and run
21
- gem2rpm $GEM
20
+ At its simplest, download a gem (let's call it GEM) in its latest
21
+ version (e.g. 1.2.3):
22
+
23
+ $ gem fetch GEM
24
+
25
+ and run gem2rpm above the downloaded file:
26
+
27
+ $ gem2rpm GEM-1.2.3.gem
28
+
29
+ You can also use the --fetch flag to fetch the (latest) gem before generating the spec file, achieving the same effect as running 'gem fetch GEM' plus 'gem2rpm GEM-1.2.3.gem':
30
+
31
+ $ gem2rpm --fetch GEM
22
32
 
23
33
  This will print an rpm spec file based on the information contained in the
24
34
  gem's spec file. In general, it is necessary to edit the generated spec
25
35
  file because the gem is missing some important information that is
26
36
  customarily provided in rpm's, most notably the license and the changelog.
27
37
 
38
+
28
39
  Rather than editing the generated specfile, edit the template from which
29
40
  the specfile is generated. This will make it easier to update the RPM when
30
41
  a new version of the Gem becomes available.
data/bin/gem2rpm CHANGED
@@ -7,8 +7,10 @@ require 'gem2rpm'
7
7
  require 'optparse'
8
8
  require 'rubygems/format'
9
9
  require 'fileutils'
10
+ require 'open-uri'
11
+ require 'uri'
10
12
 
11
- opts = OptionParser.new("#{$0} [OPTIONS] GEMFILE")
13
+ opts = OptionParser.new("Usage: #{$0} [OPTIONS] GEM")
12
14
  opts.separator(" Convert ruby Gems to source RPMs and specfiles")
13
15
  opts.separator(" Uses a template to generate the RPM specfile")
14
16
  opts.separator(" from the Gem spec")
@@ -21,7 +23,10 @@ srpm = false
21
23
  deps = false
22
24
  nongem = false
23
25
  doc_subpackage = true
26
+ fetch = false
24
27
 
28
+ opts.separator("")
29
+ opts.separator(" Options:")
25
30
  opts.on("-T", "--current-template", "Print the current template") do |val|
26
31
  print_template_file = true
27
32
  end
@@ -51,6 +56,15 @@ end
51
56
  opts.on("--no-doc", "Disable document subpackage") do |val|
52
57
  doc_subpackage = false
53
58
  end
59
+ opts.on("--fetch", "Fetch the gem from rubygems.org") do |val|
60
+ fetch = true
61
+ end
62
+ opts.separator("")
63
+ opts.separator(" Arguments:")
64
+ opts.separator(" GEM the path to locally stored gem package file or the name")
65
+ opts.separator(" of the gem when using --fetch.")
66
+ opts.separator("")
67
+
54
68
  rest = opts.permute(ARGV)
55
69
 
56
70
  template = nil
@@ -58,7 +72,8 @@ if template_file.nil?
58
72
  template = Gem2Rpm::TEMPLATE
59
73
  else
60
74
  begin
61
- f = open(template_file, "r")
75
+ f = open(template_file, "r") if File.exists?(template_file)
76
+ f = open(File.join(Gem2Rpm.template_dir, template_file + '.spec.erb'), "r") unless f
62
77
  rescue Errno::ENOENT
63
78
  $stderr.puts "Could not open template #{template_file}. Aborting"
64
79
  exit(1)
@@ -79,6 +94,17 @@ if rest.size != 1
79
94
  end
80
95
  gemfile = rest[0]
81
96
 
97
+ if fetch
98
+ gem_uri = ''
99
+ open("http://rubygems.org/api/v1/gems/#{gemfile}.json") do |f|
100
+ gem_uri = f.read.match(/"gem_uri":\s*"(.*?)",/m)[1]
101
+ gemfile = URI.parse(gem_uri).path.split('/').last
102
+ open(gemfile, 'w') do |gf|
103
+ gf.write(open(gem_uri).read)
104
+ end
105
+ end
106
+ end
107
+
82
108
  srpmdir = nil
83
109
  gemname = nil
84
110
  srpmdir = nil
@@ -115,7 +141,9 @@ if srpm
115
141
  end
116
142
 
117
143
  if deps
118
- Gem::Format.from_file_by_path(gemfile).spec.dependencies.each do |dep|
119
- puts "rubygem(#{dep.name}) #{dep.version_requirements.to_rpm}"
144
+ Gem::Format.from_file_by_path(gemfile).spec.dependencies.each do |dep|
145
+ Gem2Rpm::Dependency.new(dep).requirement.each do |r|
146
+ puts "rubygem(#{dep.name}) #{r}"
120
147
  end
148
+ end
121
149
  end
@@ -6,7 +6,20 @@ module Gem2Rpm
6
6
 
7
7
  def self.nature
8
8
  if !release_files.grep(/fedora/).empty?
9
- FEDORA
9
+ versions = []
10
+
11
+ release_files.each do |file|
12
+ /\d+/ =~ File.open(file).readline
13
+ versions << Regexp.last_match.to_s.to_i if Regexp.last_match
14
+ end
15
+
16
+ versions.uniq!
17
+
18
+ if versions.length == 1
19
+ template_by_os_version(FEDORA, versions.first) || FEDORA
20
+ else # no version or more versions (=> don't know what to do)
21
+ FEDORA
22
+ end
10
23
  elsif !release_files.grep(/SuSe/).empty?
11
24
  OPENSUSE
12
25
  else
@@ -17,6 +30,29 @@ module Gem2Rpm
17
30
  def self.release_files
18
31
  @@release_files ||= Dir.glob '/etc/*{_version,-release}*'
19
32
  end
33
+
34
+ def self.template_by_os_version(os, version)
35
+ Dir.new(Gem2Rpm::template_dir).each do |file|
36
+ /#{os}-([\w-]+).spec.erb/ =~ file
37
+ return file.gsub('.spec.erb', '') if Regexp.last_match and in_range?(version, Regexp.last_match[1].to_s.split('-'))
38
+ end
39
+
40
+ nil
41
+ end
42
+
43
+ def self.in_range?(version, range)
44
+ return nil unless range
45
+
46
+ if range.length == 1
47
+ return true if range.first.to_i == version
48
+ else # range: [xx, yy]
49
+ if range[0].to_i <= version
50
+ return true if range[1] == 'rawhide' or version <= range[1].to_i
51
+ end
52
+ end
53
+
54
+ false
55
+ end
20
56
  end
21
57
  end
22
58
 
data/lib/gem2rpm.rb CHANGED
@@ -15,7 +15,7 @@ if HAS_REMOTE_INSTALLER
15
15
  end
16
16
 
17
17
  module Gem2Rpm
18
- Gem2Rpm::VERSION = "0.7.1"
18
+ Gem2Rpm::VERSION = "0.8.0"
19
19
 
20
20
  if HAS_REMOTE_INSTALLER
21
21
  def self.find_download_url(name, version)
@@ -50,6 +50,8 @@ module Gem2Rpm
50
50
  end
51
51
  template = ERB.new(template, 0, '-')
52
52
  out.puts template.result(binding)
53
+ rescue Gem::Exception => e
54
+ puts e
53
55
  end
54
56
 
55
57
  # Returns the email address of the packager (i.e., the person running
@@ -69,7 +71,11 @@ module Gem2Rpm
69
71
  packager
70
72
  end
71
73
 
72
- TEMPLATE = File.read File.join(File.dirname(__FILE__), '..', 'templates', "#{Distro.nature.to_s}.spec.erb")
74
+ def Gem2Rpm.template_dir
75
+ File.join(File.dirname(__FILE__), '..', 'templates')
76
+ end
77
+
78
+ TEMPLATE = File.read File.join(template_dir, "#{Distro.nature.to_s}.spec.erb")
73
79
  end
74
80
 
75
81
  # Local Variables:
@@ -0,0 +1,130 @@
1
+ # Generated from <%= File::basename(format.gem_path) %> by gem2rpm -*- rpm-spec -*-
2
+ %global gem_name <%= spec.name %>
3
+ %global rubyabi 1.9.1
4
+
5
+ Summary: <%= spec.summary.gsub(/\.$/, "") %>
6
+ Name: rubygem-%{gem_name}
7
+ Version: <%= spec.version %>
8
+ Release: 1%{?dist}
9
+ Group: Development/Languages
10
+ License: <%= spec.licenses.empty? ? "GPLv2+ or Ruby" : spec.licenses.join(" and ") %>
11
+ <% if spec.homepage -%>
12
+ URL: <%= spec.homepage %>
13
+ <% end -%>
14
+ Source0: <%= download_path %>%{gem_name}-%{version}.gem
15
+ Requires: ruby(abi) = %{rubyabi}
16
+ <% for req in spec.required_rubygems_version -%>
17
+ Requires: ruby(rubygems) <%= req %>
18
+ <% end -%>
19
+ <%# TODO: Unfortunatelly this do not match with ruby(abi) yet -%>
20
+ <% for req in spec.required_ruby_version -%>
21
+ Requires: ruby <%= req %>
22
+ <% end -%>
23
+ <% for d in spec.runtime_dependencies -%>
24
+ <% for req in d.requirement -%>
25
+ Requires: rubygem(<%= d.name %>) <%= req %>
26
+ <% end -%>
27
+ <% end -%>
28
+ BuildRequires: ruby(abi) = %{rubyabi}
29
+ <% for req in spec.required_rubygems_version -%>
30
+ BuildRequires: ruby(rubygems) <%= req %>
31
+ <% end -%>
32
+ <%# TODO: Unfortunatelly this do not match with ruby(abi) yet -%>
33
+ <% for req in spec.required_ruby_version -%>
34
+ BuildRequires: ruby <%= req %>
35
+ <% end -%>
36
+ <% if spec.extensions.empty? -%>
37
+ BuildArch: noarch
38
+ <% end -%>
39
+ Provides: rubygem(%{gem_name}) = %{version}
40
+
41
+ %description
42
+ <%= spec.description %>
43
+
44
+ <% if doc_subpackage -%>
45
+ %package doc
46
+ Summary: Documentation for %{name}
47
+ Group: Documentation
48
+ Requires: %{name} = %{version}-%{release}
49
+ BuildArch: noarch
50
+
51
+ %description doc
52
+ Documentation for %{name}
53
+ <% end # if doc_subpackage -%>
54
+
55
+ %prep
56
+ %setup -q -c -T
57
+ mkdir -p .%{gem_dir}
58
+ <% unless spec.extensions.empty? -%>
59
+ export CONFIGURE_ARGS="--with-cflags='%{optflags}'"
60
+ <% end -%>
61
+ gem install --local --install-dir .%{gem_dir} \
62
+ <% unless spec.executables.nil? or spec.executables.empty? -%>
63
+ --bindir .%{_bindir} \
64
+ <% end -%>
65
+ <% unless spec.extensions.empty? -%>
66
+ -V \
67
+ <% end -%>
68
+ --force %{SOURCE0}
69
+
70
+ %build
71
+
72
+ %install
73
+ mkdir -p %{buildroot}%{gem_dir}
74
+ cp -a .%{gem_dir}/* \
75
+ %{buildroot}%{gem_dir}/
76
+
77
+ <% unless spec.extensions.empty? -%>
78
+ mkdir -p %{buildroot}%{gem_extdir}/<%= spec.require_paths.first %>
79
+ # TODO: move the extensions
80
+ ##mv %{buildroot}%{gem_instdir}/<%= spec.require_paths.first %>/shared_object.so %{buildroot}%{gem_extdir}/<%= spec.require_paths.first %>/
81
+ <% end -%>
82
+
83
+ <% unless spec.executables.nil? or spec.executables.empty? -%>
84
+ mkdir -p %{buildroot}%{_bindir}
85
+ cp -a .%{_bindir}/* \
86
+ %{buildroot}%{_bindir}/
87
+ <% end -%>
88
+
89
+ <% unless spec.executables.empty? -%>
90
+ find %{buildroot}%{gem_instdir}/bin -type f | xargs chmod a+x
91
+ <% end -%>
92
+
93
+ <% unless spec.extensions.empty? -%>
94
+ <%# TODO: Is it possible to delete the folder specified by the spec.extensions? -%>
95
+ # Remove the binary extension sources and build leftovers.
96
+ rm -rf %{buildroot}%{geminstdir}/ext
97
+ <% end -%>
98
+
99
+ %files
100
+ %dir %{gem_instdir}
101
+ <% unless spec.executables.nil? or spec.executables.empty? -%>
102
+ <% for f in spec.executables -%>
103
+ %{_bindir}/<%= f %>
104
+ <% end -%>
105
+ %{gem_instdir}/bin
106
+ <% end -%>
107
+ %{gem_libdir}
108
+ <% unless spec.extensions.empty? -%>
109
+ %{gem_extdir}
110
+ <% end -%>
111
+ <% unless doc_subpackage -%>
112
+ %doc %{gem_docdir}
113
+ <% for f in spec.extra_rdoc_files -%>
114
+ %doc %{gem_instdir}/<%= f %>
115
+ <% end -%>
116
+ <% end -%>
117
+ %exclude %{gem_cache}
118
+ %{gem_spec}
119
+
120
+ <% if doc_subpackage -%>
121
+ %files doc
122
+ %doc %{gem_docdir}
123
+ <% for f in spec.extra_rdoc_files -%>
124
+ %doc %{gem_instdir}/<%= f %>
125
+ <% end -%>
126
+ <% end # if doc_subpackage -%>
127
+
128
+ %changelog
129
+ * <%= Time.now.strftime("%a %b %d %Y") %> <%= packager %> - <%= spec.version %>-1
130
+ - Initial package
@@ -128,7 +128,7 @@ rm -rf %{buildroot}%{geminstdir}/ext
128
128
  %doc %{geminstdir}/<%= f %>
129
129
  <% end -%>
130
130
  <% end -%>
131
- %{gemdir}/cache/%{gemname}-%{version}.gem
131
+ %exclude %{gemdir}/cache/%{gemname}-%{version}.gem
132
132
  %{gemdir}/specifications/%{gemname}-%{version}.gemspec
133
133
 
134
134
  <% if doc_subpackage -%>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem2rpm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 1
10
- version: 0.7.1
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Lutterkort
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-30 00:00:00 Z
19
+ date: 2012-01-23 00:00:00 Z
20
20
  dependencies: []
21
21
 
22
22
  description: " Generate source rpms and rpm spec files from a Ruby Gem. \n The spec file tries to follow the gem as closely as possible\n"
@@ -31,14 +31,15 @@ extra_rdoc_files:
31
31
  - LICENSE
32
32
  files:
33
33
  - bin/gem2rpm
34
- - lib/gem2rpm/distro.rb
35
34
  - lib/gem2rpm/specification.rb
36
35
  - lib/gem2rpm/helpers.rb
37
36
  - lib/gem2rpm/dependency.rb
37
+ - lib/gem2rpm/distro.rb
38
38
  - lib/gem2rpm.rb
39
39
  - templates/fedora.spec.erb
40
40
  - templates/opensuse.spec.erb
41
41
  - templates/default.spec.erb
42
+ - templates/fedora-17-rawhide.spec.erb
42
43
  - LICENSE
43
44
  - README
44
45
  - AUTHORS
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  requirements: []
72
73
 
73
74
  rubyforge_project:
74
- rubygems_version: 1.7.2
75
+ rubygems_version: 1.8.11
75
76
  signing_key:
76
77
  specification_version: 3
77
78
  summary: Generate rpm specfiles from gems