diff --git a/bundler/lib/bundler/lazy_specification.rb b/bundler/lib/bundler/lazy_specification.rb index 546b8d9b098f..279d00afa743 100644 --- a/bundler/lib/bundler/lazy_specification.rb +++ b/bundler/lib/bundler/lazy_specification.rb @@ -79,7 +79,11 @@ def __materialize__ @specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name source.gemspec.tap {|s| s.source = source } else - search_object = Bundler.feature_flag.specific_platform? || Bundler.settings[:force_ruby_platform] ? self : Dependency.new(name, version) + search_object = if source.is_a?(Source::Path) + Dependency.new(name, version) + else + Bundler.feature_flag.specific_platform? || Bundler.settings[:force_ruby_platform] ? self : Dependency.new(name, version) + end platform_object = Gem::Platform.new(platform) candidates = source.specs.search(search_object) same_platform_candidates = candidates.select do |spec| diff --git a/bundler/spec/install/gemfile/specific_platform_spec.rb b/bundler/spec/install/gemfile/specific_platform_spec.rb index 959ffbf615ee..44991ef982d2 100644 --- a/bundler/spec/install/gemfile/specific_platform_spec.rb +++ b/bundler/spec/install/gemfile/specific_platform_spec.rb @@ -3,49 +3,6 @@ RSpec.describe "bundle install with specific_platform enabled" do before do bundle "config set specific_platform true" - - build_repo2 do - build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") - build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "x86_64-linux" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "x86-mingw32" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "x86-linux" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "x64-mingw32" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "universal-darwin" } - - build_gem("google-protobuf", "3.0.0.alpha.5.0.5") {|s| s.platform = "x86_64-linux" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.5") {|s| s.platform = "x86-linux" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.5") {|s| s.platform = "x64-mingw32" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.5") {|s| s.platform = "x86-mingw32" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.5") - - build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "universal-darwin" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "x86_64-linux" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "x86-mingw32" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "x86-linux" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "x64-mingw32" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.4") - - build_gem("google-protobuf", "3.0.0.alpha.5.0.3") - build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "x86_64-linux" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "x86-mingw32" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "x86-linux" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "x64-mingw32" } - build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "universal-darwin" } - - build_gem("google-protobuf", "3.0.0.alpha.4.0") - build_gem("google-protobuf", "3.0.0.alpha.3.1.pre") - build_gem("google-protobuf", "3.0.0.alpha.3") - build_gem("google-protobuf", "3.0.0.alpha.2.0") - build_gem("google-protobuf", "3.0.0.alpha.1.1") - build_gem("google-protobuf", "3.0.0.alpha.1.0") - - build_gem("facter", "2.4.6") - build_gem("facter", "2.4.6") do |s| - s.platform = "universal-darwin" - s.add_runtime_dependency "CFPropertyList" - end - build_gem("CFPropertyList") - end end let(:google_protobuf) { <<-G } @@ -57,6 +14,7 @@ before { simulate_platform "x86_64-darwin-15" } it "locks to both the specific darwin platform and ruby" do + setup_multiplatform_gem install_gemfile(google_protobuf) allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(the_bundle.locked_gems.platforms).to eq([pl("ruby"), pl("x86_64-darwin-15")]) @@ -68,13 +26,50 @@ end it "caches both the universal-darwin and ruby gems when --all-platforms is passed" do + setup_multiplatform_gem gemfile(google_protobuf) bundle "package --all-platforms" expect([cached_gem("google-protobuf-3.0.0.alpha.5.0.5.1"), cached_gem("google-protobuf-3.0.0.alpha.5.0.5.1-universal-darwin")]). to all(exist) end + it "caches multiplatform git gems with a single gemspec when --all-platforms is passed" do + git = build_git "pg_array_parser", "1.0" + + gemfile <<-G + gem "pg_array_parser", :git => "#{lib_path("pg_array_parser-1.0")}" + G + + lockfile <<-L + GIT + remote: #{lib_path("pg_array_parser-1.0")} + revision: #{git.ref_for("master")} + specs: + pg_array_parser (1.0-java) + pg_array_parser (1.0) + + GEM + specs: + + PLATFORMS + java + #{lockfile_platforms} + + DEPENDENCIES + pg_array_parser! + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "config set --local cache_all true" + bundle "cache --all-platforms" + + expect(err).to be_empty + end + it "uses the platform-specific gem with extra dependencies" do + setup_multiplatform_gem_with_different_dependencies_per_platform install_gemfile <<-G source "#{file_uri_for(gem_repo2)}" gem "facter" @@ -94,6 +89,7 @@ end it "adds the foreign platform" do + setup_multiplatform_gem install_gemfile(google_protobuf) bundle "lock --add-platform=#{x64_mingw}" @@ -106,6 +102,7 @@ end it "falls back on plain ruby when that version doesnt have a platform-specific gem" do + setup_multiplatform_gem install_gemfile(google_protobuf) bundle "lock --add-platform=#{java}" @@ -117,4 +114,55 @@ end end end + + private + + def setup_multiplatform_gem + build_repo2 do + build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") + build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "x86_64-linux" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "x86-mingw32" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "x86-linux" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "x64-mingw32" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.5.1") {|s| s.platform = "universal-darwin" } + + build_gem("google-protobuf", "3.0.0.alpha.5.0.5") {|s| s.platform = "x86_64-linux" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.5") {|s| s.platform = "x86-linux" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.5") {|s| s.platform = "x64-mingw32" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.5") {|s| s.platform = "x86-mingw32" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.5") + + build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "universal-darwin" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "x86_64-linux" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "x86-mingw32" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "x86-linux" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.4") {|s| s.platform = "x64-mingw32" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.4") + + build_gem("google-protobuf", "3.0.0.alpha.5.0.3") + build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "x86_64-linux" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "x86-mingw32" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "x86-linux" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "x64-mingw32" } + build_gem("google-protobuf", "3.0.0.alpha.5.0.3") {|s| s.platform = "universal-darwin" } + + build_gem("google-protobuf", "3.0.0.alpha.4.0") + build_gem("google-protobuf", "3.0.0.alpha.3.1.pre") + build_gem("google-protobuf", "3.0.0.alpha.3") + build_gem("google-protobuf", "3.0.0.alpha.2.0") + build_gem("google-protobuf", "3.0.0.alpha.1.1") + build_gem("google-protobuf", "3.0.0.alpha.1.0") + end + end + + def setup_multiplatform_gem_with_different_dependencies_per_platform + build_repo2 do + build_gem("facter", "2.4.6") + build_gem("facter", "2.4.6") do |s| + s.platform = "universal-darwin" + s.add_runtime_dependency "CFPropertyList" + end + build_gem("CFPropertyList") + end + end end diff --git a/bundler/spec/lock/lockfile_spec.rb b/bundler/spec/lock/lockfile_spec.rb index 98272811f871..f29fbf2cbd9c 100644 --- a/bundler/spec/lock/lockfile_spec.rb +++ b/bundler/spec/lock/lockfile_spec.rb @@ -417,34 +417,6 @@ expect(the_bundle).to include_gems "net-sftp 1.1.1", "net-ssh 1.0.0" end - it "generates a simple lockfile for a single pinned source, gem with a version requirement", :bundler => "< 3" do - git = build_git "foo" - - install_gemfile <<-G - gem "foo", :git => "#{lib_path("foo-1.0")}" - G - - lockfile_should_be <<-G - GIT - remote: #{lib_path("foo-1.0")} - revision: #{git.ref_for("master")} - specs: - foo (1.0) - - GEM - specs: - - PLATFORMS - #{lockfile_platforms} - - DEPENDENCIES - foo! - - BUNDLED WITH - #{Bundler::VERSION} - G - end - it "generates a simple lockfile for a single pinned source, gem with a version requirement" do git = build_git "foo" @@ -968,7 +940,7 @@ G end - it "keeps existing platforms in the lockfile", :bundler => "< 3" do + it "keeps existing platforms in the lockfile" do lockfile <<-G GEM remote: #{file_uri_for(gem_repo2)}/ @@ -999,49 +971,7 @@ PLATFORMS java - #{generic_local_platform} - - DEPENDENCIES - rack - - BUNDLED WITH - #{Bundler::VERSION} - G - end - - it "keeps existing platforms in the lockfile", :bundler => "3" do - lockfile <<-G - GEM - remote: #{file_uri_for(gem_repo2)}/ - specs: - rack (1.0.0) - - PLATFORMS - java - - DEPENDENCIES - rack - - BUNDLED WITH - #{Bundler::VERSION} - G - - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}/" - - gem "rack" - G - - lockfile_should_be <<-G - GEM - remote: #{file_uri_for(gem_repo2)}/ - specs: - rack (1.0.0) - - PLATFORMS - java - #{generic_local_platform} - #{specific_local_platform} + #{lockfile_platforms} DEPENDENCIES rack diff --git a/bundler/test_gems.rb.lock b/bundler/test_gems.rb.lock index 5eedc692ac32..0cd61430213c 100644 --- a/bundler/test_gems.rb.lock +++ b/bundler/test_gems.rb.lock @@ -24,6 +24,7 @@ GEM PLATFORMS java ruby + x64-mingw32 DEPENDENCIES artifice (~> 0.6.0) diff --git a/dev_gems.rb.lock b/dev_gems.rb.lock index 200208fcc9f7..2e98f9905954 100644 --- a/dev_gems.rb.lock +++ b/dev_gems.rb.lock @@ -68,6 +68,8 @@ GEM PLATFORMS java ruby + x64-mingw32 + x86_64-linux DEPENDENCIES minitest (~> 5.14, >= 5.14.2) @@ -85,4 +87,4 @@ DEPENDENCIES webrick (~> 1.6) BUNDLED WITH - 2.1.4 + 2.2.0.rc.2