Skip to content

Commit c0a1e87

Browse files
segiddinshsbt
authored andcommitted
Move most of Bundler::GemHelpers to Gem::Platform
This will help centralize wheel platform selection logic eventually Signed-off-by: Samuel Giddins <[email protected]>
1 parent 6a9af9f commit c0a1e87

22 files changed

+488
-247
lines changed

lib/bundler.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ module Bundler
5353
autoload :FeatureFlag, File.expand_path("bundler/feature_flag", __dir__)
5454
autoload :FREEBSD, File.expand_path("bundler/constants", __dir__)
5555
autoload :GemHelper, File.expand_path("bundler/gem_helper", __dir__)
56-
autoload :GemHelpers, File.expand_path("bundler/gem_helpers", __dir__)
5756
autoload :GemVersionPromoter, File.expand_path("bundler/gem_version_promoter", __dir__)
5857
autoload :Graph, File.expand_path("bundler/graph", __dir__)
5958
autoload :Index, File.expand_path("bundler/index", __dir__)
@@ -459,6 +458,10 @@ def local_platform
459458
Gem::Platform.local
460459
end
461460

461+
def generic_local_platform
462+
Gem::Platform.generic(local_platform)
463+
end
464+
462465
def default_gemfile
463466
SharedHelpers.default_gemfile
464467
end

lib/bundler/cli/outdated.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def retrieve_active_spec(definition, current_spec)
155155

156156
return active_spec if strict
157157

158-
active_specs = active_spec.source.specs.search(current_spec.name).select {|spec| spec.match_platform(current_spec.platform) }.sort_by(&:version)
158+
active_specs = active_spec.source.specs.search(current_spec.name).select {|spec| spec.installable_on_platform?(current_spec.platform) }.sort_by(&:version)
159159
if !current_spec.version.prerelease? && !options[:pre] && active_specs.size > 1
160160
active_specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? }
161161
end

lib/bundler/cli/update.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def run
9292
locked_spec = locked_info[:spec]
9393
new_spec = Bundler.definition.specs[name].first
9494
unless new_spec
95-
unless locked_spec.match_platform(Bundler.local_platform)
95+
unless locked_spec.installable_on_platform?(Bundler.local_platform)
9696
Bundler.ui.warn "Bundler attempted to update #{name} but it was not considered because it is for a different platform from the current one"
9797
end
9898

lib/bundler/current_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CurrentRuby
3232
end.freeze
3333

3434
def ruby?
35-
return true if Bundler::GemHelpers.generic_local_platform_is_ruby?
35+
return true if Bundler::MatchPlatform.generic_local_platform_is_ruby?
3636

