pvalena / rpms / ruby

Forked from rpms/ruby 6 years ago
Clone
637f46e
#!/usr/bin/ruby
637f46e
637f46e
require 'rubygems/package'
637f46e
637f46e
module RubyGemsReq
637f46e
  module Helpers
637f46e
    # Keep only '!=' requirements.
637f46e
    def self.conflicts(requirements)
637f46e
      conflicts = requirements.select {|r| r.first == '!='}
637f46e
    end
637f46e
637f46e
    # Converts Gem::Requirement into array of requirements strings compatible
637f46e
    # with RPM .spec file.
637f46e
    def self.requirement_versions_to_rpm(requirement)
637f46e
      self.conflicts(requirement.requirements).map do |op, version|
637f46e
        version == Gem::Version.new(0) ? "" : "= #{version}"
637f46e
      end
637f46e
    end
637f46e
  end
637f46e
637f46e
  # Report conflicting gem dependencies including their version.
637f46e
  def self.gem_depenencies(specification)
637f46e
    specification.runtime_dependencies.each do |dependency|
637f46e
      conflict_strings = Helpers::requirement_versions_to_rpm(dependency.requirement).map do |requirement|
637f46e
        requirement_string = "rubygem(#{dependency.name}) #{requirement}"
637f46e
      end
637f46e
      if conflict_strings.length > 0
637f46e
        conflict_string = conflict_strings.join(' with ')
637f46e
        conflict_string.prepend('(').concat(')') if conflict_strings.length > 1
637f46e
        puts conflict_string
637f46e
      end
637f46e
    end
637f46e
  end
637f46e
637f46e
  # Reports all conflicts specified by all provided .gemspec files.
637f46e
  def self.conflicts
637f46e
    while filename = gets
637f46e
      filename.strip!
637f46e
      begin
637f46e
        specification = Gem::Specification.load filename
637f46e
637f46e
        gem_depenencies(specification)
637f46e
      rescue => e
637f46e
        # Ignore all errors.
637f46e
      end
637f46e
    end
637f46e
  end
637f46e
end
637f46e
637f46e
if __FILE__ == $0
637f46e
  RubyGemsReq::conflicts
637f46e
end