Permalink
Browse files

Have the resolver take into consideration platforms

  • Loading branch information...
1 parent 3f926f0 commit 4be41ebf93216d555d9f611b8c58bfb5c8f6d306 Carlhuda committed Dec 10, 2009
Showing with 69 additions and 24 deletions.
  1. +2 −2 lib/bundler/resolver.rb
  2. +57 −22 spec/bundler/fetcher_spec.rb
  3. +10 −0 spec/support/builders.rb
View
@@ -78,7 +78,7 @@ def initialize(sources, source_requirements)
source.gems.each do |name, specs|
# Hack to work with a regular Gem::SourceIndex
[specs].flatten.compact.each do |spec|
- next if @specs[spec.name].any? { |s| s.version == spec.version }
+ next if @specs[spec.name].any? { |s| s.version == spec.version && s.platform == spec.platform }
@specs[spec.name] << spec
end
end
@@ -228,7 +228,7 @@ def search(dependency)
match = dependency =~ spec
match &= dependency.version_requirements.prerelease? if spec.version.prerelease?
match
- end.sort_by {|s| s.version }
+ end.sort_by {|s| [s.version, s.platform == 'ruby' ? "\0" : s.platform] }
end
end
end
@@ -29,28 +29,6 @@
lambda { m.install }.should raise_error(ArgumentError)
end
- it "does not include gems that don't match the current platform" do
- pending "Need to update the fixtures for this"
- begin
- Gem.platforms = [Gem::Platform::RUBY]
- m = build_manifest <<-Gemfile
- clear_sources
- source "file://#{gem_repo1}"
- gem "do_sqlite3"
- Gemfile
-
- m.install
- bundled_app.should have_cached_gems("do_sqlite3-0.9.11")
-
- # Try out windows
- # Gem.platforms = [Gem::Platform.new("mswin32_60")]
- # finder = Bundler::Finder.new(Bundler::GemSource.new(:uri => "file://#{gem_repo1}"))
- # finder.search(build_dep("do_sqlite3", "> 0")).should only_have_specs("do_sqlite3-0.9.12-x86-mswin32-60")
- ensure
- Gem.platforms = nil
- end
- end
-
it "outputs a logger message when updating an index from source" do
m = build_manifest <<-Gemfile
clear_sources
@@ -87,4 +65,61 @@
@log_output.should have_log_message("Source 'file:#{gem_repo2}' does not support prerelease gems")
tmp_gem_path.should have_cached_gems("rack-1.0.0")
end
+
+ describe "platforms" do
+ after :each do
+ Gem.platforms = nil
+ end
+
+ def rb ; Gem::Platform::RUBY ; end
+ def java ; Gem::Platform.new [nil, "java", nil] ; end
+ def linux ; Gem::Platform.new ['x86', 'linux', nil] ; end
+
+ it "installs the gem for the correct platform" do
+ Gem.platforms = [rb]
+ install_manifest <<-Gemfile
+ clear_sources
+ source "file://#{gem_repo1}"
+ gem "platform_specific"
+ Gemfile
+
+ out = run_in_context "Bundler.require_env ; puts PLATFORM_SPECIFIC"
+ out.should == "1.0.0 RUBY"
+ end
+
+ it "raises GemNotFound if no gem for correct platform exists" do
+ Gem.platforms = [linux]
+ lambda do
+ install_manifest <<-Gemfile
+ clear_sources
+ source "file://#{gem_repo1}"
+ gem "platform_specific"
+ Gemfile
+ end.should raise_error(Bundler::GemNotFound)
+ end
+
+ it "selects java one when both are available" do
+ Gem.platforms = [rb, java]
+ install_manifest <<-Gemfile
+ clear_sources
+ source "file://#{gem_repo1}"
+ gem "platform_specific"
+ Gemfile
+
+ out = run_in_context "Bundler.require_env ; puts PLATFORM_SPECIFIC"
+ out.should == "1.0.0 JAVA"
+ end
+
+ it "raises GemNotFound if no gem for corect platform exists when gem dependencies are tied to specific sources" do
+ Gem.platforms = [rb]
+ system_gems "platform_specific-1.0-java" do
+ lambda do
+ install_manifest <<-Gemfile
+ clear_sources
+ gem "platform_specific", :bundle => false
+ Gemfile
+ end.should raise_error(Bundler::GemNotFound)
+ end
+ end
+ end
end
View
@@ -43,6 +43,16 @@ def build_repo1
s.write "lib/rack/test.rb", "RACK_TEST = '1.0'"
end
+ build_gem "platform_specific" do |s|
+ s.platform = "java"
+ s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 JAVA'"
+ end
+
+ build_gem "platform_specific" do |s|
+ s.platform = "ruby"
+ s.write "lib/platform_specific.rb", "PLATFORM_SPECIFIC = '1.0.0 RUBY'"
+ end
+
build_gem "very-simple"
build_gem "very-simple-prerelease", "1.0.pre"

0 comments on commit 4be41eb

Please sign in to comment.