2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
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.
|
|
|
|
#++
|
|
|
|
|
2013-02-28 17:25:55 -05:00
|
|
|
require 'fileutils'
|
2013-03-02 11:14:32 -05:00
|
|
|
require 'tempfile'
|
2018-10-30 23:23:30 -04:00
|
|
|
require 'shellwords'
|
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
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
def self.build(extension, dest_path, results, args=[], lib_dir=nil)
|
2016-02-01 07:43:26 -05:00
|
|
|
tmp_dest = Dir.mktmpdir(".gem.", ".")
|
|
|
|
|
|
|
|
# Some versions of `mktmpdir` return absolute paths, which will break make
|
|
|
|
# if the paths contain spaces. However, on Ruby 1.9.x on Windows, relative
|
|
|
|
# paths cause all C extension builds to fail.
|
|
|
|
#
|
|
|
|
# As such, we convert to a relative path unless we are using Ruby 1.9.x on
|
|
|
|
# Windows. This means that when using Ruby 1.9.x on Windows, paths with
|
|
|
|
# spaces do not work.
|
|
|
|
#
|
|
|
|
# Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940
|
2018-05-30 09:01:35 -04:00
|
|
|
tmp_dest = get_relative_path(tmp_dest)
|
2013-03-04 01:33:48 -05:00
|
|
|
|
2013-03-04 22:31:28 -05:00
|
|
|
Tempfile.open %w"siteconf .rb", "." do |siteconf|
|
|
|
|
siteconf.puts "require 'rbconfig'"
|
2014-09-13 23:30:02 -04:00
|
|
|
siteconf.puts "dest_path = #{tmp_dest.dump}"
|
2013-03-02 11:14:32 -05:00
|
|
|
%w[sitearchdir sitelibdir].each do |dir|
|
2013-03-04 22:31:28 -05:00
|
|
|
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
|
|
|
|
siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
|
2013-02-28 17:25:55 -05:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2017-05-16 01:47:53 -04:00
|
|
|
siteconf.close
|
2013-03-04 22:31:28 -05:00
|
|
|
|
|
|
|
destdir = ENV["DESTDIR"]
|
|
|
|
|
|
|
|
begin
|
2018-10-30 23:23:30 -04:00
|
|
|
cmd = Gem.ruby.shellsplit << "-I" << File.expand_path("../../..", __FILE__) <<
|
|
|
|
"-r" << get_relative_path(siteconf.path) << File.basename(extension)
|
|
|
|
cmd.push(*args)
|
2013-03-02 11:14:32 -05:00
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
begin
|
|
|
|
run cmd, results
|
|
|
|
ensure
|
2015-07-01 17:50:14 -04:00
|
|
|
if File.exist? 'mkmf.log'
|
2017-01-23 21:38:57 -05:00
|
|
|
unless $?.success? then
|
|
|
|
results << "To see why this extension failed to compile, please check" \
|
|
|
|
" the mkmf.log which can be found here:\n"
|
|
|
|
results << " " + File.join(dest_path, 'mkmf.log') + "\n"
|
|
|
|
end
|
2015-07-01 17:50:14 -04:00
|
|
|
FileUtils.mv 'mkmf.log', dest_path
|
|
|
|
end
|
2014-05-26 10:36:36 -04:00
|
|
|
siteconf.unlink
|
2014-02-03 19:48:31 -05:00
|
|
|
end
|
2013-03-02 11:14:32 -05:00
|
|
|
|
2013-03-04 22:31:28 -05:00
|
|
|
ENV["DESTDIR"] = nil
|
2013-03-04 20:06:08 -05:00
|
|
|
|
2013-03-04 22:31:28 -05:00
|
|
|
make dest_path, results
|
2013-03-02 11:14:32 -05:00
|
|
|
|
2013-03-04 22:31:28 -05:00
|
|
|
if tmp_dest
|
2013-12-01 15:52:57 -05:00
|
|
|
# TODO remove in RubyGems 3
|
2013-12-16 15:18:29 -05:00
|
|
|
if Gem.install_extension_in_lib and lib_dir then
|
2013-12-01 15:52:57 -05:00
|
|
|
FileUtils.mkdir_p lib_dir
|
|
|
|
entries = Dir.entries(tmp_dest) - %w[. ..]
|
|
|
|
entries = entries.map { |entry| File.join tmp_dest, entry }
|
2014-12-06 19:53:01 -05:00
|
|
|
FileUtils.cp_r entries, lib_dir, :remove_destination => true
|
2013-12-01 15:52:57 -05:00
|
|
|
end
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2013-12-01 15:52:57 -05:00
|
|
|
FileEntry.new(tmp_dest).traverse do |ent|
|
2013-03-04 22:31:28 -05:00
|
|
|
destent = ent.class.new(dest_path, ent.rel)
|
2014-09-13 23:30:02 -04:00
|
|
|
destent.exist? or FileUtils.mv(ent.path, destent.path)
|
2013-03-04 22:31:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
ENV["DESTDIR"] = destdir
|
2017-05-16 01:47:53 -04:00
|
|
|
siteconf.close!
|
2013-03-04 01:33:48 -05:00
|
|
|
end
|
|
|
|
end
|
2013-07-22 18:46:50 -04:00
|
|
|
|
|
|
|
results
|
2013-03-02 11:14:32 -05:00
|
|
|
ensure
|
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
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
private
|
|
|
|
def self.get_relative_path(path)
|
|
|
|
path[0..Dir.pwd.length-1] = '.' if path.start_with?(Dir.pwd)
|
|
|
|
path
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|