Skip to content

Commit

Permalink
[Truffle] Support --disable-gems.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Nov 18, 2016
1 parent 9f5aab4 commit e095283
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Expand Up @@ -406,7 +406,6 @@ private void processArgument() {
config.setCompileMode(RubyInstanceConfig.CompileMode.TRUFFLE);
// Make the static option consistent with the compile mode.
Options.COMPILE_MODE.force("TRUFFLE");
config.setDisableGems(true);
} else if (extendedOption.endsWith("...")) {
Options.listPrefix(extendedOption.substring(0, extendedOption.length() - "...".length()));
config.setShouldRunInterpreter(false);
Expand Down
Expand Up @@ -158,6 +158,16 @@ public DynamicObject originalLoadPath() {

}

@CoreMethod(names = "rubygems_enabled?", onSingleton = true)
public abstract static class RubygemsEnabledNode extends CoreMethodNode {

@Specialization
public boolean isRubygemsEnabled() {
return !getContext().getInstanceConfig().isDisableGems();
}

}

@CoreMethod(names = "source_of_caller", isModuleFunction = true)
public abstract static class SourceOfCallerNode extends CoreMethodArrayArgumentsNode {

Expand Down
12 changes: 7 additions & 5 deletions truffle/src/main/ruby/post-boot/gems.rb
Expand Up @@ -11,8 +11,10 @@
rescue LoadError
end

begin
require 'rubygems'
rescue LoadError
warn('Could not load RubyGems during runtime bootstrap. Please set JRUBY_HOME to an appropriate location.')
end
if Truffle::Boot.rubygems_enabled?
begin
require 'rubygems'
rescue LoadError
warn('Could not load RubyGems during runtime bootstrap. Please set JRUBY_HOME to an appropriate location.')
end
end
10 changes: 6 additions & 4 deletions truffle/src/main/ruby/post-boot/shims.rb
Expand Up @@ -6,9 +6,11 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

module Gem
# Update the default_dir to match JRuby's.
def self.default_dir
File.expand_path(File.join(ConfigMap[:libdir], '..', '..', 'ruby', 'gems', 'shared'))
if Truffle::Boot.rubygems_enabled?
module Gem
# Update the default_dir to match JRuby's.
def self.default_dir
File.expand_path(File.join(ConfigMap[:libdir], '..', '..', 'ruby', 'gems', 'shared'))
end
end
end

0 comments on commit e095283

Please sign in to comment.