]> git.pld-linux.org Git - packages/rpm.git/blame - gem_helper.rb
- include libx32 dirs (mostly x32 vendorarch) when generating perl dependencies
[packages/rpm.git] / gem_helper.rb
CommitLineData
63194730
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
8require 'optparse'
b56af183 9require 'rubygems'
63194730 10
d2eb086f
ER
11# Write the .gemspec specification (in Ruby)
12def writespec(spec)
13 file_name = spec.full_name.untaint + '.gemspec'
14 File.open(file_name, "w") do |file|
15 file.puts spec.to_ruby_for_cache
16 end
17 print "Wrote: %s\n" % file_name
18end
19
20# make gemspec self-contained
21if ARGV[0] == "spec-dump"
22 spec = eval(File.read(ARGV[1]))
23 writespec(spec)
24 exit(0)
25end
26
b56af183 27if ARGV[0] == "build" or ARGV[0] == "install" or ARGV[0] == "spec"
63194730
ER
28 require 'yaml'
29 require 'zlib'
30
31 filter = nil
32 opts = nil
33 keepcache = false
34 fixperms = false
35 gemdir = nil
36 dry_run = false
37 files = []
38 argv = ARGV[1..-1]
39 # Push this into some environment variables as the modified classes doesn't
40 # seem to be able to access our global variables.. </lameworkaround>
41 ENV['GEM_MODE'] = ARGV[0]
42 if ARGV[0] == "build"
43 opts = OptionParser.new("#{$0} <--filter PATTERN>")
44 opts.on("-f", "--filter PATTERN", "Filter pattern to use for gem files") do |val|
45 filter = val
46 end
47 opts.on("-j", "--jobs JOBS", "Number of jobs to run simultaneously.") do |val|
48 ENV['jobs'] = "-j"+val
49 end
50 opts.on("--dry-run", "Only show the files the gem will include") do
51 ARGV.delete("--dry-run")
52 dry_run = true
53 end
54 elsif ARGV[0] == "install"
55 opts = OptionParser.new("#{$0} <--keep-cache>")
56 opts.on("--keep-cache", "Don't delete gem copy from cache") do
57 ARGV.delete("--keep-cache")
58 keepcache = true
59 end
60 opts.on("--fix-permissions", "Force standard permissions for files installed") do
61 ARGV.delete("--fix-permissions")
62 fixperms = true
63 end
64 opts.on("-i", "--install-dir GEMDIR", "Gem repository directory") do |val|
65 gemdir = val
66 end
67 end
68 while argv.length > 0
69 begin
70 opts.parse!(argv)
71 rescue OptionParser::InvalidOption => e
72 e.recover(argv)
73 end
74 argv.delete_at(0)
75 end
76
070ae9e2 77 file_data = Zlib::GzipReader.open("metadata.gz") {|io| io.read}
63194730 78 header = YAML::load(file_data)
070ae9e2
ER
79 body = {}
80 # I don't know any better.. :/
81 header.instance_variables.each do |iv|
31f2334b 82 body[iv.to_s.sub(/^@/,'')] = header.instance_variable_get(iv)
070ae9e2 83 end
63194730 84
63194730
ER
85 spec = Gem::Specification.from_yaml(YAML.dump(header))
86
b56af183 87 if ARGV[0] == "spec"
d2eb086f 88 writespec(spec)
b56af183
ER
89 exit(0)
90 end
91
63194730
ER
92 if ARGV[0] == "install"
93 system("gem %s %s.gem" % [ARGV.join(' '), spec.full_name])
94 if !keepcache
95 require 'fileutils'
96 FileUtils.rm_rf("%s/cache" % gemdir)
97 end
98 if fixperms
99 chmod = "chmod u+r,u+w,g-w,g+r,o+r -R %s" % gemdir
100 print "\nFixing permissions:\n\n%s\n" % chmod
101 system("%s" % chmod)
102 print "\n"
103 end
104 end
105
106 if body['extensions'].size > 0
107 require 'rubygems/ext'
108 module Gem::Ext
109 class Builder
110 def self.make(dest_path, results)
111 make_program = ENV['make']
112 unless make_program then
113 make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
114 end
115 cmd = make_program
116 if ENV['GEM_MODE'] == "build"
117 cmd += " %s" % ENV['jobs']
118 elsif ENV['GEM_MODE'] == "install"
119 cmd += " DESTDIR='%s' install" % ENV['DESTDIR']
120 end
121 results << cmd
122 results << `#{cmd} #{redirector}`
123
124 raise Gem::ExtensionBuildError, "make failed:\n\n#{results}" unless
125 $?.success?
126 end
127 end
128 end
129
130 require 'rubygems/installer'
131 module Gem
132 class Installer
133 def initialize(spec, options={})
134 @gem_dir = Dir.pwd
135 @spec = spec
136 end
137 end
138 class ConfigFile
139 def really_verbose
140 true
141 end
142 end
143 end
144
145 unless dry_run
146 Gem::Installer.new(spec).build_extensions
147 else
148 for ext in body['extensions']
149 files.push(ext[0..ext.rindex("/")-1]+".so")
150 end
151 end
152
153 body['extensions'].clear()
154 end
155 if ARGV[0] == "build"
156 body['test_files'].clear()
157
158 # We don't want ext/ in require_paths, it will only contain content for
159 # building extensions which needs to be installed in sitearchdir anyways..
160 idx = 0
161 for i in 0..body['require_paths'].size()-1
162 if body['require_paths'][idx].match("^ext(/|$)")
163 body['require_paths'].delete_at(idx)
164 else
165 idx += 1
166 end
167 end
168
169 # We'll get rid of all the files we don't really need to install
170 idx = 0
171 for i in 0..body['files'].size()-1
172 if filter and body['files'][idx].match(filter)
173 match = true
174 else
175 match = false
176 for path in body['require_paths']
177 if body['files'][idx].match("^%s/" % path)
178 match = true
179 end
180 end
181 end
182 if !match
183 body['files'].delete_at(idx)
184 else
185 idx += 1
186 end
187 end
188
189 spec = Gem::Specification.from_yaml(YAML.dump(header))
190 unless dry_run
191 Gem::Builder.new(spec).build
192 else
193 files.concat(spec.files)
194 print "%s\n" % files.join("\n")
195 end
196 end
197end
This page took 0.058602 seconds and 4 git commands to generate.