Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set gem path for ruby #581

Closed
rahmanusta opened this issue Aug 1, 2018 · 3 comments
Closed

Set gem path for ruby #581

rahmanusta opened this issue Aug 1, 2018 · 3 comments
Assignees
Labels

Comments

@rahmanusta
Copy link

Is it possible to change path which is used to load GEMs on Graal SDK possible with Context API?

@eregon eregon added the ruby label Aug 1, 2018
@eregon eregon self-assigned this Aug 1, 2018
@eregon
Copy link
Member

eregon commented Aug 1, 2018

We use the standard way of RubyGems to configure the Gem home and path.
So you can set the environment variables GEM_HOME (setting GEM_PATH too might be useful in some situations) and then require will look there.

It seems also possible to set them at runtime programmatically with Gem.paths= env:

$ ruby -e 'Gem.paths={"GEM_HOME" => "/foo"}; p Gem.path'
["/home/eregon/.gem/truffleruby/2.4.0", "/home/eregon/.rubies/truffleruby-1.0.0-rc3/lib/ruby/gems/2.4.0", "/foo"]
$ ruby -e 'Gem.paths={"GEM_HOME" => "/foo", "GEM_PATH"=> "/foo:/bar"}; p Gem.path'
["/foo", "/bar"]

If you just want to put a single lib directory on $LOAD_PATH, then that can be done directly, and extra load paths entries can be set with the option ruby.load_paths (the equivalent of ruby -I path).

@rahmanusta Does that help?

@rahmanusta
Copy link
Author

It is helpful but, in this case, my goal is to run https://github.com/asciidoctor/asciidoctor-pdf on graal.

First I cloned the source code, and run bundle install --standalone, then evaluated the following script.

Gem.paths = {
    'GEM_HOME' => '........./asciidoctor-pdf/bundle/truffleruby/2.4.0/gems',
    'GEM_PATH' => '........../asciidoctor-pdf/bundle/truffleruby/2.4.0/gems'
}

if File.exist?(asciidoctorPdf = (File.expand_path '../asciidoctor-pdf/lib/asciidoctor-pdf', '.........../asciidoctor-pdf/lib/asciidoctor-pdf.rb'))
  puts "asciidoctor-pdf is loaded"
  require asciidoctorPdf
end

However, I'm getting the following error. I don't know which part is wrong. Thanks

Exception NameError' at Unnamed:1:in const_missing' - uninitialized constant Asciidoctor
Exception in thread "main" uninitialized constant Asciidoctor (NameError)

@eregon
Copy link
Member

eregon commented Sep 4, 2018

Unfortunately, I missed your comment and forgot about your issue.
Let me move it to the TruffleRuby bug tracker, so it should be easier to track:
oracle/truffleruby#1419

@eregon eregon closed this as completed Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants