asciidoctor / asciidoctor-epub3

:blue_book: Asciidoctor EPUB3 is a set of Asciidoctor extensions for converting AsciiDoc to EPUB3
https://asciidoctor.org
MIT License
215 stars 67 forks source link

kindlegen command not found in Windows (but installed) #154

Closed abelsromero closed 4 years ago

abelsromero commented 6 years ago

I am unable to create a kindle ebook using the maven plugin, I always get that the command is not found and I have tried with:

image

NOTE: I am running in a cygwin path, but the shell is a standard cmd.

Could it be because in Windows the executables are .bat and .exe?

mojavelinux commented 6 years ago

Have you tried something like this?

https://github.com/mraible/infoq-mini-book/blob/master/build.sh

abelsromero commented 6 years ago

No luck, I tried with alias also, from cygwin and cmd, and double checked path config and nothing :/ And I also reproduced the issue from Ruby (with binary in path, no kindlegen gem).

C:\\home\asalgadr\temp\asciidoctor-maven-examples\asciidoctor-epub-example\src\docs\asciidoc>asciidoctor-epub3 -aebook-format=kf8 spine.adoc --trace
C:/tools/ruby23/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- kindlegen (LoadError)
        from C:/tools/ruby23/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-epub3-1.5.0.alpha.7/lib/asciidoctor-epub3/packager.rb:611:in `distill_epub_to_mobi'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-epub3-1.5.0.alpha.7/lib/asciidoctor-epub3/packager.rb:602:in `package'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-epub3-1.5.0.alpha.7/lib/asciidoctor-epub3/converter.rb:41:in `write'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/document.rb:1083:in `write'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1507:in `convert'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575:in `block in convert_file'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575:in `open'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575:in `convert_file'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/cli/invoker.rb:108:in `block in invoke!'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/cli/invoker.rb:102:in `each'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/cli/invoker.rb:102:in `invoke!'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/asciidoctor-epub3-1.5.0.alpha.7/bin/asciidoctor-epub3:32:in `<top (required)>'
        from C:/tools/ruby23/bin/asciidoctor-epub3:22:in `load'
        from C:/tools/ruby23/bin/asciidoctor-epub3:22:in `<main>'

Btw, I had to downgrade my Ruby versio to 2.3.3 to be able to install the gem due to issues with nokogiri.

EDIT: using the asciidoctor-epub3 gem with the kindlegen gem installed it works on Ruby 2.3.3. So, it may be a Windows pathing issue or a JRuby or Maven issue. I am trying to install the gem through the gem-maven-plugin but the the native compilation part fails.

But, I have the question now. What is the official requirement, is the kindlegen gem optional or mandatory?

mojavelinux commented 6 years ago

The require statement should only be hit if value of the environment variable KINDLEGEN does not exist or is not executable. Could it be that it's not executable? (or that the check is failing?)

See https://github.com/asciidoctor/asciidoctor-epub3/blob/master/lib/asciidoctor-epub3/packager.rb#L625-L638

abelsromero commented 6 years ago

After wasting a few hours due to a missconfiguration in my pom (shame on me). I confirm that setting the KINDLEGEN env var allows to find the kindlegen binary on Maven. And it also works with the gem. But I suspect I found an issue with jRuby. The build fails with the new error:

(Errno::ENOENT) C:/home/bin/path/kindlegen.exe -dont_append_source -c0 -o spine.m
obi C:/home/asalgadr/temp/asciidoctor-maven-examples/asciidoctor-epub-example/target/generated-docs/spine-kf8.epub -> [Help 1]

I wrote a minimal script that reproduces distill_epub_to_mobi . This works from Ruby, but fails from JRuby (last version, 9.1.15.0) with the same error. I'll put it all in a project to report to JRuby Team when I get home.

Thanks @mojavelinux for your help! I think we can close this issue or mark as 'tracking' if jRuby confirm the issue.

khalid-hussain commented 5 years ago

I'm having the same problem. I'm not a Ruby developer and thus don't understand some of the things discussed here. How can a user overcome this issue?

I get a similar if not exactly same error:

C:/Ruby23-x64/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- kindlegen (LoadError)
        from C:/Ruby23-x64/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-epub3-1.5.0.alpha.8/lib/asciidoctor-epub3/packager.rb:628:in `distill_epub_to_mobi'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-epub3-1.5.0.alpha.8/lib/asciidoctor-epub3/packager.rb:619:in `package'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-epub3-1.5.0.alpha.8/lib/asciidoctor-epub3/converter.rb:41:in `write'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.8/lib/asciidoctor/document.rb:1217:in `write'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.8/lib/asciidoctor.rb:1524:in `convert'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.8/lib/asciidoctor.rb:1595:in `block in convert_file'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.8/lib/asciidoctor.rb:1595:in `open'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.8/lib/asciidoctor.rb:1595:in `convert_file'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.8/lib/asciidoctor/cli/invoker.rb:129:in `block in invoke!'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.8/lib/asciidoctor/cli/invoker.rb:112:in `each'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-1.5.8/lib/asciidoctor/cli/invoker.rb:112:in `invoke!'
        from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/asciidoctor-epub3-1.5.0.alpha.8/bin/asciidoctor-epub3:32:in `<top (required)>'
        from C:/Ruby23-x64/bin/asciidoctor-epub3:22:in `load'
        from C:/Ruby23-x64/bin/asciidoctor-epub3:22:in `<main>'

I have kindlegen installed and have used it before.

*************************************************************
 Amazon kindlegen(Windows) V2.9 build 0830-03578f
 A command line e-book compiler
 Copyright Amazon.com and its Affiliates 2015
*************************************************************

I added the KINDLEGEN environment variable and pointed it to folder where I stored kindlegen. It still doesn't work.

ysb33r commented 5 years ago

There are two solutions that might work better and both can be used especially by tools that embed Asciidoctor / AsciidoctorJ

[1] Make it possible to set the location via attribute or option.

[2] Instead of fully processing with kindlegen, have an option that can only generate the intermediate files. IN this way kindlegen can be run by the embedding framework as a post-procesing tool. (bascially don't call distill_epub_to_mobi).This would make it work on Windows and solve the NOENT issue.

slonopotamus commented 4 years ago

Gradle users have exactly the same problem: asciidoctor/asciidoctorj#659

slonopotamus commented 4 years ago

~Seems like Open3.popen2e call that we use simply doesn't work on Windows: jruby/jruby#4943.~

This statement is only half-true.

slonopotamus commented 4 years ago

I've learnt much more than I would like to about JRuby on Windows while fixing this bug. I'll possibly share my knowledge. But later, when I calm down a bit.

mojavelinux commented 4 years ago

When you're feeling better, I'd be interested with what you found. So would the AsciidoctorJ devs, I'm sure of it.