aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/ext/ext_conf_builder.rb
blob: 3a439af5022629484b9e9dd4391896f018c975b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

require 'rubygems/ext/builder'
require 'rubygems/command'
require 'fileutils'
require 'tmpdir'

class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder

  def self.build(extension, directory, dest_path, results, args=[])
    pwd = Dir.pwd
    cmd = "#{Gem.ruby} -r./siteconf #{File.join pwd, File.basename(extension)}"
    cmd << " #{args.join ' '}" unless args.empty?

    Dir.mktmpdir("gem-install.") do |tmpdir|
      Dir.chdir(tmpdir) do
        open("siteconf.rb", "w") do |f|
          f.puts "require 'rbconfig'"
          f.puts "dest_path = #{dest_path.dump}"
          %w[sitearchdir sitelibdir].each do |dir|
            f.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
            f.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
          end
        end

        begin
          run cmd, results

          make dest_path, results
        ensure
          FileUtils.mv("mkmf.log", pwd) if $! and File.exist?("mkmf.log")
        end
      end
    end

    results
  end

end