2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-07-04 03:03:07 -04:00
|
|
|
$extmk = true
|
2018-11-16 20:42:30 -05: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 03:03:07 -04:00
|
|
|
|
2009-08-06 00: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-25 21:42:24 -05:00
|
|
|
$INCFLAGS << " -I."
|
2009-08-06 00:14:50 -04:00
|
|
|
$extout_prefix = "$(extout)$(target_prefix)/"
|
|
|
|
|
2013-03-11 08:12:15 -04:00
|
|
|
class TestMkmf < Test::Unit::TestCase
|
2022-04-22 16:01:43 -04:00
|
|
|
module Base
|
|
|
|
MKMFLOG = proc {File.read("mkmf.log") rescue ""}
|
2010-12-17 05:35:20 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
class Capture
|
|
|
|
attr_accessor :origin
|
|
|
|
def initialize
|
|
|
|
@buffer = ""
|
|
|
|
@filter = nil
|
2010-12-17 05:35:20 -05:00
|
|
|
@out = true
|
2022-04-22 16:01:43 -04:00
|
|
|
@origin = nil
|
2010-12-17 05:35:20 -05:00
|
|
|
end
|
2022-04-22 16:01:43 -04:00
|
|
|
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
|
|
|
|
@origin.reopen(io) if @origin
|
|
|
|
when IO
|
|
|
|
@out = true
|
|
|
|
@origin.reopen(io) if @origin
|
|
|
|
else
|
|
|
|
@out = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def filter(&block)
|
|
|
|
@filter = block
|
|
|
|
end
|
|
|
|
def write(*s)
|
|
|
|
if @out
|
|
|
|
@buffer.concat(*s)
|
|
|
|
elsif @origin
|
|
|
|
@origin.write(*s)
|
|
|
|
end
|
2015-11-03 20:31:15 -05:00
|
|
|
end
|
2010-12-17 05:35:20 -05:00
|
|
|
end
|
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
attr_reader :stdout
|
2010-12-17 05:35:20 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def mkmflog(msg)
|
|
|
|
proc {MKMFLOG[] << msg}
|
|
|
|
end
|
2010-12-10 04:11:10 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def setup
|
|
|
|
@rbconfig = rbconfig0 = RbConfig::CONFIG
|
|
|
|
@mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG
|
|
|
|
rbconfig = {
|
|
|
|
"hdrdir" => $hdrdir,
|
|
|
|
"srcdir" => $srcdir,
|
|
|
|
"topdir" => $topdir,
|
|
|
|
}
|
|
|
|
mkconfig = {
|
|
|
|
"hdrdir" => "$(top_srcdir)/include",
|
|
|
|
"srcdir" => "$(top_srcdir)",
|
|
|
|
"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)
|
|
|
|
}
|
|
|
|
MakeMakefile.class_eval {
|
|
|
|
remove_const(:CONFIG)
|
|
|
|
const_set(:CONFIG, mkconfig)
|
|
|
|
}
|
|
|
|
@tmpdir = Dir.mktmpdir
|
|
|
|
@curdir = Dir.pwd
|
|
|
|
@mkmfobj = Object.new
|
|
|
|
@stdout = Capture.new
|
|
|
|
Dir.chdir(@tmpdir)
|
|
|
|
@quiet, Logging.quiet = Logging.quiet, true
|
|
|
|
init_mkmf
|
|
|
|
$INCFLAGS[0, 0] = "-I. "
|
|
|
|
end
|
2009-08-06 00:14:50 -04:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def teardown
|
|
|
|
rbconfig0 = @rbconfig
|
|
|
|
mkconfig0 = @mkconfig
|
|
|
|
RbConfig.module_eval {
|
|
|
|
remove_const(:CONFIG)
|
|
|
|
const_set(:CONFIG, rbconfig0)
|
|
|
|
remove_const(:MAKEFILE_CONFIG)
|
|
|
|
const_set(:MAKEFILE_CONFIG, mkconfig0)
|
|
|
|
}
|
|
|
|
MakeMakefile.class_eval {
|
|
|
|
remove_const(:CONFIG)
|
|
|
|
const_set(:CONFIG, mkconfig0)
|
|
|
|
}
|
|
|
|
Logging.quiet = @quiet
|
|
|
|
Logging.log_close
|
|
|
|
FileUtils.rm_f("mkmf.log")
|
|
|
|
Dir.chdir(@curdir)
|
|
|
|
FileUtils.rm_rf(@tmpdir)
|
|
|
|
end
|
2009-08-06 00:14:50 -04:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def mkmf(*args, &block)
|
|
|
|
@stdout.clear
|
|
|
|
stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout
|
|
|
|
verbose, $VERBOSE = $VERBOSE, false
|
|
|
|
@mkmfobj.instance_eval(*args, &block)
|
|
|
|
ensure
|
|
|
|
$VERBOSE = verbose
|
|
|
|
$stdout, @stdout.origin = @stdout.origin, stdout
|
|
|
|
end
|
2010-12-10 04:12:33 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
def config_value(name)
|
|
|
|
create_tmpsrc("---config-value=#{name}")
|
|
|
|
xpopen(cpp_command('')) do |f|
|
|
|
|
f.grep(/^---config-value=(.*)/) {return $1}
|
|
|
|
end
|
|
|
|
nil
|
2010-12-10 04:12:33 -05:00
|
|
|
end
|
|
|
|
end
|
2015-02-03 03:15:47 -05:00
|
|
|
|
2022-04-22 16:01:43 -04:00
|
|
|
include Base
|
2015-02-03 03:15:47 -05:00
|
|
|
|
2019-04-07 19:55:34 -04: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 03:15:47 -05:00
|
|
|
end
|
|
|
|
end
|