diff options
| -rw-r--r-- | doc/guides/mrbgems.md | 8 | ||||
| -rw-r--r-- | lib/mruby/build/load_gems.rb | 8 |
2 files changed, 13 insertions, 3 deletions
diff --git a/doc/guides/mrbgems.md b/doc/guides/mrbgems.md index 4246587ce..f05fd1f08 100644 --- a/doc/guides/mrbgems.md +++ b/doc/guides/mrbgems.md @@ -12,12 +12,18 @@ a GEM, add the following line to your build configuration file, for example: conf.gem '/path/to/your/gem/dir' ``` -You can also use a relative path which would be relative from the mruby root: +You can also use a relative path to specify a gem. ```ruby conf.gem 'examples/mrbgems/ruby_extension_example' ``` +In that case, + +* if your build configuration file is in the `build_config` directory, it's + relative from `MRUBY_ROOT`. +* otherwise, it is relative from the directory where your build configuration is. + A remote GIT repository location for a GEM is also supported: ```ruby conf.gem :git => 'https://github.com/masuidrive/mrbgems-example.git', :branch => 'master' diff --git a/lib/mruby/build/load_gems.rb b/lib/mruby/build/load_gems.rb index b2b185f05..28811e8ec 100644 --- a/lib/mruby/build/load_gems.rb +++ b/lib/mruby/build/load_gems.rb @@ -15,10 +15,14 @@ module MRuby def gem(gemdir, &block) if gemdir.is_a?(Hash) gemdir = load_special_path_gem(gemdir) - elsif GemBox.path && gemdir.is_a?(String) + elsif GemBox.path gemdir = File.expand_path(gemdir, File.dirname(GemBox.path)) else - gemdir = File.expand_path(gemdir, MRUBY_ROOT) + caller_dir = File.expand_path(File.dirname(caller(1,1)[0][/^(.*?):\d/,1])) + if caller_dir == "#{MRUBY_ROOT}/build_config" + caller_dir = MRUBY_ROOT + end + gemdir = File.expand_path(gemdir, caller_dir) end gemrake = File.join(gemdir, "mrbgem.rake") |
