Update to ruby/spec@2a047c8
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ab55cd9fb5
commit
2531a1013b
@ -62,16 +62,18 @@ describe "CApiModule" do
|
|||||||
mod = @m.rb_define_module_under(CApiModuleSpecs, "ModuleSpecsModuleUnder2")
|
mod = @m.rb_define_module_under(CApiModuleSpecs, "ModuleSpecsModuleUnder2")
|
||||||
mod.name.should == "CApiModuleSpecs::ModuleSpecsModuleUnder2"
|
mod.name.should == "CApiModuleSpecs::ModuleSpecsModuleUnder2"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "rb_define_module_under" do
|
||||||
|
before :each do
|
||||||
|
compile_extension("module_under_autoload")
|
||||||
|
end
|
||||||
|
|
||||||
it "defines a module for an existing Autoload with an extension" do
|
it "defines a module for an existing Autoload with an extension" do
|
||||||
compile_extension("module_under_autoload")
|
|
||||||
|
|
||||||
CApiModuleSpecs::ModuleUnderAutoload.name.should == "CApiModuleSpecs::ModuleUnderAutoload"
|
CApiModuleSpecs::ModuleUnderAutoload.name.should == "CApiModuleSpecs::ModuleUnderAutoload"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "defines a module for an existing Autoload with a ruby object" do
|
it "defines a module for an existing Autoload with a ruby object" do
|
||||||
compile_extension("module_under_autoload")
|
|
||||||
|
|
||||||
CApiModuleSpecs::RubyUnderAutoload.name.should == "CApiModuleSpecs::RubyUnderAutoload"
|
CApiModuleSpecs::RubyUnderAutoload.name.should == "CApiModuleSpecs::RubyUnderAutoload"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
require File.expand_path('../../../spec_helper', __FILE__)
|
require File.expand_path('../../../spec_helper', __FILE__)
|
||||||
$extmk = false
|
|
||||||
|
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
|
|
||||||
@ -15,130 +14,59 @@ def object_path
|
|||||||
end
|
end
|
||||||
|
|
||||||
def compile_extension(name)
|
def compile_extension(name)
|
||||||
preloadenv = RbConfig::CONFIG["PRELOADENV"] || "LD_PRELOAD"
|
debug = false
|
||||||
preload, ENV[preloadenv] = ENV[preloadenv], nil if preloadenv
|
run_mkmf_in_process = false
|
||||||
|
|
||||||
path = extension_path
|
if RUBY_NAME == 'truffleruby'
|
||||||
objdir = object_path
|
run_mkmf_in_process = true
|
||||||
|
|
||||||
# TODO use rakelib/ext_helper.rb?
|
|
||||||
arch_hdrdir = nil
|
|
||||||
|
|
||||||
if RUBY_NAME == 'rbx'
|
|
||||||
hdrdir = RbConfig::CONFIG["rubyhdrdir"]
|
|
||||||
elsif RUBY_NAME =~ /^ruby/
|
|
||||||
hdrdir = RbConfig::CONFIG["rubyhdrdir"]
|
|
||||||
arch_hdrdir = RbConfig::CONFIG["rubyarchhdrdir"]
|
|
||||||
elsif RUBY_NAME == 'jruby'
|
|
||||||
require 'mkmf'
|
|
||||||
hdrdir = $hdrdir
|
|
||||||
elsif RUBY_NAME == "maglev"
|
|
||||||
require 'mkmf'
|
|
||||||
hdrdir = $hdrdir
|
|
||||||
elsif RUBY_NAME == 'truffleruby'
|
|
||||||
return compile_truffleruby_extconf_make(name, path, objdir)
|
|
||||||
else
|
|
||||||
raise "Don't know how to build C extensions with #{RUBY_NAME}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ext = "#{name}_spec"
|
|
||||||
source = File.join(path, "#{ext}.c")
|
|
||||||
obj = File.join(objdir, "#{ext}.#{RbConfig::CONFIG['OBJEXT']}")
|
|
||||||
lib = File.join(objdir, "#{ext}.#{RbConfig::CONFIG['DLEXT']}")
|
|
||||||
|
|
||||||
ruby_header = File.join(hdrdir, "ruby.h")
|
|
||||||
rubyspec_header = File.join(path, "rubyspec.h")
|
|
||||||
|
|
||||||
return lib if File.exist?(lib) and File.mtime(lib) > File.mtime(source) and
|
|
||||||
File.mtime(lib) > File.mtime(ruby_header) and
|
|
||||||
File.mtime(lib) > File.mtime(rubyspec_header) and
|
|
||||||
true # sentinel
|
|
||||||
|
|
||||||
# avoid problems where compilation failed but previous shlib exists
|
|
||||||
File.delete lib if File.exist? lib
|
|
||||||
|
|
||||||
cc = RbConfig::CONFIG["CC"]
|
|
||||||
cflags = (ENV["CFLAGS"] || RbConfig::CONFIG["CFLAGS"]).dup
|
|
||||||
cflags += " #{RbConfig::CONFIG["ARCH_FLAG"]}" if RbConfig::CONFIG["ARCH_FLAG"]
|
|
||||||
cflags += " #{RbConfig::CONFIG["CCDLFLAGS"]}" if RbConfig::CONFIG["CCDLFLAGS"]
|
|
||||||
cppflags = (ENV["CPPFLAGS"] || RbConfig::CONFIG["CPPFLAGS"]).dup
|
|
||||||
incflags = "-I#{path}"
|
|
||||||
incflags << " -I#{arch_hdrdir}" if arch_hdrdir
|
|
||||||
incflags << " -I#{hdrdir}"
|
|
||||||
csrcflag = RbConfig::CONFIG["CSRCFLAG"]
|
|
||||||
coutflag = RbConfig::CONFIG["COUTFLAG"]
|
|
||||||
|
|
||||||
compile_cmd = "#{cc} #{incflags} #{cflags} #{cppflags} #{coutflag}#{obj} -c #{csrcflag}#{source}"
|
|
||||||
output = `#{compile_cmd}`
|
|
||||||
|
|
||||||
unless $?.success? and File.exist?(obj)
|
|
||||||
puts "\nERROR:\n#{compile_cmd}\n#{output}"
|
|
||||||
puts "incflags=#{incflags}"
|
|
||||||
puts "cflags=#{cflags}"
|
|
||||||
puts "cppflags=#{cppflags}"
|
|
||||||
raise "Unable to compile \"#{source}\""
|
|
||||||
end
|
|
||||||
|
|
||||||
ldshared = RbConfig::CONFIG["LDSHARED"]
|
|
||||||
ldshared += " #{RbConfig::CONFIG["ARCH_FLAG"]}" if RbConfig::CONFIG["ARCH_FLAG"]
|
|
||||||
libs = RbConfig::CONFIG["LIBS"]
|
|
||||||
dldflags = "#{RbConfig::CONFIG["LDFLAGS"]} #{RbConfig::CONFIG["DLDFLAGS"]} #{RbConfig::CONFIG["EXTDLDFLAGS"]}"
|
|
||||||
dldflags.sub!(/-Wl,-soname,\S+/, '')
|
|
||||||
|
|
||||||
if /mswin/ =~ RUBY_PLATFORM
|
|
||||||
dldflags.sub!("$(LIBPATH)", RbConfig::CONFIG["LIBPATHFLAG"] % path)
|
|
||||||
libs += RbConfig::CONFIG["LIBRUBY"]
|
|
||||||
outflag = RbConfig::CONFIG["OUTFLAG"]
|
|
||||||
|
|
||||||
link_cmd = "#{ldshared} #{outflag}#{lib} #{obj} #{libs} -link #{dldflags} /export:Init_#{ext}"
|
|
||||||
else
|
|
||||||
libpath = "-L#{path}"
|
|
||||||
dldflags.sub!("$(TARGET_ENTRY)", "Init_#{ext}")
|
|
||||||
|
|
||||||
link_cmd = "#{ldshared} #{obj} #{libpath} #{dldflags} #{libs} -o #{lib}"
|
|
||||||
end
|
|
||||||
output = `#{link_cmd}`
|
|
||||||
|
|
||||||
unless $?.success?
|
|
||||||
puts "\nERROR:\n#{link_cmd}\n#{output}"
|
|
||||||
raise "Unable to link \"#{source}\""
|
|
||||||
end
|
|
||||||
|
|
||||||
lib
|
|
||||||
ensure
|
|
||||||
ENV[preloadenv] = preload if preloadenv
|
|
||||||
end
|
|
||||||
|
|
||||||
def compile_truffleruby_extconf_make(name, path, objdir)
|
|
||||||
ext = "#{name}_spec"
|
ext = "#{name}_spec"
|
||||||
file = "#{ext}.c"
|
source = "#{extension_path}/#{ext}.c"
|
||||||
source = "#{path}/#{ext}.c"
|
lib = "#{object_path}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"
|
||||||
lib = "#{objdir}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"
|
ruby_header = "#{RbConfig::CONFIG['rubyhdrdir']}/ruby.h"
|
||||||
|
|
||||||
|
return lib if File.exist?(lib) and
|
||||||
|
File.mtime(lib) > File.mtime(source) and
|
||||||
|
File.mtime(lib) > File.mtime(ruby_header) and
|
||||||
|
File.mtime(lib) > File.mtime("#{extension_path}/rubyspec.h") and
|
||||||
|
true # sentinel
|
||||||
|
|
||||||
# Copy needed source files to tmpdir
|
# Copy needed source files to tmpdir
|
||||||
tmpdir = tmp("cext_#{name}")
|
tmpdir = tmp("cext_#{name}")
|
||||||
Dir.mkdir tmpdir
|
Dir.mkdir(tmpdir)
|
||||||
begin
|
begin
|
||||||
["rubyspec.h", "truffleruby.h", "#{ext}.c"].each do |file|
|
["jruby.h", "rubinius.h", "truffleruby.h", "rubyspec.h", "#{ext}.c"].each do |file|
|
||||||
cp "#{path}/#{file}", "#{tmpdir}/#{file}"
|
cp "#{extension_path}/#{file}", "#{tmpdir}/#{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir(tmpdir) do
|
Dir.chdir(tmpdir) do
|
||||||
required = require 'mkmf'
|
if run_mkmf_in_process
|
||||||
# Reinitialize mkmf if already required
|
required = require 'mkmf'
|
||||||
init_mkmf unless required
|
# Reinitialize mkmf if already required
|
||||||
create_makefile(ext, tmpdir)
|
init_mkmf unless required
|
||||||
system "make"
|
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
|
||||||
|
|
||||||
copy_exts = RbConfig::CONFIG.values_at('OBJEXT', 'DLEXT')
|
output = `make V=1 TARGET_SO_DIR=./`
|
||||||
Dir.glob("*.{#{copy_exts.join(',')}}") do |file|
|
raise "make failed:\n#{output}" unless $?.success?
|
||||||
cp file, "#{objdir}/#{file}"
|
$stderr.puts output if debug
|
||||||
|
|
||||||
|
Dir.glob("*.#{RbConfig::CONFIG['DLEXT']}") do |file|
|
||||||
|
cp file, "#{object_path}/#{file}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
rm_r tmpdir
|
rm_r tmpdir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
File.chmod(0755, lib)
|
||||||
lib
|
lib
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user