From 30b63b090c9ab4f733f91b0141100865e8bc99ac Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Sun, 6 Jun 2010 13:02:17 -0700 Subject: Get the basic platform DSL working --- lib/bundler/definition.rb | 1 + lib/bundler/dependency.rb | 27 +++++++++++++++++++++++++++ spec/install/gems/platform_spec.rb | 16 ++++++++++++++-- spec/support/matchers.rb | 6 +++++- spec/support/platforms.rb | 14 ++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 5f07ebbc27..e22ab9c159 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -66,6 +66,7 @@ module Bundler def specs_for(groups) deps = dependencies.select { |d| (d.groups & groups).any? } + deps.delete_if { |d| !d.current_platform? } specs.for(expand_dependencies(deps)) end diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 1d0a912d96..060ccce592 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -40,6 +40,11 @@ module Bundler platforms end + def current_platform? + return true if @platforms.empty? + @platforms.any? { |p| send("#{p}?") } + end + def to_lock out = " #{name}" @@ -51,5 +56,27 @@ module Bundler out << "\n" end + + private + + def ruby? + !mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx") + end + + def ruby_18? + ruby? && RUBY_VERSION < "1.9" + end + + def ruby_19? + ruby? && RUBY_VERSION >= "1.9" + end + + def jruby? + RUBY_ENGINE == "jruby" + end + + def mswin? + # w0t? + end end end diff --git a/spec/install/gems/platform_spec.rb b/spec/install/gems/platform_spec.rb index e8e2020d25..e1b00bf8cf 100644 --- a/spec/install/gems/platform_spec.rb +++ b/spec/install/gems/platform_spec.rb @@ -87,15 +87,27 @@ end # TODO: Don't make the tests hardcoded to a platform describe "bundle install with platform conditionals" do - it "works" do + it "installs gems tagged w/ the current platform" do install_gemfile <<-G source "file://#{gem_repo1}" - platforms :ruby do + platforms :#{local_tag} do gem "nokogiri" end G should_be_installed "nokogiri 1.4.2" end + + it "doesn't install gems tagged w/ a different platform" do + install_gemfile <<-G + source "file://#{gem_repo1}" + + platforms :#{not_local_tag} do + gem "nokogiri" + end + G + + should_not_be_installed "nokogiri" + end end \ No newline at end of file diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index c70522c3c9..ba32897ac2 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -53,7 +53,11 @@ module Spec puts "WIN" end R - out.should == "WIN" || Gem::Version.new(out).should_not == Gem::Version.new(version) + if version.nil? || out == "WIN" + out.should == "WIN" + else + Gem::Version.new(out).should_not == Gem::Version.new(version) + end end end diff --git a/spec/support/platforms.rb b/spec/support/platforms.rb index 18fa233183..e17573855a 100644 --- a/spec/support/platforms.rb +++ b/spec/support/platforms.rb @@ -27,5 +27,19 @@ module Spec def not_local all_platforms.reject { |p| p == Gem::Platform.local } end + + def local_tag + if RUBY_PLATFORM == "java" + :jruby + elsif RUBY_VERSION >= "1.9" + :ruby_19 + else + :ruby_18 + end + end + + def not_local_tag + [:ruby_18, :ruby_19, :jruby].find { |tag| tag != local_tag } + end end end \ No newline at end of file -- cgit v1.2.1