]> git.pld-linux.org Git - packages/rpm.git/blame - rubygems.rb
- updated macros
[packages/rpm.git] / rubygems.rb
CommitLineData
e2489d8e
ER
1#!/usr/bin/env ruby
2#--
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).
6#
7# FIXME: Someone with actual ruby skills should really clean up and sanitize
8# this! fugliness obvious...
9#++
10
11require 'optparse'
12require 'rbconfig'
13
14provides = false
15requires = false
16
17opts = OptionParser.new("#{$0} <--provides|--requires>")
18opts.on("-P", "--provides", "Print provides") do |val|
19 provides = true
20end
21opts.on("-R", "--requires", "Print requires") do |val|
22 requires= true
23end
24
25rest = opts.permute(ARGV)
26
27if rest.size != 0 or (!provides and !requires) or (provides and requires)
28 $stderr.puts "Use either --provides OR --requires"
29 $stderr.puts opts
30 exit(1)
31end
32
73eb048b
ER
33require 'rubygems'
34gem_dir = Gem.respond_to?(:default_dirs) ? Gem.default_dirs[:system][:gem_dir] : Gem.path.first
35specpatt = "#{gem_dir}/specifications/.*\.gemspec$"
e2489d8e
ER
36gems = []
37ruby_versioned = false
38abi_provide = false
73eb048b
ER
39# as ruby_version may be empty, take version from basename of archdir
40ruby_version = RbConfig::CONFIG["ruby_version"].empty? ? File.basename(RbConfig::CONFIG["archdir"]) : RbConfig::CONFIG["ruby_version"]
e2489d8e
ER
41
42for 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")
47 abi_provide = true
48 ruby_versioned = true
49 elsif path.match(specpatt)
e2489d8e
ER
50 gems.push(path.chomp)
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"])
57 ruby_versioned = true
58 elsif path.match(RbConfig::CONFIG["archdir"])
59 ruby_versioned = true
60 elsif path.match(RbConfig::CONFIG["sitelibdir"])
73eb048b 61 ruby_versioned = !RbConfig::CONFIG["ruby_version"].empty?
e2489d8e
ER
62 elsif path.match(RbConfig::CONFIG["sitearchdir"])
63 ruby_versioned = true
64 elsif path.match(RbConfig::CONFIG["vendorlibdir"])
73eb048b 65 ruby_versioned = !RbConfig::CONFIG["ruby_version"].empty?
e2489d8e
ER
66 elsif path.match(RbConfig::CONFIG["vendorarchdir"])
67 ruby_versioned = true
68 end
69 end
70end
71
72if requires or abi_provide
73 abidep = "ruby(abi)"
74 if ruby_versioned
73eb048b 75 abidep += " = %s" % ruby_version
e2489d8e
ER
76 end
77 print abidep + "\n"
78end
79
80if gems.length > 0
81 require 'rubygems'
82
83 if requires
84
85 module Gem
86 class Requirement
87 def rpm_dependency_transform(name, version)
88 pessimistic = ""
89 if version == "> 0.0.0" or version == ">= 0"
90 version = ""
91 else
92 if version[0..1] == "~>"
93 pessimistic = "rubygem(%s) < %s\n" % [name, Gem::Version.create(version[3..-1]).bump]
94 version = version.gsub(/\~>/, '=>')
95 end
4366f922 96 if version[0..1] == "!="
ba52d6d6 97 version = version.gsub(/\!=/, '>')
4366f922 98 end
31f2334b 99 version = version.sub(/^/, ' ')
e2489d8e
ER
100 end
101 version = "rubygem(%s)%s\n%s" % [name, version, pessimistic]
102 end
103
104 def to_rpm(name)
105 result = as_list
106 return result.map { |version| rpm_dependency_transform(name, version) }
107 end
108
109 end
110 end
111 end
112
113 for gem in gems
114 data = File.read(gem)
115 spec = eval(data)
116 if provides
117 print "rubygem(%s) = %s\n" % [spec.name, spec.version]
118 end
119 if requires
120 for d in spec.dependencies
121 print d.requirement.to_rpm(d.name)[0] unless d.type != :runtime
122 end
123 for d in spec.required_rubygems_version.to_rpm("rubygems")
124 print d.gsub(/(rubygem\()|(\))/, "")
125 end
126 end
127 end
128end
This page took 0.044723 seconds and 4 git commands to generate.