module Bundler::GemHelpers

def select_best_platform_match(specs, platform)

def select_best_platform_match(specs, platform)
  matching = specs.select {|spec| spec.match_platform(platform) }
  exact = matching.select {|spec| spec.platform == platform }
  return exact if exact.any?
  sorted_matching = matching.sort_by {|spec| platform_specificity_match(spec.platform, platform) }
  exemplary_spec = sorted_matching.first
  sorted_matching.take_while{|spec| same_specificity(platform, spec, exemplary_spec) && same_deps(spec, exemplary_spec) }
end