Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ruby version check for bundle#install

  • Loading branch information...
commit 4f97b19c6a6b2b8e0c0da27691f575ad72723c61 1 parent 04a0dd8
Yehuda Katz and Terence Lee authored hone committed
27 lib/bundler.rb
View
@@ -43,19 +43,20 @@ def self.status_code(code)
end
end
- class GemfileNotFound < BundlerError; status_code(10) ; end
- class GemNotFound < BundlerError; status_code(7) ; end
- class GemfileError < BundlerError; status_code(4) ; end
- class InstallError < BundlerError; status_code(5) ; end
- class InstallHookError < BundlerError; status_code(6) ; end
- class PathError < BundlerError; status_code(13) ; end
- class GitError < BundlerError; status_code(11) ; end
- class DeprecatedError < BundlerError; status_code(12) ; end
- class GemspecError < BundlerError; status_code(14) ; end
- class DslError < BundlerError; status_code(15) ; end
- class ProductionError < BundlerError; status_code(16) ; end
- class InvalidOption < DslError ; end
- class HTTPError < BundlerError; status_code(17) ; end
+ class GemfileNotFound < BundlerError; status_code(10) ; end
+ class GemNotFound < BundlerError; status_code(7) ; end
+ class GemfileError < BundlerError; status_code(4) ; end
+ class InstallError < BundlerError; status_code(5) ; end
+ class InstallHookError < BundlerError; status_code(6) ; end
+ class PathError < BundlerError; status_code(13) ; end
+ class GitError < BundlerError; status_code(11) ; end
+ class DeprecatedError < BundlerError; status_code(12) ; end
+ class GemspecError < BundlerError; status_code(14) ; end
+ class DslError < BundlerError; status_code(15) ; end
+ class ProductionError < BundlerError; status_code(16) ; end
+ class InvalidOption < DslError ; end
+ class HTTPError < BundlerError; status_code(17) ; end
+ class RubyVersionMismatch < BundlerError; status_code(18) ; end
WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
9 lib/bundler/cli.rb
View
@@ -217,7 +217,9 @@ def install
# rubygems plugins sometimes hook into the gem install process
Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins)
- Installer.install(Bundler.root, Bundler.definition, opts)
+ definition = Bundler.definition
+ definition.validate_ruby!
+ Installer.install(Bundler.root, definition, opts)
Bundler.load.cache if Bundler.root.join("vendor/cache").exist? && !options["no-cache"]
if Bundler.settings[:path]
@@ -619,7 +621,10 @@ def clean
desc "ruby", "Displays the ruby version specified"
def ruby
- Bundler.ui.info Bundler.definition.ruby_version
+ ruby_version = Bundler.definition.ruby_version
+ ruby_version = "No ruby version specified" unless ruby_version
+
+ Bundler.ui.info ruby_version
end
private
20 lib/bundler/definition.rb
View
@@ -336,6 +336,26 @@ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
raise ProductionError, msg if added.any? || deleted.any? || changed.any?
end
+ def validate_ruby!
+ return unless ruby_version
+
+ system_ruby_version = Bundler::SystemRubyVersion.new
+ if diff = ruby_version.diff(system_ruby_version)
+ problem, expected, actual = diff
+
+ msg = case problem
+ when :engine
+ "Your Ruby engine is #{actual}, but your Gemfile specified #{expected}"
+ when :version
+ "Your Ruby version is #{actual}, but your Gemfile specified #{expected}"
+ when :engine_version
+ "Your #{system_ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
+ end
+
+ raise RubyVersionMismatch, msg
+ end
+ end
+
private
def nothing_changed?
2  lib/bundler/dsl.rb
View
@@ -25,7 +25,7 @@ def initialize
@groups = []
@platforms = []
@env = nil
- @ruby_version = ""
+ @ruby_version = nil
end
def eval_gemfile(gemfile)
24 lib/bundler/ruby_version.rb
View
@@ -25,9 +25,27 @@ def to_s
end
def ==(other)
- @version == other.version &&
- @engine == other.engine &&
- @engine_version == other.engine_version
+ version == other.version &&
+ engine == other.engine &&
+ engine_version == other.engine_version
+ end
+
+ # Returns a tuple of thsee things:
+ # [diff, this, other]
+ # The priority of attributes are
+ # 1. engine
+ # 2. ruby_version
+ # 3. engine_version
+ def diff(other)
+ if engine != other.engine
+ [ :engine, engine, other.engine ]
+ elsif version != other.version
+ [ :version, version, other.version ]
+ elsif engine_version != other.engine_version
+ [ :engine_version, engine_version, other.engine_version ]
+ else
+ nil
+ end
end
end
51 spec/other/ruby_spec.rb
View
@@ -91,4 +91,55 @@
exitstatus.should_not == 0
end
+
+ context "bundle install" do
+ it "installs fine when the ruby version matches" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ ruby_version "#{RUBY_VERSION}", :engine => "#{local_ruby_engine}", :engine_version => "#{local_engine_version}"
+ G
+
+ bundled_app('Gemfile.lock').should exist
+ end
+
+ it "doesn't install when the ruby version doesn't match" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ ruby_version "#{not_local_ruby_version}", :engine => "#{local_ruby_engine}", :engine_version => "#{not_local_ruby_version}"
+ G
+
+ bundled_app('Gemfile.lock').should_not exist
+ out.should == "Your Ruby version is #{RUBY_VERSION}, but your Gemfile specified #{not_local_ruby_version}"
+ end
+
+ it "doesn't install when engine doesn't match" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ ruby_version "#{RUBY_VERSION}", :engine => "#{not_local_tag}", :engine_version => "#{RUBY_VERSION}"
+ G
+
+ bundled_app('Gemfile.lock').should_not exist
+ out.should == "Your Ruby engine is #{local_ruby_engine}, but your Gemfile specified #{not_local_tag}"
+ end
+
+ it "doesn't install when engine version doesn't match" do
+ simulate_ruby_engine "jruby" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ ruby_version "#{RUBY_VERSION}", :engine => "#{local_ruby_engine}", :engine_version => "#{not_local_engine_version}"
+ G
+
+ bundled_app('Gemfile.lock').should_not exist
+ out.should == "Your #{local_ruby_engine} version is #{local_engine_version}, but your Gemfile specified #{local_ruby_engine} #{not_local_engine_version}"
+ end
+ end
+ end
end
11 spec/support/helpers.rb
View
@@ -292,6 +292,17 @@ def simulate_platform(platform)
ENV['BUNDLER_SPEC_PLATFORM'] = old if block_given?
end
+ def simulate_ruby_engine(engine, version = "1.6.0")
+ return if engine == RUBY_ENGINE
+
+ old, ENV['BUNDLER_SPEC_RUBY_ENGINE'] = ENV['BUNDLER_SPEC_RUBY_ENGINE'], engine
+ old_version, ENV['BUNDLER_SPEC_RUBY_ENGINE_VERSION'] = ENV['BUNDLER_SPEC_RUBY_ENGINE_VERSION'], version
+ yield if block_given?
+ ensure
+ ENV['BUNDLER_SPEC_RUBY_ENGINE'] = old if block_given?
+ ENV['BUNDLER_SPEC_RUBY_ENGINE_VERSION'] = old_version if block_given?
+ end
+
def simulate_bundler_version(version)
old, ENV['BUNDLER_SPEC_VERSION'] = ENV['BUNDLER_SPEC_VERSION'], version.to_s
yield if block_given?
33 spec/support/platforms.rb
View
@@ -49,5 +49,38 @@ def local_tag
def not_local_tag
[:ruby, :jruby].find { |tag| tag != local_tag }
end
+
+ def local_ruby_engine
+ ENV["BUNDLER_SPEC_RUBY_ENGINE"] || RUBY_ENGINE
+ end
+
+ def local_engine_version
+ return ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"] if ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"]
+
+ case local_ruby_engine
+ when "ruby"
+ RUBY_VERSION
+ when "rbx"
+ Rubinius::VERSION
+ when "jruby"
+ JRUBY_VERSION
+ else
+ raise BundlerError, "That RUBY_ENGINE is not recognized"
+ nil
+ end
+ end
+
+ def not_local_engine_version
+ case not_local_tag
+ when :ruby
+ not_local_ruby_version
+ when :jruby
+ "1.6.1"
+ end
+ end
+
+ def not_local_ruby_version
+ "1.12"
+ end
end
end
13 spec/support/rubygems_hax/platform.rb
View
@@ -8,4 +8,15 @@ class Gem::Platform
module Bundler
VERSION = ENV['BUNDLER_SPEC_VERSION'].dup
end
-end
+end
+
+class Object
+ if ENV['BUNDLER_SPEC_RUBY_ENGINE']
+ remove_const :RUBY_ENGINE
+ RUBY_ENGINE = ENV['BUNDLER_SPEC_RUBY_ENGINE']
+
+ if RUBY_ENGINE == "jruby"
+ JRUBY_VERSION = ENV["BUNDLER_SPEC_RUBY_ENGINE_VERSION"]
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.