3737
!windows? && (RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx" || RUBY_ENGINE == "maglev" || RUBY_ENGINE == "truffleruby")
3838
end

lib/bundler/definition.rb

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
module Bundler
66
class Definition
7-
include GemHelpers
8-
97
class << self
108
# Do not create or modify a lockfile (Makes #lock a noop)
119
attr_accessor :no_lock
@@ -282,7 +280,7 @@ def current_locked_dependencies
282280
end
283281

284282
def filter_relevant(dependencies)
285-
platforms_array = [generic_local_platform].freeze
283+
platforms_array = [Bundler.generic_local_platform].freeze
286284
dependencies.select do |d|
287285
d.should_include? && !d.gem_platforms(platforms_array).empty?
288286
end
@@ -456,8 +454,8 @@ def validate_platforms!
456454
return if current_platform_locked? || @platforms.include?(Gem::Platform::RUBY)
457455

458456
raise ProductionError, "Your bundle only supports platforms #{@platforms.map(&:to_s)} " \
459-
"but your local platform is #{local_platform}. " \
460-
"Add the current platform to the lockfile with\n`bundle lock --add-platform #{local_platform}` and try again."
457+
"but your local platform is #{Bundler.local_platform}. " \
458+
"Add the current platform to the lockfile with\n`bundle lock --add-platform #{Bundler.local_platform}` and try again."
461459
end
462460

463461
def normalize_platforms
@@ -568,7 +566,7 @@ def resolve_needed?
568566
end
569567

570568
def should_add_extra_platforms?
571-
!lockfile_exists? && generic_local_platform_is_ruby? && !Bundler.settings[:force_ruby_platform]
569+
!lockfile_exists? && Bundler::MatchPlatform.generic_local_platform_is_ruby? && !Bundler.settings[:force_ruby_platform]
572570
end
573571

574572
def lockfile_exists?
@@ -632,7 +630,7 @@ def resolution_base
632630
@resolution_base ||= begin
633631
last_resolve = converge_locked_specs
634632
remove_invalid_platforms!
635-
new_resolution_platforms = @current_platform_missing ? @new_platforms + [local_platform] : @new_platforms
633+
new_resolution_platforms = @current_platform_missing ? @new_platforms + [Bundler.local_platform] : @new_platforms
636634
base = Resolver::Base.new(source_requirements, expanded_dependencies, last_resolve, @platforms, locked_specs: @originally_locked_specs, unlock: @unlocking_all || @gems_to_unlock, prerelease: gem_version_promoter.pre?, prefer_local: @prefer_local, new_platforms: new_resolution_platforms)
637635
base = additional_base_requirements_to_prevent_downgrades(base)
638636
base = additional_base_requirements_to_force_updates(base)
@@ -738,8 +736,8 @@ def reresolve_without(incomplete_specs)
738736
end
739737

740738
def start_resolution
741-
local_platform_needed_for_resolvability = @most_specific_non_local_locked_platform && !@platforms.include?(local_platform)
742-
@platforms << local_platform if local_platform_needed_for_resolvability
739+
local_platform_needed_for_resolvability = @most_specific_non_local_locked_platform && !@platforms.include?(Bundler.local_platform)
740+
@platforms << Bundler.local_platform if local_platform_needed_for_resolvability
743741
add_platform(Gem::Platform::RUBY) if RUBY_ENGINE == "truffleruby"
744742

745743
result = SpecSet.new(resolver.start)
@@ -758,7 +756,7 @@ def start_resolution
758756
if result.incomplete_for_platform?(current_dependencies, @most_specific_non_local_locked_platform)
759757
@platforms.delete(@most_specific_non_local_locked_platform)
760758
elsif local_platform_needed_for_resolvability
761-
@platforms.delete(local_platform)
759+
@platforms.delete(Bundler.local_platform)
762760
end
763761
end
764762

@@ -777,17 +775,17 @@ def precompute_source_requirements_for_indirect_dependencies?
777775

778776
def current_platform_locked?
779777
@platforms.any? do |bundle_platform|
780-
generic_local_platform == bundle_platform || local_platform === bundle_platform
778+
Bundler.generic_local_platform == bundle_platform || Bundler.local_platform === bundle_platform
781779
end
782780
end
783781

784782
def add_current_platform
785-
return if @platforms.include?(local_platform)
783+
return if @platforms.include?(Bundler.local_platform)
786784

787785
@most_specific_non_local_locked_platform = find_most_specific_locked_platform
788786
return if @most_specific_non_local_locked_platform
789787

790-
@platforms << local_platform
788+
@platforms << Bundler.local_platform
791789
true
792790
end
793791

@@ -1167,7 +1165,7 @@ def dup_for_full_unlock
11671165
def remove_invalid_platforms!
11681166
return if Bundler.frozen_bundle?
11691167

1170-
skips = (@new_platforms + [local_platform]).uniq
1168+
skips = (@new_platforms + [Bundler.local_platform]).uniq
11711169

11721170
# We should probably avoid removing non-ruby platforms, since that means
11731171
# lockfile will no longer install on those platforms, so a error to give

lib/bundler/dependency.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def gem_platforms(valid_platforms)
9999
return RUBY_PLATFORM_ARRAY if force_ruby_platform
100100
return valid_platforms if platforms.empty?
101101

102-
valid_platforms.select {|p| expanded_platforms.include?(GemHelpers.generic(p)) }
102+
valid_platforms.select {|p| expanded_platforms.include?(Gem::Platform.generic(p)) }
103103
end
104104

105105
def expanded_platforms

lib/bundler/dsl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def gemspec(opts = nil)
7373
case specs_by_name_and_version.size
7474
when 1
7575
specs = specs_by_name_and_version.values.first
76-
spec = specs.find {|s| s.match_platform(Bundler.local_platform) } || specs.first
76+
spec = specs.find {|s| s.installable_on_platform?(Bundler.local_platform) } || specs.first
7777

7878
@gemspecs << spec
7979

lib/bundler/gem_helpers.rb

Lines changed: 0 additions & 144 deletions
This file was deleted.

lib/bundler/lazy_specification.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ def materialize_for_installation
142142
end
143143
else
144144
materialize([name, version]) do |matching_specs|
145-
target_platform = source.is_a?(Source::Path) ? platform : local_platform
145+
target_platform = source.is_a?(Source::Path) ? platform : Bundler.local_platform
146146

147-
installable_candidates = GemHelpers.select_best_platform_match(matching_specs, target_platform)
147+
installable_candidates = MatchPlatform.select_best_platform_match(matching_specs, target_platform)
148148

149149
specification = choose_compatible(installable_candidates, fallback_to_non_installable: false)
150150
return specification unless specification.nil?
151151

152152
if target_platform != platform
153-
installable_candidates = GemHelpers.select_best_platform_match(matching_specs, platform)
153+
installable_candidates = MatchPlatform.select_best_platform_match(matching_specs, platform)
154154
end
155155

156156
choose_compatible(installable_candidates)
@@ -190,7 +190,7 @@ def use_exact_resolved_specifications?
190190
end
191191

192192
def ruby_platform_materializes_to_ruby_platform?
193-
generic_platform = generic_local_platform == Gem::Platform::JAVA ? Gem::Platform::JAVA : Gem::Platform::RUBY
193+
generic_platform = Bundler.generic_local_platform == Gem::Platform::JAVA ? Gem::Platform::JAVA : Gem::Platform::RUBY
194194

195195
(most_specific_locked_platform != generic_platform) || force_ruby_platform || Bundler.settings[:force_ruby_platform]
196196
end

lib/bundler/lockfile_parser.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
module Bundler
66
class LockfileParser
7-
include GemHelpers
8-
97
class Position
108
attr_reader :line, :column
119
def initialize(line, column)
@@ -157,7 +155,7 @@ def initialize(lockfile)
157155
end
158156

159157
@most_specific_locked_platform = @platforms.min_by do |bundle_platform|
160-
platform_specificity_match(bundle_platform, local_platform)
158+
Gem::Platform.platform_specificity_match(bundle_platform, Bundler.local_platform)
161159
end
162160
@specs = @specs.values.sort_by!(&:full_name).each do |spec|
163161
spec.most_specific_locked_platform = @most_specific_locked_platform

0 commit comments

Comments
 (0)