2015-12-16 08:07:31 +03:00
|
|
|
# frozen_string_literal: false
|
2013-07-04 11:03:07 +04:00
|
|
|
$extmk = true
|
2018-11-17 04:42:30 +03:00
|
|
|
require 'rbconfig'
|
|
|
|
RbConfig.fire_update!("top_srcdir", File.expand_path("../..", __dir__))
|
|
|
|
File.foreach(RbConfig::CONFIG["topdir"]+"/Makefile") do |line|
|
|
|
|
if /^CC_WRAPPER\s*=\s*/ =~ line
|
|
|
|
RbConfig.fire_update!('CC_WRAPPER', $'.strip)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2013-07-04 11:03:07 +04:00
|
|
|
|
2009-08-06 08:14:50 +04:00
|
|
|
require 'test/unit'
|
|
|
|
require 'mkmf'
|
|
|
|
require 'tmpdir'
|
|
|
|
|
|
|
|
$extout = '$(topdir)/'+RbConfig::CONFIG["EXTOUT"]
|
|
|
|
RbConfig::CONFIG['topdir'] = CONFIG['topdir'] = File.expand_path(CONFIG['topdir'])
|
|
|
|
RbConfig::CONFIG["extout"] = CONFIG["extout"] = $extout
|
2009-11-26 05:42:24 +03:00
|
|
|
$INCFLAGS << " -I."
|
2009-08-06 08:14:50 +04:00
|
|
|
$extout_prefix = "$(extout)$(target_prefix)/"
|
|
|
|
|
2013-03-11 16:12:15 +04:00
|
|
|
class TestMkmf < Test::Unit::TestCase
|
2015-02-05 07:50:18 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
module TestMkmf::Base
|
2010-12-10 12:11:10 +03:00
|
|
|
MKMFLOG = proc {File.read("mkmf.log") rescue ""}
|
2010-12-17 13:35:20 +03:00
|
|
|
|
|
|
|
class Capture
|
2012-05-08 10:50:05 +04:00
|
|
|
attr_accessor :origin
|
2010-12-17 13:35:20 +03:00
|
|
|
def initialize
|
|
|
|
@buffer = ""
|
|
|
|
@filter = nil
|
|
|
|
@out = true
|
2012-05-08 10:50:05 +04:00
|
|
|
@origin = nil
|
2010-12-17 13:35:20 +03:00
|
|
|
end
|
|
|
|
def clear
|
|
|
|
@buffer.clear
|
|
|
|
end
|
|
|
|
def flush
|
|
|
|
STDOUT.print @filter ? @filter.call(@buffer) : @buffer
|
|
|
|
clear
|
|
|
|
end
|
|
|
|
def reopen(io)
|
|
|
|
case io
|
|
|
|
when Capture
|
|
|
|
initialize_copy(io)
|
|
|
|
when File
|
|
|
|
@out = false
|
2012-05-08 10:50:05 +04:00
|
|
|
@origin.reopen(io) if @origin
|
2010-12-17 13:35:20 +03:00
|
|
|
when IO
|
|
|
|
@out = true
|
2012-05-08 10:50:05 +04:00
|
|
|
@origin.reopen(io) if @origin
|
2010-12-17 13:35:20 +03:00
|
|
|
else
|
|
|
|
@out = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def filter(&block)
|
|
|
|
@filter = block
|
|
|
|
end
|
2017-10-23 17:05:07 +03:00
|
|
|
def write(*s)
|
2015-11-04 04:31:15 +03:00
|
|
|
if @out
|
2017-10-23 17:05:07 +03:00
|
|
|
@buffer.concat(*s)
|
2015-11-04 04:31:15 +03:00
|
|
|
elsif @origin
|
2017-10-23 17:05:07 +03:00
|
|
|
@origin.write(*s)
|
2015-11-04 04:31:15 +03:00
|
|
|
end
|
2010-12-17 13:35:20 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :stdout
|
|
|
|
|
2010-12-10 12:11:48 +03:00
|
|
|
def mkmflog(msg)
|
2013-03-08 11:02:37 +04:00
|
|
|
proc {MKMFLOG[] << msg}
|
2010-12-10 12:11:48 +03:00
|
|
|
end
|
2010-12-10 12:11:10 +03:00
|
|
|
|
2009-08-06 08:14:50 +04:00
|
|
|
def setup
|
2011-01-15 05:57:36 +03:00
|
|
|
@rbconfig = rbconfig0 = RbConfig::CONFIG
|
|
|
|
@mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG
|
|
|
|
rbconfig = {
|
|
|
|
"hdrdir" => $hdrdir,
|
|
|
|
"srcdir" => $srcdir,
|
|
|
|
"topdir" => $topdir,
|
|
|
|
}
|
|
|
|
mkconfig = {
|
|
|
|
"hdrdir" => "$(top_srcdir)/include",
|
2012-04-03 18:30:08 +04:00
|
|
|
"srcdir" => "$(top_srcdir)",
|
2011-01-15 05:57:36 +03:00
|
|
|
"topdir" => $topdir,
|
|
|
|
}
|
|
|
|
rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup}
|
|
|
|
mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup}
|
|
|
|
RbConfig.module_eval {
|
|
|
|
remove_const(:CONFIG)
|
|
|
|
const_set(:CONFIG, rbconfig)
|
|
|
|
remove_const(:MAKEFILE_CONFIG)
|
|
|
|
const_set(:MAKEFILE_CONFIG, mkconfig)
|
|
|
|
}
|
2011-11-30 04:57:24 +04:00
|
|
|
MakeMakefile.class_eval {
|
2011-01-15 05:57:36 +03:00
|
|
|
remove_const(:CONFIG)
|
|
|
|
const_set(:CONFIG, mkconfig)
|
|
|
|
}
|
2009-08-06 08:14:50 +04:00
|
|
|
@tmpdir = Dir.mktmpdir
|
|
|
|
@curdir = Dir.pwd
|
|
|
|
@mkmfobj = Object.new
|
2015-02-05 07:50:18 +03:00
|
|
|
@stdout = Capture.new
|
2009-08-06 08:14:50 +04:00
|
|
|
Dir.chdir(@tmpdir)
|
2010-12-06 17:18:26 +03:00
|
|
|
@quiet, Logging.quiet = Logging.quiet, true
|
2011-01-15 05:57:36 +03:00
|
|
|
init_mkmf
|
|
|
|
$INCFLAGS[0, 0] = "-I. "
|
2009-08-06 08:14:50 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2011-01-15 05:57:36 +03:00
|
|
|
rbconfig0 = @rbconfig
|
|
|
|
mkconfig0 = @mkconfig
|
|
|
|
RbConfig.module_eval {
|
|
|
|
remove_const(:CONFIG)
|
|
|
|
const_set(:CONFIG, rbconfig0)
|
|
|
|
remove_const(:MAKEFILE_CONFIG)
|
|
|
|
const_set(:MAKEFILE_CONFIG, mkconfig0)
|
|
|
|
}
|
2011-11-30 04:57:24 +04:00
|
|
|
MakeMakefile.class_eval {
|
2011-01-15 05:57:36 +03:00
|
|
|
remove_const(:CONFIG)
|
|
|
|
const_set(:CONFIG, mkconfig0)
|
|
|
|
}
|
2010-12-06 17:18:26 +03:00
|
|
|
Logging.quiet = @quiet
|
2010-12-10 12:11:10 +03:00
|
|
|
Logging.log_close
|
2012-04-03 13:41:14 +04:00
|
|
|
FileUtils.rm_f("mkmf.log")
|
2009-08-06 08:14:50 +04:00
|
|
|
Dir.chdir(@curdir)
|
|
|
|
FileUtils.rm_rf(@tmpdir)
|
|
|
|
end
|
|
|
|
|
|
|
|
def mkmf(*args, &block)
|
2010-12-17 13:35:20 +03:00
|
|
|
@stdout.clear
|
2012-05-08 10:50:05 +04:00
|
|
|
stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout
|
2019-06-20 13:27:27 +03:00
|
|
|
verbose, $VERBOSE = $VERBOSE, false
|
2009-08-06 08:14:50 +04:00
|
|
|
@mkmfobj.instance_eval(*args, &block)
|
2010-12-17 13:35:20 +03:00
|
|
|
ensure
|
2019-06-20 13:27:27 +03:00
|
|
|
$VERBOSE = verbose
|
2012-05-08 10:50:05 +04:00
|
|
|
$stdout, @stdout.origin = @stdout.origin, stdout
|
2009-08-06 08:14:50 +04:00
|
|
|
end
|
2010-12-10 12:12:33 +03:00
|
|
|
|
|
|
|
def config_value(name)
|
|
|
|
create_tmpsrc("---config-value=#{name}")
|
|
|
|
xpopen(cpp_command('')) do |f|
|
|
|
|
f.grep(/^---config-value=(.*)/) {return $1}
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
2009-08-06 08:14:50 +04:00
|
|
|
end
|
2015-02-03 11:15:47 +03:00
|
|
|
|
|
|
|
class TestMkmf
|
|
|
|
include TestMkmf::Base
|
|
|
|
|
2019-04-08 02:55:34 +03:00
|
|
|
def assert_separately(args, src, *rest, **options)
|
|
|
|
super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\nEND{teardown}\n#{src}", *rest, **options)
|
2015-02-03 11:15:47 +03:00
|
|
|
end
|
|
|
|
end
|