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