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).
11 # Write the .gemspec specification (in Ruby)
13 file_name = spec.full_name.untaint + '.gemspec'
14 File.open(file_name, "w") do |file|
15 file.puts spec.to_ruby_for_cache
17 print "Wrote: %s\n" % file_name
20 # make gemspec self-contained
21 if ARGV[0] == "spec-dump"
22 spec = eval(File.read(ARGV[1]))
27 if ARGV[0] == "build" or ARGV[0] == "install" or ARGV[0] == "spec"
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]
43 opts = OptionParser.new("#{$0} <--filter PATTERN>")
44 opts.on("-f", "--filter PATTERN", "Filter pattern to use for gem files") do |val|
47 opts.on("-j", "--jobs JOBS", "Number of jobs to run simultaneously.") do |val|
48 ENV['jobs'] = "-j"+val
50 opts.on("--dry-run", "Only show the files the gem will include") do
51 ARGV.delete("--dry-run")
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")
60 opts.on("--fix-permissions", "Force standard permissions for files installed") do
61 ARGV.delete("--fix-permissions")
64 opts.on("-i", "--install-dir GEMDIR", "Gem repository directory") do |val|
71 rescue OptionParser::InvalidOption => e
77 file_data = Zlib::GzipReader.open("metadata.gz") {|io| io.read}
78 header = YAML::load(file_data)
80 # I don't know any better.. :/
81 header.instance_variables.each do |iv|
82 body[iv.to_s.sub(/^@/,'')] = header.instance_variable_get(iv)
85 spec = Gem::Specification.from_yaml(YAML.dump(header))
92 if ARGV[0] == "install"
93 system("gem %s %s.gem" % [ARGV.join(' '), spec.full_name])
96 FileUtils.rm_rf("%s/cache" % gemdir)
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
106 if body['extensions'].size > 0
107 require 'rubygems/ext'
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'
116 if ENV['GEM_MODE'] == "build"
117 cmd += " %s" % ENV['jobs']
118 elsif ENV['GEM_MODE'] == "install"
119 cmd += " DESTDIR='%s' install" % ENV['DESTDIR']
122 results << `#{cmd} #{redirector}`
124 raise Gem::ExtensionBuildError, "make failed:\n\n#{results}" unless
130 require 'rubygems/installer'
133 def initialize(spec, options={})
146 Gem::Installer.new(spec).build_extensions
148 for ext in body['extensions']
149 files.push(ext[0..ext.rindex("/")-1]+".so")
153 body['extensions'].clear()
155 if ARGV[0] == "build"
156 body['test_files'].clear()
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..
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)
169 # We'll get rid of all the files we don't really need to install
171 for i in 0..body['files'].size()-1
172 if filter and body['files'][idx].match(filter)
176 for path in body['require_paths']
177 if body['files'][idx].match("^%s/" % path)
183 body['files'].delete_at(idx)
189 spec = Gem::Specification.from_yaml(YAML.dump(header))
191 Gem::Builder.new(spec).build
193 files.concat(spec.files)
194 print "%s\n" % files.join("\n")