2007-11-10 02:48:56 -05:00
|
|
|
#--
|
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
|
|
|
#++
|
|
|
|
|
|
|
|
require 'rubygems/ext/builder'
|
2009-06-09 17:38:59 -04:00
|
|
|
require 'rubygems/command'
|
2013-02-28 17:25:55 -05:00
|
|
|
require 'fileutils'
|
2013-03-02 11:14:32 -05:00
|
|
|
require 'tempfile'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
|
2013-03-04 01:33:48 -05:00
|
|
|
FileEntry = FileUtils::Entry_ # :nodoc:
|
2013-03-02 11:17:22 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def self.build(extension, directory, dest_path, results, args=[])
|
2013-03-04 01:33:48 -05:00
|
|
|
tmp_dest = (Dir.mktmpdir(".gem.", ".") if File.identical?(dest_path, "."))
|
|
|
|
|
2013-03-02 11:14:32 -05:00
|
|
|
siteconf = Tempfile.open(%w"siteconf .rb", ".") do |f|
|
|
|
|
f.puts "require 'rbconfig'"
|
2013-03-04 01:33:48 -05:00
|
|
|
f.puts "dest_path = #{(tmp_dest || dest_path).dump}"
|
2013-03-02 11:14:32 -05:00
|
|
|
%w[sitearchdir sitelibdir].each do |dir|
|
|
|
|
f.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
|
|
|
|
f.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
|
2013-02-28 17:25:55 -05:00
|
|
|
end
|
2013-03-02 11:14:32 -05:00
|
|
|
f
|
2013-02-28 17:25:55 -05:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2013-03-02 11:16:19 -05:00
|
|
|
rubyopt = ENV["RUBYOPT"]
|
|
|
|
ENV["RUBYOPT"] = ["-r#{siteconf.path}", rubyopt].compact.join(' ')
|
|
|
|
cmd = [Gem.ruby, File.basename(extension), *args].join ' '
|
2013-03-02 11:14:32 -05:00
|
|
|
|
|
|
|
run cmd, results
|
|
|
|
|
2013-03-04 20:06:08 -05:00
|
|
|
destdir = ENV["DESTDIR"]
|
|
|
|
ENV["DESTDIR"] = nil
|
|
|
|
|
2013-03-02 11:14:32 -05:00
|
|
|
make dest_path, results
|
|
|
|
|
2013-03-04 01:33:48 -05:00
|
|
|
if tmp_dest
|
|
|
|
FileEntry.new(tmp_dest).traverse do |ent|
|
|
|
|
destent = ent.class.new(dest_path, ent.rel)
|
|
|
|
destent.exist? or File.rename(ent.path, destent.path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
results
|
2013-03-02 11:14:32 -05:00
|
|
|
ensure
|
2013-03-02 11:16:19 -05:00
|
|
|
ENV["RUBYOPT"] = rubyopt
|
2013-03-04 20:06:08 -05:00
|
|
|
ENV["DESTDIR"] = destdir
|
2013-03-02 11:14:32 -05:00
|
|
|
siteconf.close(true) if siteconf
|
2013-03-04 01:33:48 -05:00
|
|
|
FileUtils.rm_rf tmp_dest if tmp_dest
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|