ruby2d / ruby2d

🎨 The Ruby 2D gem
http://ruby2d.com
MIT License
646 stars 75 forks source link

invalid byte sequence in Windows-31J (ArgumentError) #167

Open yumetodo opened 5 years ago

yumetodo commented 5 years ago

On pure msys2 mingw64 environment, after merge #166, rake test:native audio will fail (usage of File.foreach).

I think that we need to specify encoding as utf-8. However, I don't know how to specify encoding is best so that I just create this issue.

https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/cli/build.rb#L62-L64

$rake test:native audio

==> Running native test: audio.rb

==> ruby2d build --clean
cleaning up...
==> ruby2d build --native test/audio.rb --debug
Traceback (most recent call last):
        8: from C:/msys64/mingw64/bin/ruby2d:23:in `<main>'
        7: from C:/msys64/mingw64/bin/ruby2d:23:in `load'
        6: from C:/msys64/mingw64/lib/ruby/gems/2.6.0/gems/ruby2d-0.9.2/bin/ruby2d:85:in `<top (required)>'
        5: from C:/msys64/mingw64/lib/ruby/gems/2.6.0/gems/ruby2d-0.9.2/lib/ruby2d/cli/build.rb:87:in `build_native'
        4: from C:/msys64/mingw64/lib/ruby/gems/2.6.0/gems/ruby2d-0.9.2/lib/ruby2d/cli/build.rb:87:in `open'
        3: from C:/msys64/mingw64/lib/ruby/gems/2.6.0/gems/ruby2d-0.9.2/lib/ruby2d/cli/build.rb:87:in `block in build_native'
        2: from C:/msys64/mingw64/lib/ruby/gems/2.6.0/gems/ruby2d-0.9.2/lib/ruby2d/cli/build.rb:62:in `strip_require'
        1: from C:/msys64/mingw64/lib/ruby/gems/2.6.0/gems/ruby2d-0.9.2/lib/ruby2d/cli/build.rb:62:in `foreach'
C:/msys64/mingw64/lib/ruby/gems/2.6.0/gems/ruby2d-0.9.2/lib/ruby2d/cli/build.rb:63:in `block in strip_require': invalid byte sequence in Windows-31J (ArgumentError)
==> ( cd test/ && ../build/app )
Souravgoswami commented 5 years ago

require 'ruby2d' require('ruby2d') require'ruby2d' require %q(ruby2d) require %Q(ruby2d) %w(open3 bigdecimal ruby2d).each { |x| require(x) } %w(open3 bigdecimal ruby2d).each(&method(:require)) gem 'ruby2d' gem('ruby2d')

This will not match the regexp. There are a tonne of ways a one liner could write require.

yumetodo commented 5 years ago

When I replace the function like below, another error occurred.

def strip_require(file)
  output = ''
  f = File.open(file, "rt:BOM|utf-8")
  f.each_line{ |line|
    output << line unless line =~ /require ('|")ruby2d('|")/
  }
  return output
end
$rake test:native audio

==> Running native test: audio.rb

==> ruby2d build --clean
cleaning up...
==> ruby2d build --native test/audio.rb --debug
cc: error: `simple2d: No such file or directory
cc: error: unrecognized command line option '--libs`'
Native app created at `build/app`
==> ( cd test/ && ../build/app )

https://github.com/ruby2d/ruby2d/blob/43ce9805a7ae8b82b7ab8c50bf6d4c845d395dc4/lib/ruby2d/cli/build.rb#L99

What is simple2d command?