diff --git a/lib/gem2rpm/rpm_dependency.rb b/lib/gem2rpm/rpm_dependency.rb index 8cfaee6..3bba4b9 100644 --- a/lib/gem2rpm/rpm_dependency.rb +++ b/lib/gem2rpm/rpm_dependency.rb @@ -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 ? reqs.first : "(#{reqs.join(' with ')})" + + if with_requires + result.prepend(dep.type == :development ? 'BuildRequires: ' : 'Requires: ') + end + + if commented_out + result.prepend('# ') + end + + result + end end end diff --git a/lib/gem2rpm/rpm_dependency_list.rb b/lib/gem2rpm/rpm_dependency_list.rb index 0f42f5a..3204181 100644 --- a/lib/gem2rpm/rpm_dependency_list.rb +++ b/lib/gem2rpm/rpm_dependency_list.rb @@ -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, comment_out: comment_out) + end.join("\n") + s += "\n" unless s.empty? + end end end diff --git a/templates/fedora-27-rawhide.spec.erb b/templates/fedora-27-rawhide.spec.erb index 7ad641b..b917ba1 100644 --- a/templates/fedora-27-rawhide.spec.erb +++ b/templates/fedora-27-rawhide.spec.erb @@ -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, comment_out: true) -%> <% if spec.extensions.empty? -%> BuildArch: noarch <% end -%>