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).
10 if ARGV[0] == "build" or ARGV[0] == "install"
22 # Push this into some environment variables as the modified classes doesn't
23 # seem to be able to access our global variables.. </lameworkaround>
24 ENV['GEM_MODE'] = ARGV[0]
26 opts = OptionParser.new("#{$0} <--filter PATTERN>")
27 opts.on("-f", "--filter PATTERN", "Filter pattern to use for gem files") do |val|
30 opts.on("-j", "--jobs JOBS", "Number of jobs to run simultaneously.") do |val|
31 ENV['jobs'] = "-j"+val
33 opts.on("--dry-run", "Only show the files the gem will include") do
34 ARGV.delete("--dry-run")
37 elsif ARGV[0] == "install"
38 opts = OptionParser.new("#{$0} <--keep-cache>")
39 opts.on("--keep-cache", "Don't delete gem copy from cache") do
40 ARGV.delete("--keep-cache")
43 opts.on("--fix-permissions", "Force standard permissions for files installed") do
44 ARGV.delete("--fix-permissions")
47 opts.on("-i", "--install-dir GEMDIR", "Gem repository directory") do |val|
54 rescue OptionParser::InvalidOption => e
60 file_data = Zlib::GzipReader.open("metadata.gz")
61 header = YAML::load(file_data)
63 body = header.instance_variable_get :@ivars
66 spec = Gem::Specification.from_yaml(YAML.dump(header))
68 if ARGV[0] == "install"
69 system("gem %s %s.gem" % [ARGV.join(' '), spec.full_name])
72 FileUtils.rm_rf("%s/cache" % gemdir)
75 chmod = "chmod u+r,u+w,g-w,g+r,o+r -R %s" % gemdir
76 print "\nFixing permissions:\n\n%s\n" % chmod
82 if body['extensions'].size > 0
83 require 'rubygems/ext'
86 def self.make(dest_path, results)
87 make_program = ENV['make']
88 unless make_program then
89 make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
92 if ENV['GEM_MODE'] == "build"
93 cmd += " %s" % ENV['jobs']
94 elsif ENV['GEM_MODE'] == "install"
95 cmd += " DESTDIR='%s' install" % ENV['DESTDIR']
98 results << `#{cmd} #{redirector}`
100 raise Gem::ExtensionBuildError, "make failed:\n\n#{results}" unless
106 require 'rubygems/installer'
109 def initialize(spec, options={})
122 Gem::Installer.new(spec).build_extensions
124 for ext in body['extensions']
125 files.push(ext[0..ext.rindex("/")-1]+".so")
129 body['extensions'].clear()
131 if ARGV[0] == "build"
132 body['test_files'].clear()
134 # We don't want ext/ in require_paths, it will only contain content for
135 # building extensions which needs to be installed in sitearchdir anyways..
137 for i in 0..body['require_paths'].size()-1
138 if body['require_paths'][idx].match("^ext(/|$)")
139 body['require_paths'].delete_at(idx)
145 # We'll get rid of all the files we don't really need to install
147 for i in 0..body['files'].size()-1
148 if filter and body['files'][idx].match(filter)
152 for path in body['require_paths']
153 if body['files'][idx].match("^%s/" % path)
159 body['files'].delete_at(idx)
165 spec = Gem::Specification.from_yaml(YAML.dump(header))
167 Gem::Builder.new(spec).build
169 files.concat(spec.files)
170 print "%s\n" % files.join("\n")