From 1d8ae5030fb02e39aa2928d184c8302152ed89a1 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Wed, 12 Sep 2012 08:10:29 +0000 Subject: 1.160: merge rubygems.rb from Mandriva, so that it works with ruby 1.9.x --- rubygems.rb | 62 ++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 15 deletions(-) (limited to 'rubygems.rb') diff --git a/rubygems.rb b/rubygems.rb index 1a775bd..5368b26 100755 --- a/rubygems.rb +++ b/rubygems.rb @@ -3,40 +3,75 @@ # Copyright 2010 Per Øyvind Karlsen # This program is free software. It may be redistributed and/or modified under # the terms of the LGPL version 2.1 (or later). +# +# FIXME: Someone with actual ruby skills should really clean up and sanitize +# this! fugliness obvious... #++ require 'optparse' -require 'rubygems' +require 'rbconfig' provides = false requires = false opts = OptionParser.new("#{$0} <--provides|--requires>") opts.on("-P", "--provides", "Print provides") do |val| - provides = true + provides = true end opts.on("-R", "--requires", "Print requires") do |val| - requires= true + requires= true end rest = opts.permute(ARGV) if rest.size != 0 or (!provides and !requires) or (provides and requires) - $stderr.puts "Use either --provides OR --requires" - $stderr.puts opts - exit(1) + $stderr.puts "Use either --provides OR --requires" + $stderr.puts opts + exit(1) end -specpath = "%s/specifications/.*\.gemspec$" % Gem::dir +specpatt = "%s/specifications/.*\.gemspec$" % RbConfig::CONFIG["rubygemsdir"] + gems = [] -for gemspec in $stdin.readlines - if gemspec.match(specpath) - gems.push(gemspec.chomp) +ruby_versioned = false +abi_provide = false + +for path in $stdin.readlines + # way fugly, but we make the assumption that if the package has + # this file, the package is the current ruby version, and should + # therefore provide ruby(abi) = version + if provides and path.match(RbConfig::CONFIG["archdir"] + "/rbconfig.rb") + abi_provide = true + elsif path.match(specpatt) + ruby_versioned = true + gems.push(path.chomp) + # this is quite ugly and lame, but the assumption made is that if any files + # found in any of these directories specific to this ruby version, the + # package is dependent on this specific version. + # FIXME: only supports current ruby version + elsif not ruby_versioned + if path.match(RbConfig::CONFIG["rubylibdir"]) + ruby_versioned = true + elsif path.match(RbConfig::CONFIG["sitelibdir"]) + ruby_versioned = true + elsif path.match(RbConfig::CONFIG["vendorlibdir"]) + ruby_versioned = true + end + end +end + +if requires or abi_provide + abidep = "ruby(abi)" + if ruby_versioned + abidep += " = %s" % RbConfig::CONFIG["ruby_version"] end + print abidep + "\n" end + if gems.length > 0 + require 'rubygems' + if requires - require 'rbconfig' module Gem class Requirement @@ -61,9 +96,6 @@ if gems.length > 0 end end - # TODO: Should we add a strict dependency on ruby version here? - #print "ruby < %s%s\n" % [Config::CONFIG["ruby_version"][0..-2], Config::CONFIG["ruby_version"][-1..-1].to_i + 1] - print "ruby >= %s\n" % Config::CONFIG["ruby_version"] end for gem in gems @@ -74,7 +106,7 @@ if gems.length > 0 end if requires for d in spec.dependencies - print d.requirement.to_rpm(d.name) unless d.type != :runtime + print d.requirement.to_rpm(d.name)[0] unless d.type != :runtime end for d in spec.required_rubygems_version.to_rpm("rubygems") print d.gsub(/(rubygem\()|(\))/, "") -- cgit v1.2.1