Ocra gives errors when packing a script

SCENARIO

I installed the Ruby 2.1.5 package (x64) , after which I installed Ocra gem successfully:

gem install ocra Fetching: ocra-1.3.3.gem (100%) Successfully installed ocra-1.3.3 Parsing documentation for ocra-1.3.3 Installing ri documentation for ocra-1.3.3 Done installing documentation for ocra after 0 seconds 1 gem installed 

PROBLEM

I am trying to pack a Script test:

 # -*- coding: UTF-8 -*- # require '' exit if Object.const_defined?(:Ocra) print "Hello World!" sleep 3 __END__ 

But when I try to use Ocra , it throws errors:

 ocra "TestScript.rb" === Loading script to check dependencies === Detected gem ocra-1.3.3 (loaded, files) === 6 files, 190931 bytes === Detected gem io-console-0.4.2 (loaded, files) C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra:86:in `open': No such file or directory @ dir_initialize - C:/Program Files/Ruby/lib/ruby/gem s/2.1.0/gems/io-console-0.4.2 (Errno::ENOENT) from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 86:in `entries' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 86:in `entries' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 92:in `find_all_files' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 665:in `block (2 levels) in find_gem_files' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 658:in `each' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 658:in `block in find_gem_files' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 611:in `each' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 611:in `find_gem_files' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 728:in `build_exe' from C:/Program Files/Ruby/lib/ruby/gems/2.1.0/gems/ocra-1.3.3/bin/ocra: 1165:in `block in <top (required)>' 

Question

Why is this happening? How to fix it?

+5
source share
2 answers

tl; dr: I was able to successfully create an executable from your script using Ocra with Ruby version 2.0.0p481 and rubygems 2.0.14. If you can switch Ruby versions, you can get the same results. ( Here is an entry I made using several versions of Ruby on Windows with an awesome uru .)

Deep dive:

This io-console issue has caused concern for many users of the Ocra gem, and there is currently a problem with github for it:

https://github.com/larsch/ocra/issues/77

Ocra calls Gem::Specification#gem_dir for all the loaded gems in your script, which includes io-console . This operation returns a path that does not exist, hence an error.

(Here's a link to the gem_dir method from rubygems for your reference too.)

You can try it yourself:

 irb(main):001:0>require "io/console" => true irb(main):002:0>io_console_spec = Gem.loaded_specs["io-console"] => #<Gem::Specification:0xblahblah io-console-0.4.2> irb(main):003:0>proposed_path = io_console_spec.gem_dir => "$YOUR_RUBY_DIRECTORY/lib/ruby/gems/2.1.0/gems/io-console-0.4.2" irb(main):004:0>File.directory? proposed_path => false 

Ocra successfully executed the execution of this script when using Ruby 2.0.0p481:

ocra-success

This makes me believe that the result of Gem.loaded_specs changed somewhere between rubygems 2.0.14 (this is the version running on my version 2.0.0p481) and rubygems 2.2.2 (this is the version running on my 2.1.5 build). Understanding why Gem::Specification#gem_dir for io-console is something I will work on more (I am very new to working with Ocra and Rubygems), but hopefully it was useful.

+1
source

The problem is with installing irb1.8 and NOT the irb dependency package. to solve the problem, simply run "apt-get install irb" if you already have irbl installed.

+2
source

Source: https://habr.com/ru/post/1209953/


All Articles