| 1 |
#!/usr/bin/env ruby |
| 2 |
|
| 3 |
# Wrapper for running tests for cross-compiled Windows builds in Wine. |
| 4 |
|
| 5 |
require 'open3' |
| 6 |
|
| 7 |
DOSROOT = 'z:' |
| 8 |
|
| 9 |
# Rewrite test output to replace DOS-isms with Unix-isms. |
| 10 |
def clean(output, stderr = false) |
| 11 |
ends_with_newline = !!(output =~ /\n$/) |
| 12 |
executable = ARGV[0].gsub(/\.exe\z/i, '') |
| 13 |
|
| 14 |
# Fix line-ends |
| 15 |
output = output.gsub(/\r\n/, "\n") |
| 16 |
|
| 17 |
# Strip out Wine messages |
| 18 |
|
| 19 |
|
| 20 |
results = output.split(/\n/).map do |line| |
| 21 |
# Fix file paths |
| 22 |
if line =~ /#{DOSROOT}\\/i |
| 23 |
line.gsub!(/#{DOSROOT}([^:]*)/i) { |path| |
| 24 |
path.gsub!(/^#{DOSROOT}/i, '') |
| 25 |
path.gsub!(%r{\\}, '/') |
| 26 |
path |
| 27 |
} |
| 28 |
end |
| 29 |
|
| 30 |
# strip '.exe' off the end of the executable's name if needed |
| 31 |
line.gsub!(/(#{Regexp.escape executable})\.exe/i, '\1') |
| 32 |
|
| 33 |
line |
| 34 |
end |
| 35 |
|
| 36 |
result_text = results.join("\n") |
| 37 |
result_text += "\n" if ends_with_newline |
| 38 |
result_text |
| 39 |
end |
| 40 |
|
| 41 |
|
| 42 |
def main |
| 43 |
if ARGV.empty? || ARGV[0] =~ /^- (-?) (\?|help|h) $/x |
| 44 |
puts "#{$0} <command-line>" |
| 45 |
exit 0 |
| 46 |
end |
| 47 |
|
| 48 |
# For simplicity, just read all of stdin into memory and pass that |
| 49 |
# as an argument when invoking wine. (Skipped if STDIN was not |
| 50 |
# redirected.) |
| 51 |
if !STDIN.tty? |
| 52 |
input = STDIN.read |
| 53 |
else |
| 54 |
input = "" |
| 55 |
end |
| 56 |
|
| 57 |
# Disable all Wine messages so they don't interfere with the output |
| 58 |
ENV['WINEDEBUG'] = 'err-all,warn-all,fixme-all,trace-all' |
| 59 |
|
| 60 |
# Run the program in wine and capture the output |
| 61 |
output, errormsg, status = Open3.capture3('wine', *ARGV, :stdin_data => input) |
| 62 |
|
| 63 |
# Clean and print the results. |
| 64 |
STDOUT.write clean(output) |
| 65 |
STDERR.write clean(errormsg) |
| 66 |
|
| 67 |
exit(status.exitstatus) |
| 68 |
end |
| 69 |
|
| 70 |
|
| 71 |
main() |