Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Shim to make it easier to use bundler.
Browse files Browse the repository at this point in the history
chrisseaton committed Aug 30, 2015
1 parent be1d57f commit 3bf5855
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -586,6 +586,7 @@ private void initializeConstants() {
Layouts.MODULE.getFields(objectClass).setConstant(node, "RUBY_PATCHLEVEL", 0);
Layouts.MODULE.getFields(objectClass).setConstant(node, "RUBY_REVISION", Constants.RUBY_REVISION);
Layouts.MODULE.getFields(objectClass).setConstant(node, "RUBY_ENGINE", Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(Constants.ENGINE + "+truffle", UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null));
Layouts.MODULE.getFields(objectClass).setConstant(node, "JRUBY_ENGINE", Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(Constants.ENGINE, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null));
Layouts.MODULE.getFields(objectClass).setConstant(node, "RUBY_PLATFORM", Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(Constants.PLATFORM, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null));
Layouts.MODULE.getFields(objectClass).setConstant(node, "RUBY_RELEASE_DATE", Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(Constants.COMPILE_DATE, UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null));
Layouts.MODULE.getFields(objectClass).setConstant(node, "RUBY_DESCRIPTION", Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(stringClass), RubyString.encodeBytelist(OutputStrings.getVersionString(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null));
Original file line number Diff line number Diff line change
@@ -979,15 +979,27 @@ public RubyNode visitConstNode(org.jruby.ast.ConstNode node) {
// Unqualified constant access, as in CONST
final SourceSection sourceSection = translate(node.getPosition());

String name = ConstantReplacer.replacementName(sourceSection, node.getName());

/*
* We'd like to be able to use JRuby to run bundler to standalone-install gems required to run
* programs using Truffle. Bundler puts the JRuby engine name into the path, so to get around
* that we detect it asking for the engine, and pretend to be just JRuby.
*/

if (name.equals("RUBY_ENGINE")
&& sourceSection.getSource().getPath().endsWith("bundler/setup.rb")
&& sourceSection.getStartLine() == 3) {
name = "JRUBY_ENGINE";
}

/*
* Constants of the form Rubinius::Foo in the Rubinius kernel code always seem to get resolved, even if
* Rubinius is not defined, such as in BasicObject. We get around this by translating Rubinius to be
* ::Rubinius. Note that this isn't quite what Rubinius does, as they say that Rubinius isn't defined, but
* we will because we'll translate that to ::Rubinius. But it is a simpler translation.
*/

final String name = ConstantReplacer.replacementName(sourceSection, node.getName());

if (name.equals("Rubinius") && sourceSection.getSource().getPath().startsWith(CoreLibrary.CORE_LOAD_PATH + "/core/rubinius")) {
final RubyNode ret = new org.jruby.ast.Colon3Node(node.getPosition(), name).accept(this);
return addNewlineIfNeeded(node, ret);

0 comments on commit 3bf5855

Please sign in to comment.