Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/gem2rpm/rpm_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,23 @@ def to_rpm
end
rpm_dependencies.join("\n")
end

# Returns string with entry suitable for RPM .spec file with RPM 4.14+.
def to_rich_rpm(with_requires: false, commented_out: false)
rpm_dependencies = requirement.map do |version|
version.to_s.empty? ? name : "#{name} #{version}"
end
result = rpm_dependencies.size == 1 ? rpm_dependencies.first : "(#{rpm_dependencies.join(' with ')})"

if with_requires
result.prepend(__getobj__.type == :development ? 'BuildRequires: ' : 'Requires: ')
end

if commented_out
result.prepend('# ')
end

result
end
end
end
12 changes: 11 additions & 1 deletion lib/gem2rpm/rpm_dependency_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ def comment_out
end

# Returns string with all dependencies from the list converted into entries
# suitable for RPM .spec file. Thise entries should include all necessary
# suitable for RPM .spec file. These entries should include all necessary
# macros depending on file categorization.
def to_rpm
s = entries.map(&:to_rpm).join("\n")
s += "\n" unless s.empty?
end

# Returns a string with all dependencies from the list converted into entries
# suitable for RPM .spec file with RPM 4.14+. Thise entries should include
# all necessary macros depending on file categorization.
def to_rich_rpm(with_requires: false, commented_out: false)
s = entries.map do |entry|
entry.to_rich_rpm(with_requires: with_requires, commented_out: comment_out)
end.join("\n")
s += "\n" unless s.empty?
end
end
end
2 changes: 1 addition & 1 deletion templates/fedora-27-rawhide.spec.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BuildRequires: gcc
<% end -%>
<%= development_dependencies.reject do |d|
["rdoc", "rake", "bundler"].include? d.name
end.virtualize.with_requires.comment_out.to_rpm -%>
end.virtualize.to_rich_rpm(with_requires: true, commented_out: true) -%>
<% if spec.extensions.empty? -%>
BuildArch: noarch
<% end -%>
Expand Down
2 changes: 1 addition & 1 deletion test/templates/test_fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_exclude_extension_directory
end

def test_build_requires
assert_match(/^# BuildRequires: rubygem\(test_development\) >= 1\.0\.0$/, @out_string)
assert_includes(@out_string, "\n# BuildRequires: (rubygem(test_development) >= 1.0 with rubygem(test_development) < 2 with rubygem(test_development) >= 1.0.0)\n")
end

def test_rubygems_is_not_required
Expand Down