2007-11-10 07:48:56 +00: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 21:38:59 +00:00
|
|
|
require 'rubygems/command'
|
2013-02-28 22:25:55 +00:00
|
|
|
require 'fileutils'
|
2013-03-02 16:14:32 +00:00
|
|
|
require 'tempfile'
|
2007-11-10 07:48:56 +00:00
|
|
|
|
|
|
|
class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
|
2013-03-04 06:33:48 +00:00
|
|
|
FileEntry = FileUtils::Entry_ # :nodoc:
|
2013-03-02 16:17:22 +00:00
|
|
|
|
2012-11-29 06:52:18 +00:00
|
|
|
def self.build(extension, directory, dest_path, results, args=[])
|
2013-03-10 14:27:56 +00:00
|
|
|
tmp_dest = Dir.mktmpdir(".gem.", ".")
|
2013-03-04 06:33:48 +00:00
|
|
|
|
2013-03-05 03:31:28 +00:00
|
|
|
Tempfile.open %w"siteconf .rb", "." do |siteconf|
|
|
|
|
siteconf.puts "require 'rbconfig'"
|
|
|
|
siteconf.puts "dest_path = #{(tmp_dest || dest_path).dump}"
|
2013-03-02 16:14:32 +00:00
|
|
|
%w[sitearchdir sitelibdir].each do |dir|
|
2013-03-05 03:31:28 +00:00
|
|
|
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
|
|
|
|
siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
|
2013-02-28 22:25:55 +00:00
|
|
|
end
|
2007-11-10 07:48:56 +00:00
|
|
|
|
2013-03-05 03:31:28 +00:00
|
|
|
siteconf.flush
|
|
|
|
|
2013-03-11 21:29:32 +00:00
|
|
|
siteconf_path = File.expand_path siteconf.path
|
|
|
|
|
2013-03-05 03:31:28 +00:00
|
|
|
rubyopt = ENV["RUBYOPT"]
|
|
|
|
destdir = ENV["DESTDIR"]
|
|
|
|
|
|
|
|
begin
|
2013-03-11 21:29:32 +00:00
|
|
|
ENV["RUBYOPT"] = ["-r#{siteconf_path}", rubyopt].compact.join(' ')
|
2013-03-05 03:31:28 +00:00
|
|
|
cmd = [Gem.ruby, File.basename(extension), *args].join ' '
|
2013-03-02 16:14:32 +00:00
|
|
|
|
2013-03-05 03:31:28 +00:00
|
|
|
run cmd, results
|
2013-03-02 16:14:32 +00:00
|
|
|
|
2013-03-05 03:31:28 +00:00
|
|
|
ENV["DESTDIR"] = nil
|
2013-03-05 01:06:08 +00:00
|
|
|
|
2013-03-05 03:31:28 +00:00
|
|
|
make dest_path, results
|
2013-03-02 16:14:32 +00:00
|
|
|
|
2013-03-05 03:31:28 +00: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
|
|
|
|
|
|
|
|
results
|
|
|
|
ensure
|
|
|
|
ENV["RUBYOPT"] = rubyopt
|
|
|
|
ENV["DESTDIR"] = destdir
|
2013-03-04 06:33:48 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-02 16:14:32 +00:00
|
|
|
ensure
|
2013-03-04 06:33:48 +00:00
|
|
|
FileUtils.rm_rf tmp_dest if tmp_dest
|
2007-11-10 07:48:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|