From 51b5119abc6bc1fe4a77a1bc2d139e4b082ca386 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 24 Nov 2023 18:58:45 +0100 Subject: [PATCH] Implement rich RPM dependencies This implements rich RPM dependencies, which are available with RPM 4.14+ (introduced in Fedora 27[1]). This means only a single line for a dependency is used. That doesn't play well with the .with_requires.commented_out approach that was implemented. This instead moves the loop back to the template. [1]: https://fedoraproject.org/wiki/Changes/RPM-4.14 --- lib/gem2rpm/rpm_dependency.rb | 6 ++++++ templates/fedora-27-rawhide.spec.erb | 6 +++--- test/templates/test_fedora.rb | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/gem2rpm/rpm_dependency.rb b/lib/gem2rpm/rpm_dependency.rb index 8cfaee6..a81fb0c 100644 --- a/lib/gem2rpm/rpm_dependency.rb +++ b/lib/gem2rpm/rpm_dependency.rb @@ -47,5 +47,11 @@ 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 + rpm_dependencies = requirement.map { |v| v.to_s.empty? ? name : "#{name} #{v}" } + rpm_dependencies.size == 1 ? rpm_dependencies.first : "(#{rpm_dependencies.join(' with ')})" + end end end diff --git a/templates/fedora-27-rawhide.spec.erb b/templates/fedora-27-rawhide.spec.erb index 7ad641b..897c16e 100644 --- a/templates/fedora-27-rawhide.spec.erb +++ b/templates/fedora-27-rawhide.spec.erb @@ -22,9 +22,9 @@ BuildRequires: <%= requirement "ruby#{'-devel' unless spec.extensions.empty?}", # https://fedoraproject.org/wiki/Packaging:C_and_C++#BuildRequires_and_Requires BuildRequires: gcc <% end -%> -<%= development_dependencies.reject do |d| - ["rdoc", "rake", "bundler"].include? d.name -end.virtualize.with_requires.comment_out.to_rpm -%> +<% for req in development_dependencies.reject { |d| ["rdoc", "rake", "bundler"].include? d.name }.virtualize -%> +# BuildRequires: <%= req.to_rich_rpm %> +<% end -%> <% if spec.extensions.empty? -%> BuildArch: noarch <% end -%> diff --git a/test/templates/test_fedora.rb b/test/templates/test_fedora.rb index 338908b..a9734d5 100644 --- a/test/templates/test_fedora.rb +++ b/test/templates/test_fedora.rb @@ -36,7 +36,7 @@ def test_exclude_extension_directory end def test_build_requires - assert_includes(@out_string, "\n# BuildRequires: (rubygem(test_development) >= 1.0 with rubygem(test_development) >= 1.0 with rubygem(test_development) >= 1.0.0)\n") + 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