2018-02-01 18:22:44 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'rubygems/package'
|
|
|
|
|
|
|
|
module RubyGemsReq
|
|
|
|
module Helpers
|
|
|
|
# Keep only '!=' requirements.
|
|
|
|
def self.conflicts(requirements)
|
|
|
|
conflicts = requirements.select {|r| r.first == '!='}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Converts Gem::Requirement into array of requirements strings compatible
|
|
|
|
# with RPM .spec file.
|
|
|
|
def self.requirement_versions_to_rpm(requirement)
|
|
|
|
self.conflicts(requirement.requirements).map do |op, version|
|
|
|
|
version == Gem::Version.new(0) ? "" : "= #{version}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Report conflicting gem dependencies including their version.
|
2024-09-02 10:04:28 +00:00
|
|
|
def self.gem_dependencies(specification)
|
2018-02-01 18:22:44 +00:00
|
|
|
specification.runtime_dependencies.each do |dependency|
|
|
|
|
conflict_strings = Helpers::requirement_versions_to_rpm(dependency.requirement).map do |requirement|
|
|
|
|
requirement_string = "rubygem(#{dependency.name}) #{requirement}"
|
|
|
|
end
|
|
|
|
if conflict_strings.length > 0
|
|
|
|
conflict_string = conflict_strings.join(' with ')
|
|
|
|
conflict_string.prepend('(').concat(')') if conflict_strings.length > 1
|
|
|
|
puts conflict_string
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Reports all conflicts specified by all provided .gemspec files.
|
|
|
|
def self.conflicts
|
|
|
|
while filename = gets
|
|
|
|
filename.strip!
|
|
|
|
begin
|
|
|
|
specification = Gem::Specification.load filename
|
|
|
|
|
2024-09-02 10:04:28 +00:00
|
|
|
gem_dependencies(specification)
|
2018-02-01 18:22:44 +00:00
|
|
|
rescue => e
|
|
|
|
# Ignore all errors.
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if __FILE__ == $0
|
|
|
|
RubyGemsReq::conflicts
|
|
|
|
end
|