From 724ffdbb53749eb752ed8d30bc663e48a0738948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Mon, 3 Mar 2014 17:49:42 +0100 Subject: [PATCH] Add RPM dependency generators for RubyGems. --- ruby.spec | 16 ++++++++++ rubygems.attr | 3 ++ rubygems.prov | 36 +++++++++++++++++++++++ rubygems.req | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 rubygems.attr create mode 100644 rubygems.prov create mode 100644 rubygems.req diff --git a/ruby.spec b/ruby.spec index 86359f7..f157de9 100644 --- a/ruby.spec +++ b/ruby.spec @@ -82,6 +82,10 @@ Source6: abrt_prelude.rb # https://fedorahosted.org/fpc/ticket/312 # https://bugzilla.redhat.com/show_bug.cgi?id=977941 Source7: config.h +# RPM dependency generators. +Source8: rubygems.attr +Source9: rubygems.req +Source10: rubygems.prov # Include the constants defined in macros files. @@ -477,6 +481,12 @@ sed -i "s/%%{name}/%{name}/" %{buildroot}%{_rpmconfigdir}/macros.d/macros.ruby install -m 644 %{SOURCE5} %{buildroot}%{_rpmconfigdir}/macros.d/macros.rubygems sed -i "s/%%{name}/%{name}/" %{buildroot}%{_rpmconfigdir}/macros.d/macros.rubygems +# Install dependency generators. +mkdir -p %{buildroot}%{_rpmconfigdir}/fileattrs +install -m 644 %{SOURCE8} %{buildroot}%{_rpmconfigdir}/fileattrs +install -m 755 %{SOURCE9} %{buildroot}%{_rpmconfigdir} +install -m 755 %{SOURCE10} %{buildroot}%{_rpmconfigdir} + # Install custom operating_system.rb. mkdir -p %{buildroot}%{rubygems_dir}/rubygems/defaults cp %{SOURCE1} %{buildroot}%{rubygems_dir}/rubygems/defaults @@ -821,6 +831,9 @@ OPENSSL_ENABLE_MD5_VERIFY=1 make check TESTS="-v $DISABLE_TESTS" %files -n rubygems-devel %{_rpmconfigdir}/macros.d/macros.rubygems +%{_rpmconfigdir}/fileattrs/rubygems.attr +%{_rpmconfigdir}/rubygems.req +%{_rpmconfigdir}/rubygems.prov %files -n rubygem-rake %{_bindir}/rake @@ -890,6 +903,9 @@ OPENSSL_ENABLE_MD5_VERIFY=1 make check TESTS="-v $DISABLE_TESTS" %{ruby_libdir}/tkextlib %changelog +* Mon Mar 03 2014 Vít Ondruch - 2.1.0-19 +- Add RPM dependency generators for RubyGems. + * Mon Feb 10 2014 Josef Stribny - 2.1.0-19 - Don't link cert.pem explicitely diff --git a/rubygems.attr b/rubygems.attr new file mode 100644 index 0000000..f711775 --- /dev/null +++ b/rubygems.attr @@ -0,0 +1,3 @@ +%__rubygems_requires %{_rpmconfigdir}/rubygems.req +%__rubygems_provides %{_rpmconfigdir}/rubygems.prov +%__rubygems_path ^%{gem_spec}$ diff --git a/rubygems.prov b/rubygems.prov new file mode 100644 index 0000000..f23ec3f --- /dev/null +++ b/rubygems.prov @@ -0,0 +1,36 @@ +#!/usr/bin/ruby + +require 'rubygems/package' + +module RubyGemsProv + module Helpers + # If there is some prelease version files, such as rc1 (i.e. non-numeric + # field), prepend this field by tilde instead of dot. + def self.normalize_prerelease(version) + if version.prerelease? + prerelease = version.version.sub /^#{version.release}\./, '' + "#{version.release}~#{prerelease}" + else + version.release + end + end + end + + # Reports all functionality gem provides. + def self.provides + while filename = gets + filename.strip! + begin + specification = Gem::Specification.load filename + + puts "rubygem(#{specification.name}) = #{Helpers::normalize_prerelease(specification.version)}" + rescue => e + # Ignore all errors. + end + end + end +end + +if __FILE__ == $0 + RubyGemsProv::provides +end diff --git a/rubygems.req b/rubygems.req new file mode 100644 index 0000000..831d7af --- /dev/null +++ b/rubygems.req @@ -0,0 +1,81 @@ +#!/usr/bin/ruby + +require 'rubygems/package' + +module RubyGemsReq + module Helpers + # Expands '~>' and '!=' gem requirements. + def self.expand_requirement(requirements) + requirements.inject([]) do |output, r| + output.concat case r.first + when '~>' + expand_pessimistic_requirement(r) + when '!=' + expand_not_equal_requirement(r) + else + [r] + end + end + end + + # Expands the pessimistic version operator '~>' into equivalent '>=' and + # '<' pair. + def self.expand_pessimistic_requirement(requirement) + next_version = Gem::Version.create(requirement.last).bump + return ['>=', requirement.last], ['<', next_version] + end + + # Expands the not equal version operator '!=' into equivalent '<' and + # '>' pair. + def self.expand_not_equal_requirement(requirement) + return ['<', requirement.last], ['>', requirement.last] + end + + # Converts Gem::Requirement into array of requirements strings compatible + # with RPM .spec file. + def self.requirement_versions_to_rpm(requirement) + self.expand_requirement(requirement.requirements).map do |op, version| + version == Gem::Version.new(0) ? "" : "#{op} #{version}" + end + end + end + + # Report RubyGems dependency, versioned if required. + def self.rubygems_dependency(specification) + Helpers::requirement_versions_to_rpm(specification.required_rubygems_version).each do |requirement| + dependency_string = "ruby(rubygems)" + dependency_strint += " #{specification.required_rubygems_version}" if requirement && requirement.length > 0 + puts dependency_string + end + end + + # Report all gem dependencies including their version. + def self.gem_depenencies(specification) + specification.runtime_dependencies.each do |dependency| + Helpers::requirement_versions_to_rpm(dependency.requirement).each do |requirement| + dependency_string = "rubygem(#{dependency.name})" + dependency_string += " #{requirement}" if requirement && requirement.length > 0 + puts dependency_string + end + end + end + + # Reports all requirements specified by all provided .gemspec files. + def self.requires + while filename = gets + filename.strip! + begin + specification = Gem::Specification.load filename + + rubygems_dependency(specification) + gem_depenencies(specification) + rescue => e + # Ignore all errors. + end + end + end +end + +if __FILE__ == $0 + RubyGemsReq::requires +end