Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bundler/cli/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def ruby_shebang?(file)
possibilities = [
"#!/usr/bin/env ruby\n",
"#!/usr/bin/env jruby\n",
"#!/usr/bin/env truffleruby\n",
"#!#{Gem.ruby}\n",
]

Expand Down
8 changes: 7 additions & 1 deletion lib/bundler/current_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class CurrentRuby
mswin64
rbx
ruby
truffleruby
x64_mingw
].freeze

def ruby?
!mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx" || RUBY_ENGINE == "maglev")
!mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" ||
RUBY_ENGINE == "rbx" || RUBY_ENGINE == "maglev" || RUBY_ENGINE == "truffleruby")
end

def mri?
Expand All @@ -55,6 +57,10 @@ def maglev?
defined?(RUBY_ENGINE) && RUBY_ENGINE == "maglev"
end

def truffleruby?
defined?(RUBY_ENGINE) && RUBY_ENGINE == "truffleruby"
end

def mswin?
Bundler::WINDOWS
end
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Dependency < Gem::Dependency
:mri_24 => Gem::Platform::RUBY,
:mri_25 => Gem::Platform::RUBY,
:rbx => Gem::Platform::RUBY,
:truffleruby => Gem::Platform::RUBY,
:jruby => Gem::Platform::JAVA,
:jruby_18 => Gem::Platform::JAVA,
:jruby_19 => Gem::Platform::JAVA,
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/ruby_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def self.system
when "jruby"
JRUBY_VERSION.dup
else
raise BundlerError, "RUBY_ENGINE value #{RUBY_ENGINE} is not recognized"
RUBY_ENGINE_VERSION.dup
end
patchlevel = RUBY_PATCHLEVEL.to_s

Expand Down
14 changes: 8 additions & 6 deletions man/gemfile.5.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ All parameters are `OPTIONAL` unless otherwise specified.
### VERSION (required)

The version of Ruby that your application requires. If your application
requires an alternate Ruby engine, such as JRuby or Rubinius, this should be
the Ruby version that the engine is compatible with.
requires an alternate Ruby engine, such as JRuby, Rubinius or TruffleRuby, this
should be the Ruby version that the engine is compatible with.

ruby "1.9.3"

Expand Down Expand Up @@ -188,22 +188,24 @@ platforms.
There are a number of `Gemfile` platforms:

* `ruby`:
C Ruby (MRI) or Rubinius, but `NOT` Windows
C Ruby (MRI), Rubinius or TruffleRuby, but `NOT` Windows
* `mri`:
Same as _ruby_, but not Rubinius
Same as _ruby_, but only C Ruby (MRI)
* `mingw`:
Windows 32 bit 'mingw32' platform (aka RubyInstaller)
* `x64_mingw`:
Windows 64 bit 'mingw32' platform (aka RubyInstaller x64)
* `rbx`:
Same as _ruby_, but only Rubinius (not MRI)
Rubinius
* `jruby`:
JRuby
* `truffleruby`:
TruffleRuby
* `mswin`:
Windows

You can restrict further by platform and version for all platforms *except* for
`rbx`, `jruby`, and `mswin`.
`rbx`, `jruby`, `truffleruby` and `mswin`.

To specify a version in addition to a platform, append the version number without
the delimiter to the platform. For example, to specify that a gem should only be
Expand Down
2 changes: 1 addition & 1 deletion spec/bundler/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

describe "#gem" do
[:ruby, :ruby_18, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24, :ruby_25, :mri, :mri_18, :mri_19,
:mri_20, :mri_21, :mri_22, :mri_23, :mri_24, :mri_25, :jruby, :rbx].each do |platform|
:mri_20, :mri_21, :mri_22, :mri_23, :mri_24, :mri_25, :jruby, :rbx, :truffleruby].each do |platform|
it "allows #{platform} as a valid platform" do
subject.gem("foo", :platform => platform)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/bundler/ruby_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
context "engine is ruby" do
before do
stub_const("RUBY_VERSION", "2.2.4")
allow(Bundler).to receive(:ruby_engine).and_return("ruby")
stub_const("RUBY_ENGINE", "ruby")
end

it "should return a copy of the value of RUBY_VERSION" do
Expand Down Expand Up @@ -479,11 +479,11 @@
context "engine is some other ruby engine" do
before do
stub_const("RUBY_ENGINE", "not_supported_ruby_engine")
allow(Bundler).to receive(:ruby_engine).and_return("not_supported_ruby_engine")
stub_const("RUBY_ENGINE_VERSION", "1.2.3")
end

it "should raise a BundlerError with a 'not recognized' message" do
expect { bundler_system_ruby_version.engine_versions }.to raise_error(Bundler::BundlerError, "RUBY_ENGINE value not_supported_ruby_engine is not recognized")
it "returns RUBY_ENGINE_VERSION" do
expect(bundler_system_ruby_version.engine_versions).to eq(["1.2.3"])
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/other/bundle_ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@
expect(out).to include("ruby 1.8.7 (rbx 1.2.4)")
end

it "handles truffleruby" do
gemfile <<-G
source "file://#{gem_repo1}"
ruby "2.5.1", :engine => 'truffleruby', :engine_version => '1.0.0-rc6'

gem "foo"
G

bundle_ruby

expect(out).to include("ruby 2.5.1 (truffleruby 1.0.0-rc6)")
end

it "raises an error if engine is used but engine version is not" do
gemfile <<-G
source "file://#{gem_repo1}"
Expand Down
13 changes: 13 additions & 0 deletions spec/other/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@
expect(out).to eq("ruby 1.8.7 (rbx 1.2.4)")
end

it "handles truffleruby" do
gemfile <<-G
source "file://#{gem_repo1}"
ruby "2.5.1", :engine => 'truffleruby', :engine_version => '1.0.0-rc6'

gem "foo"
G

bundle "platform --ruby"

expect(out).to eq("ruby 2.5.1 (truffleruby 1.0.0-rc6)")
end

it "raises an error if engine is used but engine version is not" do
gemfile <<-G
source "file://#{gem_repo1}"
Expand Down
2 changes: 1 addition & 1 deletion spec/support/platforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def local_engine_version
when "jruby"
JRUBY_VERSION
else
raise BundlerError, "That RUBY_ENGINE is not recognized"
Copy link
Copy Markdown
Member

@colby-swandale colby-swandale Sep 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo! This is awesome! 🎉

My first question though, why are you modifying this behavior instead of adding to it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might also want to check that RUBY_ENGINE_VERSION is indeed defined? I'm not sure if all Rubies define it

Copy link
Copy Markdown
Contributor Author

@eregon eregon Sep 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was rather than adding a special case for truffleruby I'd make it general.
Every not ancient (=1.8) Ruby version should define RUBY_ENGINE_VERSION, it's a standard constant like RUBY_ENGINE, RUBY_VERSION, etc.
I can add a defined? if it causes a problem for an implementation but it seems unlikely as currently this code path was hardcoded to only support MRI, JRuby and Rubinius.

Copy link
Copy Markdown
Contributor Author

@eregon eregon Sep 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colby-swandale What do you think? Is this code fine as-is or should I change it to something else?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the PR, so let's merge it

RUBY_ENGINE_VERSION
end
end

Expand Down