3 # Copyright 2010 Per Øyvind Karlsen <peroyvind@mandriva.org>
4 # This program is free software. It may be redistributed and/or modified under
5 # the terms of the LGPL version 2.1 (or later).
7 # FIXME: Someone with actual ruby skills should really clean up and sanitize
8 # this! fugliness obvious...
17 opts = OptionParser.new("#{$0} <--provides|--requires>")
18 opts.on("-P", "--provides", "Print provides") do |val|
21 opts.on("-R", "--requires", "Print requires") do |val|
25 rest = opts.permute(ARGV)
27 if rest.size != 0 or (!provides and !requires) or (provides and requires)
28 $stderr.puts "Use either --provides OR --requires"
34 gem_dir = Gem.respond_to?(:default_dirs) ? Gem.default_dirs[:system][:gem_dir] : Gem.path.first
35 specpatt = "#{gem_dir}/specifications/.*\.gemspec$"
37 ruby_versioned = false
39 # as ruby_version may be empty, take version from basename of archdir
40 ruby_version = RbConfig::CONFIG["ruby_version"].empty? ? File.basename(RbConfig::CONFIG["archdir"]) : RbConfig::CONFIG["ruby_version"]
42 for path in $stdin.readlines
43 # way fugly, but we make the assumption that if the package has
44 # this file, the package is the current ruby version, and should
45 # therefore provide ruby(abi) = version
46 if provides and path.match(RbConfig::CONFIG["archdir"] + "/rbconfig.rb")
49 elsif path.match(specpatt)
51 # this is quite ugly and lame, but the assumption made is that if any files
52 # found in any of these directories specific to this ruby version, the
53 # package is dependent on this specific version.
54 # FIXME: only supports current ruby version
55 elsif not ruby_versioned
56 if path.match(RbConfig::CONFIG["rubylibdir"])
58 elsif path.match(RbConfig::CONFIG["archdir"])
60 elsif path.match(RbConfig::CONFIG["sitelibdir"])
61 ruby_versioned = !RbConfig::CONFIG["ruby_version"].empty?
62 elsif path.match(RbConfig::CONFIG["sitearchdir"])
64 elsif path.match(RbConfig::CONFIG["vendorlibdir"])
65 ruby_versioned = !RbConfig::CONFIG["ruby_version"].empty?
66 elsif path.match(RbConfig::CONFIG["vendorarchdir"])
72 if requires or abi_provide
75 abidep += " = %s" % ruby_version
87 def rpm_dependency_transform(name, version)
89 if version == "> 0.0.0" or version == ">= 0"
92 if version[0..1] == "~>"
93 pessimistic = "rubygem(%s) < %s\n" % [name, Gem::Version.create(version[3..-1]).bump]
94 version = version.gsub(/\~>/, '=>')
96 if version[0..1] == "!="
97 version = version.gsub(/\!=/, '>')
99 version = version.sub(/^/, ' ')
101 version = "rubygem(%s)%s\n%s" % [name, version, pessimistic]
106 return result.map { |version| rpm_dependency_transform(name, version) }
114 data = File.read(gem)
117 print "rubygem(%s) = %s\n" % [spec.name, spec.version]
120 for d in spec.dependencies
121 print d.requirement.to_rpm(d.name)[0] unless d.type != :runtime
123 for d in spec.required_rubygems_version.to_rpm("rubygems")
124 print d.gsub(/(rubygem\()|(\))/, "")