diff options
author | Carl Lerche <carllerche@mac.com> | 2010-07-24 11:15:04 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-07-24 11:16:32 -0700 |
commit | b2e678bdb6e2baa8cd85952a4e5d4a76e4485ae9 (patch) | |
tree | ddb7fca2785cf769ec5f548ced615e6c093bbf34 | |
parent | e6c3bebfbd6d3ec0490aea8d184b81d8cf0eb0fb (diff) | |
download | bundler-b2e678bdb6e2baa8cd85952a4e5d4a76e4485ae9.tar.gz |
Remove the #to_generic monkey patch to Gem::Platform
-rw-r--r-- | lib/bundler/definition.rb | 6 | ||||
-rw-r--r-- | lib/bundler/lazy_specification.rb | 4 | ||||
-rw-r--r-- | lib/bundler/remote_specification.rb | 4 | ||||
-rw-r--r-- | lib/bundler/resolver.rb | 4 | ||||
-rw-r--r-- | lib/bundler/rubygems_ext.rb | 121 | ||||
-rw-r--r-- | spec/lock/flex_spec.rb | 31 | ||||
-rw-r--r-- | spec/other/ext_spec.rb | 8 | ||||
-rw-r--r-- | spec/support/helpers.rb | 1 | ||||
-rw-r--r-- | spec/support/platforms.rb | 8 |
9 files changed, 105 insertions, 82 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index b456075663..1c8334674d 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -2,6 +2,8 @@ require "digest/sha1" module Bundler class Definition + include GemHelpers + attr_reader :dependencies, :platforms, :sources def self.build(gemfile, lockfile, unlock) @@ -52,7 +54,7 @@ module Bundler @unlock[:gems] ||= [] @unlock[:sources] ||= [] - current_platform = Gem.platforms.map { |p| p.to_generic }.compact.last + current_platform = Gem.platforms.map { |p| generic(p) }.compact.last @platforms |= [current_platform] converge @@ -267,7 +269,7 @@ module Bundler deps = [] dependencies.each do |dep| dep.gem_platforms(@platforms).each do |p| - deps << DepProxy.new(dep, p) if remote || p == Gem::Platform.local.to_generic + deps << DepProxy.new(dep, p) if remote || p == generic(Gem::Platform.local) end end deps diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 4015752cf6..9db9b0edce 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -3,7 +3,7 @@ require "rubygems/spec_fetcher" module Bundler class LazySpecification - include Gem::MatchPlatform + include MatchPlatform attr_reader :name, :version, :dependencies, :platform attr_accessor :source @@ -68,4 +68,4 @@ module Bundler end end -end
\ No newline at end of file +end diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb index cde4a73356..3851014cf4 100644 --- a/lib/bundler/remote_specification.rb +++ b/lib/bundler/remote_specification.rb @@ -7,7 +7,7 @@ module Bundler # be seeded with what we're given from the source's abbreviated index - the # full specification will only be fetched when necesary. class RemoteSpecification - include Gem::MatchPlatform + include MatchPlatform attr_reader :name, :version, :platform attr_accessor :source @@ -56,4 +56,4 @@ module Bundler end end end -end
\ No newline at end of file +end diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 5852d87e23..82e2e2827b 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -27,6 +27,8 @@ module Bundler Gem::Platform::MING] class SpecGroup < Array + include GemHelpers + attr_reader :activated, :required_by def initialize(a) @@ -52,7 +54,7 @@ module Bundler @activated.each do |p| if s = @specs[p] - platform = Gem::Platform.new(s.platform).to_generic + platform = generic(Gem::Platform.new(s.platform)) next if specs[platform] lazy_spec = LazySpecification.new(name, version, platform, source) diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 8429d439a3..5c62c1c772 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -8,61 +8,15 @@ end require 'rubygems' require 'rubygems/specification' -module Bundler - class DepProxy - - attr_reader :required_by, :__platform, :dep - - def initialize(dep, platform) - @dep, @__platform, @required_by = dep, platform, [] - end - - def hash - @hash ||= dep.hash - end - - def ==(o) - dep == o.dep && __platform == o.__platform - end - - alias eql? == - - def type - @dep.type - end - - def to_s - @dep.to_s - end - - private - - def method_missing(*args) - @dep.send(*args) - end - - end -end - module Gem @loaded_stacks = Hash.new { |h,k| h[k] = [] } - module MatchPlatform - def match_platform(p) - Gem::Platform::RUBY == platform or - platform.nil? or p == platform or - Gem::Platform.new(platform).to_generic == p - end - end - class Specification attr_accessor :source, :location, :relative_loaded_from alias_method :rg_full_gem_path, :full_gem_path alias_method :rg_loaded_from, :loaded_from - include MatchPlatform - def full_gem_path source.respond_to?(:path) ? Pathname.new(loaded_from).dirname.expand_path.to_s : @@ -169,22 +123,81 @@ module Gem MSWIN = Gem::Platform.new('mswin32') MING = Gem::Platform.new('x86-mingw32') - GENERIC_CACHE = {} - - class << RUBY - def to_generic ; self ; end + def hash + @cpu.hash + @os.hash + @version.hash end - GENERICS = [JAVA, MSWIN, MING, RUBY] + alias eql? == + end +end + +module Bundler + class DepProxy + + attr_reader :required_by, :__platform, :dep + + def initialize(dep, platform) + @dep, @__platform, @required_by = dep, platform, [] + end def hash - @cpu.hash + @os.hash + @version.hash + @hash ||= dep.hash + end + + def ==(o) + dep == o.dep && __platform == o.__platform end alias eql? == - def to_generic - GENERIC_CACHE[self] ||= GENERICS.find { |p| self =~ p } || RUBY + def type + @dep.type + end + + def to_s + @dep.to_s end + + private + + def method_missing(*args) + @dep.send(*args) + end + + end + + module GemHelpers + + GENERIC_CACHE = {} + GENERICS = [ + Gem::Platform::JAVA, + Gem::Platform::MSWIN, + Gem::Platform::MING, + Gem::Platform::RUBY + ] + + def generic(p) + if p == Gem::Platform::RUBY + return p + end + + GENERIC_CACHE[p] ||= GENERICS.find { |p2| p =~ p2 } || Gem::Platform::RUBY + end + end + + module MatchPlatform + include GemHelpers + + def match_platform(p) + Gem::Platform::RUBY == platform or + platform.nil? or p == platform or + generic(Gem::Platform.new(platform)) == p + end + end +end + +module Gem + class Specification + include Bundler::MatchPlatform end end diff --git a/spec/lock/flex_spec.rb b/spec/lock/flex_spec.rb index 160121933b..70a01edb6e 100644 --- a/spec/lock/flex_spec.rb +++ b/spec/lock/flex_spec.rb @@ -1,6 +1,7 @@ require "spec_helper" describe "the lockfile format" do + include Bundler::GemHelpers def be_with_diff(expected) # Trim the leading spaces @@ -33,7 +34,7 @@ describe "the lockfile format" do rack (1.0.0) PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES rack @@ -56,7 +57,7 @@ describe "the lockfile format" do rack PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES rack-obama @@ -79,7 +80,7 @@ describe "the lockfile format" do rack PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES rack-obama (>= 1.0) @@ -129,7 +130,7 @@ describe "the lockfile format" do specs: PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES foo! @@ -156,7 +157,7 @@ describe "the lockfile format" do specs: PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES foo! @@ -183,7 +184,7 @@ describe "the lockfile format" do specs: PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES foo! @@ -210,7 +211,7 @@ describe "the lockfile format" do specs: PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES foo! @@ -234,7 +235,7 @@ describe "the lockfile format" do specs: PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES foo! @@ -264,7 +265,7 @@ describe "the lockfile format" do rack PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES actionpack @@ -302,7 +303,7 @@ describe "the lockfile format" do rake (0.8.7) PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES rails @@ -325,7 +326,7 @@ describe "the lockfile format" do rack PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES rack-obama (>= 1.0) @@ -348,7 +349,7 @@ describe "the lockfile format" do rack PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES rack-obama (>= 1.0) @@ -373,7 +374,7 @@ describe "the lockfile format" do specs: PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES foo @@ -398,7 +399,7 @@ describe "the lockfile format" do specs: PLATFORMS - #{Gem::Platform.local.to_generic} + #{generic(Gem::Platform.local)} DEPENDENCIES foo @@ -425,7 +426,7 @@ describe "the lockfile format" do gem "rack" G - platforms = ['java', Gem::Platform.local.to_generic.to_s].sort + platforms = ['java', generic(Gem::Platform.local).to_s].sort lockfile_should_be <<-G GEM diff --git a/spec/other/ext_spec.rb b/spec/other/ext_spec.rb index caf2c15756..f91bc05ecd 100644 --- a/spec/other/ext_spec.rb +++ b/spec/other/ext_spec.rb @@ -7,8 +7,10 @@ describe "Gem::Specification#match_platform" do end end -describe "Gem::Platform#to_generic" do +describe "Bundler::GemHelpers#generic" do + include Bundler::GemHelpers + it "works" do - pl('x86-darwin-10').to_generic.should == pl('ruby') + generic(pl('x86-darwin-10')).should == pl('ruby') end -end
\ No newline at end of file +end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 77e2c7e0e9..8f40caa80f 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -1,6 +1,7 @@ module Spec module Helpers def reset! + @in_p, @out_p, @err_p = nil, nil, nil Dir["#{tmp}/{gems/*,*}"].each do |dir| next if %(base remote1 gems rubygems_1_3_5 rubygems_1_3_6 rubygems_master).include?(File.basename(dir)) if File.owned?(dir) diff --git a/spec/support/platforms.rb b/spec/support/platforms.rb index b2b9526694..f009de39dd 100644 --- a/spec/support/platforms.rb +++ b/spec/support/platforms.rb @@ -1,5 +1,7 @@ module Spec module Platforms + include Bundler::GemHelpers + def rb Gem::Platform::RUBY end @@ -25,11 +27,11 @@ module Spec end def local - Gem::Platform.local.to_generic + generic(Gem::Platform.local) end def not_local - all_platforms.find { |p| p != Gem::Platform.local.to_generic } + all_platforms.find { |p| p != generic(Gem::Platform.local) } end def local_tag @@ -44,4 +46,4 @@ module Spec [:ruby, :jruby].find { |tag| tag != local_tag } end end -end
\ No newline at end of file +end |