Created
September 10, 2017 13:06
-
-
Save nownabe/5d50e0d988d1f6593b91efd0a28a9045 to your computer and use it in GitHub Desktop.
test-gems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/mkmf.rb b/lib/mkmf.rb | |
index 7e40c2d..a6299a0 100644 | |
--- a/lib/mkmf.rb | |
+++ b/lib/mkmf.rb | |
@@ -6,6 +6,61 @@ | |
require 'rbconfig' | |
require 'fileutils' | |
require 'shellwords' | |
+require "pp" | |
+require "open3" | |
+ | |
+module Dbg | |
+ class << self | |
+ def methods | |
+ @methods ||= [] | |
+ end | |
+ | |
+ def depth | |
+ @depth ||= 0 | |
+ end | |
+ | |
+ def start(meth) | |
+ log "#### begin: #{meth} ####" | |
+ @depth = @depth ? @depth + 1 : @depth | |
+ methods.push(meth) | |
+ end | |
+ | |
+ def finish | |
+ @depth -= 1 | |
+ meth = methods.pop | |
+ log "#### end: #{meth} ####" | |
+ end | |
+ | |
+ def file | |
+ @file ||= File.open("/home/nownabe/tmp/rubyhackchallenge/gemtest/log.log", "a") | |
+ end | |
+ | |
+ def log(msg) | |
+ file.puts(msg.gsub(/^/, " " * 4 * depth)) | |
+ end | |
+ | |
+ def command(env, command) | |
+ start("command") | |
+ Dbg.log "env: #{env}\n" | |
+ Dbg.log "command: #{command}\n" | |
+ finish | |
+ end | |
+ | |
+ def error(e) | |
+ Dbg.log e.class.to_s + "\n" | |
+ Dbg.log e.message + "\n" | |
+ Dbg.log e.backtrace.join("\n") + "\n" | |
+ end | |
+ end | |
+ | |
+ depth | |
+end | |
+ | |
+Dbg.log "\n\n==============================\n" | |
+Dbg.log "Current Directory: #{Dir.pwd}\n\n" | |
+Dbg.log "ENV:\n" | |
+Dbg.log "#{PP.pp(ENV, "")}\n\n" | |
+Dbg.log "==============================\n\n" | |
# :stopdoc: | |
class String | |
@@ -376,26 +431,41 @@ def libpath_env | |
end | |
def xsystem command, opts = nil | |
+ Dbg.start "xsystem(command, opts = nil)" | |
varpat = /\$\((\w+)\)|\$\{(\w+)\}/ | |
if varpat =~ command | |
vars = Hash.new {|h, k| h[k] = ENV[k]} | |
command = command.dup | |
nil while command.gsub!(varpat) {vars[$1||$2]} | |
end | |
+ | |
Logging::open do | |
puts command.quote | |
if opts and opts[:werror] | |
result = nil | |
Logging.postpone do |log| | |
+ Dbg.log("libpath_env: #{libpath_env}") | |
+ Dbg.log("command: #{command}") | |
output = IO.popen(libpath_env, command, &:read) | |
result = ($?.success? and File.zero?(log.path)) | |
+ Dbg.log "Output: #{output}" | |
+ Dbg.log "Result: #{result}" | |
output | |
end | |
result | |
else | |
- system(libpath_env, command) | |
+ Dbg.log("libpath_env: #{libpath_env}") | |
+ Dbg.log("command: #{command}") | |
+ o, e, s = Open3.capture3(libpath_env, command) | |
+ #res = system(libpath_env, command) | |
+ Dbg.log "Stdout: #{o}" | |
+ Dbg.log "Stderr: #{e}" | |
+ Dbg.log "Result: #{s}\n" | |
+ s.success? | |
end | |
end | |
+ ensure | |
+ Dbg.finish | |
end | |
def xpopen command, *mode, &block | |
@@ -445,14 +515,21 @@ def create_tmpsrc(src) | |
end | |
def have_devel? | |
+ Dbg.start "have_devel?" | |
unless defined? $have_devel | |
+ Dbg.log "$hava_devel is not defined.\n" | |
+ Dbg.log "MAIN_DOES_NOTHING: #{MAIN_DOES_NOTHING}\n" | |
$have_devel = true | |
$have_devel = try_link(MAIN_DOES_NOTHING) | |
+ Dbg.log "$have_devel = #{$have_devel}\n" | |
end | |
$have_devel | |
+ ensure | |
+ Dbg.finish | |
end | |
def try_do(src, command, *opts, &b) | |
+ Dbg.start "try_do(src, command, *opts, &b)" | |
unless have_devel? | |
raise <<MSG | |
The compiler failed to generate an executable file. | |
@@ -465,6 +542,11 @@ def try_do(src, command, *opts, &b) | |
ensure | |
log_src(src) | |
end | |
+ rescue => e | |
+ Dbg.error(e) | |
+ raise e | |
+ ensure | |
+ Dbg.finish | |
end | |
def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH) | |
@@ -526,6 +608,7 @@ def with_werror(opt, opts = nil) | |
end | |
def try_link0(src, opt="", *opts, &b) # :nodoc: | |
+ Dbg.start "try_link0(src, opts = \"\", *opts, &b)" | |
exe = CONFTEST+$EXEEXT | |
cmd = link_command("", opt) | |
if $universal | |
@@ -544,6 +627,7 @@ def try_link0(src, opt="", *opts, &b) # :nodoc: | |
exe | |
ensure | |
MakeMakefile.rm_rf(*Dir["#{CONFTEST}*"]-[exe]) | |
+ Dbg.finish | |
end | |
# Returns whether or not the +src+ can be compiled as a C source and linked | |
@@ -557,9 +641,14 @@ def try_link0(src, opt="", *opts, &b) # :nodoc: | |
# [+src+] a String which contains a C source | |
# [+opt+] a String which contains linker options | |
def try_link(src, opt="", *opts, &b) | |
- exe = try_link0(src, opt, *opts, &b) or return false | |
+ Dbg.start "try_link(src, opt = \"\", *opts, &b)" | |
+ exe = try_link0(src, opt, *opts, &b) | |
+ Dbg.log "exe: #{exe}\n" | |
+ return false unless exe | |
MakeMakefile.rm_f exe | |
true | |
+ ensure | |
+ Dbg.finish | |
end | |
# Returns whether or not the +src+ can be compiled as a C source. +opt+ is | |
@@ -588,10 +677,21 @@ def try_compile(src, opt="", *opts, &b) | |
# [+src+] a String which contains a C source | |
# [+opt+] a String which contains preprocessor options | |
def try_cpp(src, opt="", *opts, &b) | |
- try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b) and | |
+ Dbg.start "try_cpp(src, opt = \"\", *opts, &b)" | |
+ Dbg.log "src: #{src}\n" | |
+ Dbg.log "CPPOUTFILE: #{CPPOUTFILE.dump}\n" | |
+ Dbg.log "cpp_command(CPPOUTFILE, opt): #{cpp_command(CPPOUTFILE, opt).dump}\n" | |
+ | |
+ res = try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b) and | |
File.file?("#{CONFTEST}.i") | |
+ Dbg.log "Result: #{res}\n" | |
+ res | |
+ rescue => e | |
+ Dbg.error(e) | |
+ raise e | |
ensure | |
MakeMakefile.rm_f "#{CONFTEST}*" | |
+ Dbg.finish | |
end | |
alias_method :try_header, (config_string('try_header') || :try_cpp) | |
@@ -1094,7 +1194,8 @@ def have_var(var, headers = nil, opt = "", &b) | |
# +HAVE_FOO_H+ preprocessor macro would be passed to the compiler. | |
# | |
def have_header(header, preheaders = nil, opt = "", &b) | |
- checking_for header do | |
+ Dbg.start "have_header(header, preheaders = nil, opt = \"\", &b)" | |
+ res = checking_for header do | |
if try_header(cpp_include(preheaders)+cpp_include(header), opt, &b) | |
$defs.push(format("-DHAVE_%s", header.tr_cpp)) | |
true | |
@@ -1102,6 +1203,10 @@ def have_header(header, preheaders = nil, opt = "", &b) | |
false | |
end | |
end | |
+ Dbg.log "Result: #{res}\n" | |
+ res | |
+ ensure | |
+ Dbg.finish | |
end | |
# Returns whether or not the given +framework+ can be found on your system. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment