zakird / wkhtmltopdf_binary_gem

Ruby gem containing easily installable access to wkhtmltopdf application
https://rubygems.org/gems/wkhtmltopdf-binary
Apache License 2.0
184 stars 346 forks source link

RUBY_PLATFORM on JRuby is 'java' #50

Closed headius closed 5 years ago

headius commented 5 years ago

Currently the gem is using RUBY_PLATFORM to get the OS, so it can pick the right binary. On JRuby, this is always "java", because it's the only way we can differentiate gems for our platform:

$ jruby -e 'p RUBY_PLATFORM'
"java"

This prevents commands from working:

$ wkhtmltopdf 
RuntimeError: Invalid platform. Must be running linux or intel-based Mac OS.
  <main> at /Users/headius/projects/jruby/lib/ruby/gems/shared/gems/wkhtmltopdf-0.1.2/bin/wkhtmltopdf:8
    load at org/jruby/RubyKernel.java:1022
  <main> at /Users/headius/projects/jruby/bin/wkhtmltopdf:23

However we do support the (arguably more reliable) RbConfig::CONFIG['host_os'] which should work the same way for you:

$ jruby -e 'p RbConfig::CONFIG["host_os"]'
"darwin"

Changing the bin script to use this value instead of RUBY_PLATFORM would allow the gem to work on JRuby:

$ wkhtmltopdf ; echo $?
0
--- lib/ruby/gems/shared/gems/wkhtmltopdf-0.1.2/bin/wkhtmltopdf 2019-04-26 11:06:09.000000000 -0500
+++ lib/ruby/gems/shared/gems/wkhtmltopdf-0.1.2/bin/wkhtmltopdf-old 2019-04-26 11:05:41.000000000 -0500
@@ -1,10 +1,8 @@
 #!/usr/bin/ruby

-platform = RbConfig::CONFIG['host_os']
-
-if platform =~ /linux/
+if RUBY_PLATFORM =~ /linux/
   executable = 'wkhtmltopdf_linux_386'
-elsif platform =~ /darwin/
+elsif RUBY_PLATFORM =~ /darwin/
   executable = 'wkhtmltopdf_darwin_386'
 else
   raise "Invalid platform. Must be running linux or intel-based Mac OS."

👍

headius commented 5 years ago

Oh...maybe this has been fixed? I guess I installed wkhtmltopdf instead of wkhtmltopdf-binary, and it didn't work...

headius commented 5 years ago

Ahh yes, that was it...maybe those old gems should just get yanked?

Anyway, carry on!