Skip to content

Commit

Permalink
Merge pull request #3909 from rubygems/platform_issues
Browse files Browse the repository at this point in the history
Fix platform issues when running under a frozen bundle
  • Loading branch information
deivid-rodriguez committed Sep 3, 2020
2 parents 2ceb821 + b475adf commit 0ab446f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
23 changes: 11 additions & 12 deletions bundler/lib/bundler/definition.rb
Expand Up @@ -204,10 +204,6 @@ def removed_specs
@locked_specs - specs
end

def new_platform?
@new_platform
end

def missing_specs
missing = []
resolve.materialize(requested_dependencies, missing)
Expand Down Expand Up @@ -557,10 +553,9 @@ def add_platforms
end

def current_platforms
current_platform = Bundler.local_platform
[].tap do |platforms|
platforms << current_platform if Bundler.feature_flag.specific_platform?
platforms << generic(current_platform)
platforms << local_platform if Bundler.feature_flag.specific_platform?
platforms << generic_local_platform
end
end

Expand Down Expand Up @@ -891,18 +886,22 @@ def ruby_version_requirements(ruby_version)
end

def expand_dependencies(dependencies, remote = false)
sorted_platforms = Resolver.sort_platforms(@platforms)
deps = []
dependencies.each do |dep|
dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name)
next if !remote && !dep.current_platform?
dep.gem_platforms(sorted_platforms).each do |p|
deps << DepProxy.new(dep, p) if remote || p == generic_local_platform
end
next unless remote || dep.current_platform?
target_platforms = dep.gem_platforms(remote ? Resolver.sort_platforms(@platforms) : [generic_local_platform])
deps += expand_dependency_with_platforms(dep, target_platforms)
end
deps
end

def expand_dependency_with_platforms(dep, platforms)
platforms.map do |p|
DepProxy.new(dep, p)
end
end

def dependencies_for(groups)
current_dependencies.reject do |d|
(d.groups & groups).empty?
Expand Down
7 changes: 6 additions & 1 deletion bundler/lib/bundler/gem_helpers.rb
Expand Up @@ -24,10 +24,15 @@ def generic(p)
module_function :generic

def generic_local_platform
generic(Bundler.local_platform)
generic(local_platform)
end
module_function :generic_local_platform

def local_platform
Bundler.local_platform
end
module_function :local_platform

def platform_specificity_match(spec_platform, user_platform)
spec_platform = Gem::Platform.new(spec_platform)
return PlatformMatch::EXACT_MATCH if spec_platform == user_platform
Expand Down
25 changes: 25 additions & 0 deletions bundler/spec/install/gemfile/platform_spec.rb
Expand Up @@ -50,6 +50,31 @@
expect(the_bundle).to include_gems "platform_specific 1.0 JAVA"
end

it "pulls the pure ruby version on jruby if the java platform is not present in the lockfile and bundler is run in frozen mode", :jruby do
lockfile <<-G
GEM
remote: #{file_uri_for(gem_repo1)}
specs:
platform_specific (1.0)
PLATFORMS
ruby
DEPENDENCIES
platform_specific
G

bundle "config set --local frozen true"

install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "platform_specific"
G

expect(the_bundle).to include_gems "platform_specific 1.0 RUBY"
end

it "works with gems that have different dependencies" do
simulate_platform "java"
install_gemfile <<-G
Expand Down

0 comments on commit 0ab446f

Please sign in to comment.