Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specific_platform and cache_all with bundle cache --all-platforms #4022

Merged
merged 7 commits into from Oct 22, 2020
Merged
6 changes: 5 additions & 1 deletion bundler/lib/bundler/lazy_specification.rb
Expand Up @@ -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|
Expand Down
134 changes: 91 additions & 43 deletions bundler/spec/install/gemfile/specific_platform_spec.rb
Expand Up @@ -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 }
Expand All @@ -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")])
Expand All @@ -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"
Expand All @@ -94,6 +89,7 @@
end

it "adds the foreign platform" do
setup_multiplatform_gem
install_gemfile(google_protobuf)
bundle "lock --add-platform=#{x64_mingw}"

Expand All @@ -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}"

Expand All @@ -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
74 changes: 2 additions & 72 deletions bundler/spec/lock/lockfile_spec.rb
Expand Up @@ -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"

Expand Down Expand Up @@ -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)}/
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions bundler/test_gems.rb.lock
Expand Up @@ -24,6 +24,7 @@ GEM
PLATFORMS
java
ruby
x64-mingw32

DEPENDENCIES
artifice (~> 0.6.0)
Expand Down
4 changes: 3 additions & 1 deletion dev_gems.rb.lock
Expand Up @@ -68,6 +68,8 @@ GEM
PLATFORMS
java
ruby
x64-mingw32
x86_64-linux

DEPENDENCIES
minitest (~> 5.14, >= 5.14.2)
Expand All @@ -85,4 +87,4 @@ DEPENDENCIES
webrick (~> 1.6)

BUNDLED WITH
2.1.4
2.2.0.rc.2