diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-10-22 13:41:50 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-22 13:41:50 +0900 |
| commit | 74b02fba81c0da246ff6418bf9557f78192ff33f (patch) | |
| tree | fe0b3c1302da8bc5de48d649dd0984d279d5f0ba /build_config/helpers/wine_runner.rb | |
| parent | fabe8212fee00917eec114fd6e100dc9d532090c (diff) | |
| parent | 5c4273f944b538bc24ed98c52991ea8bf9044654 (diff) | |
| download | mruby-74b02fba81c0da246ff6418bf9557f78192ff33f.tar.gz mruby-74b02fba81c0da246ff6418bf9557f78192ff33f.zip | |
Merge pull request #5563 from suetanvil-misc/project-bintest-emulator-4-flat
Added testing support for cross-MinGW builds.
Diffstat (limited to 'build_config/helpers/wine_runner.rb')
| -rwxr-xr-x | build_config/helpers/wine_runner.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/build_config/helpers/wine_runner.rb b/build_config/helpers/wine_runner.rb new file mode 100755 index 000000000..9a7eb46b0 --- /dev/null +++ b/build_config/helpers/wine_runner.rb @@ -0,0 +1,71 @@ +#!/usr/bin/env ruby + +# Wrapper for running tests for cross-compiled Windows builds in Wine. + +require 'open3' + +DOSROOT = 'z:' + +# Rewrite test output to replace DOS-isms with Unix-isms. +def clean(output, stderr = false) + ends_with_newline = !!(output =~ /\n$/) + executable = ARGV[0].gsub(/\.exe\z/i, '') + + # Fix line-ends + output = output.gsub(/\r\n/, "\n") + + # Strip out Wine messages + + + results = output.split(/\n/).map do |line| + # Fix file paths + if line =~ /#{DOSROOT}\\/i + line.gsub!(/#{DOSROOT}([^:]*)/i) { |path| + path.gsub!(/^#{DOSROOT}/i, '') + path.gsub!(%r{\\}, '/') + path + } + end + + # strip '.exe' off the end of the executable's name if needed + line.gsub!(/(#{Regexp.escape executable})\.exe/i, '\1') + + line + end + + result_text = results.join("\n") + result_text += "\n" if ends_with_newline + return result_text +end + + +def main + if ARGV.empty? || ARGV[0] =~ /^- (-?) (\?|help|h) $/x + puts "#{$0} <command-line>" + exit 0 + end + + # For simplicity, just read all of stdin into memory and pass that + # as an argument when invoking wine. (Skipped if STDIN was not + # redirected.) + if !STDIN.tty? + input = STDIN.read + else + input = "" + end + + # Disable all Wine messages so they don't interfere with the output + ENV['WINEDEBUG'] = 'err-all,warn-all,fixme-all,trace-all' + + # Run the program in wine and capture the output + output, errormsg, status = Open3.capture3('wine', *ARGV, :stdin_data => input) + + # Clean and print the results. + STDOUT.write clean(output) + STDERR.write clean(errormsg) + + exit(status.exitstatus) +end + + +main() |
