2017-05-07 08:04:49 -04:00
|
|
|
require File.expand_path('../../../spec_helper', __FILE__)
|
|
|
|
|
|
|
|
require 'rbconfig'
|
|
|
|
|
|
|
|
OBJDIR ||= File.expand_path("../../../ext/#{RUBY_NAME}/#{RUBY_VERSION}", __FILE__)
|
2017-05-14 10:09:56 -04:00
|
|
|
mkdir_p(OBJDIR)
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
def extension_path
|
|
|
|
File.expand_path("../ext", __FILE__)
|
|
|
|
end
|
|
|
|
|
|
|
|
def object_path
|
|
|
|
OBJDIR
|
|
|
|
end
|
|
|
|
|
|
|
|
def compile_extension(name)
|
2017-05-28 07:30:42 -04:00
|
|
|
debug = false
|
|
|
|
run_mkmf_in_process = false
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2017-05-28 07:30:42 -04:00
|
|
|
if RUBY_NAME == 'truffleruby'
|
|
|
|
run_mkmf_in_process = true
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2017-05-28 07:30:42 -04:00
|
|
|
ext = "#{name}_spec"
|
|
|
|
source = "#{extension_path}/#{ext}.c"
|
|
|
|
lib = "#{object_path}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"
|
|
|
|
ruby_header = "#{RbConfig::CONFIG['rubyhdrdir']}/ruby.h"
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2017-05-28 07:30:42 -04:00
|
|
|
return lib if File.exist?(lib) and
|
|
|
|
File.mtime(lib) > File.mtime(source) and
|
2017-05-07 08:04:49 -04:00
|
|
|
File.mtime(lib) > File.mtime(ruby_header) and
|
2017-05-28 07:30:42 -04:00
|
|
|
File.mtime(lib) > File.mtime("#{extension_path}/rubyspec.h") and
|
2017-05-07 08:04:49 -04:00
|
|
|
true # sentinel
|
|
|
|
|
2017-05-27 17:55:02 -04:00
|
|
|
# Copy needed source files to tmpdir
|
|
|
|
tmpdir = tmp("cext_#{name}")
|
2017-05-28 07:30:42 -04:00
|
|
|
Dir.mkdir(tmpdir)
|
2017-05-07 08:04:49 -04:00
|
|
|
begin
|
2017-05-28 07:30:42 -04:00
|
|
|
["jruby.h", "rubinius.h", "truffleruby.h", "rubyspec.h", "#{ext}.c"].each do |file|
|
|
|
|
cp "#{extension_path}/#{file}", "#{tmpdir}/#{file}"
|
2017-05-27 17:55:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Dir.chdir(tmpdir) do
|
2017-05-28 07:30:42 -04:00
|
|
|
if run_mkmf_in_process
|
|
|
|
required = require 'mkmf'
|
|
|
|
# Reinitialize mkmf if already required
|
|
|
|
init_mkmf unless required
|
|
|
|
create_makefile(ext, tmpdir)
|
|
|
|
else
|
|
|
|
File.write("extconf.rb", "require 'mkmf'\n" +
|
|
|
|
"create_makefile(#{ext.inspect})\n")
|
|
|
|
output = ruby_exe("extconf.rb")
|
|
|
|
raise "extconf failed:\n#{output}" unless $?.success?
|
|
|
|
$stderr.puts output if debug
|
|
|
|
end
|
|
|
|
|
|
|
|
output = `make V=1 TARGET_SO_DIR=./`
|
|
|
|
raise "make failed:\n#{output}" unless $?.success?
|
|
|
|
$stderr.puts output if debug
|
2017-05-27 17:55:02 -04:00
|
|
|
|
2017-05-28 07:30:42 -04:00
|
|
|
Dir.glob("*.#{RbConfig::CONFIG['DLEXT']}") do |file|
|
|
|
|
cp file, "#{object_path}/#{file}"
|
2017-05-27 17:55:02 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
ensure
|
2017-05-27 17:55:02 -04:00
|
|
|
rm_r tmpdir
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
2017-05-27 17:55:02 -04:00
|
|
|
|
2017-05-28 07:30:42 -04:00
|
|
|
File.chmod(0755, lib)
|
2017-05-27 17:55:02 -04:00
|
|
|
lib
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_extension(name)
|
|
|
|
require compile_extension(name)
|
|
|
|
rescue LoadError
|
|
|
|
if %r{/usr/sbin/execerror ruby "\(ld 3 1 main ([/a-zA-Z0-9_\-.]+_spec\.so)"} =~ $!.message
|
|
|
|
system('/usr/sbin/execerror', "#{RbConfig::CONFIG["bindir"]}/ruby", "(ld 3 1 main #{$1}")
|
|
|
|
end
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
|
|
|
|
# Constants
|
|
|
|
CAPI_SIZEOF_LONG = [0].pack('l!').size
|