Skip to content

Instantly share code, notes, and snippets.

@adamwiggins
Created July 20, 2008 22:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamwiggins/36 to your computer and use it in GitHub Desktop.
Save adamwiggins/36 to your computer and use it in GitHub Desktop.
diff --git a/bin/bundle b/bin/bundle
index 6efdf51..7b57fac 100755
--- a/bin/bundle
+++ b/bin/bundle
@@ -9,8 +9,23 @@ $:.each do |path|
end
require 'bundler/cli'
+
begin
+ require "rubygems"
+
+ if ENV["PROFILE"]
+ require "ruby-prof"
+ RubyProf.measure_mode = RubyProf::WALL_TIME
+ RubyProf.start
+ end
+
Bundler::CLI.start
+
+ if ENV["PROFILE"]
+ result = RubyProf.stop
+ printer = RubyProf::CallStackPrinter.new(result)
+ printer.print(File.open("/Users/wycats/Code/cool_stuff/bundler/output.html", "w"), :min_percent => 0)
+ end
rescue Bundler::BundlerError => e
Bundler.ui.error e.message
Bundler.ui.debug e.backtrace.join("\n")
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index a59d19a..6cbc796 100644
--- a/lib/bundler/index.rb
+++ b/lib/bundler/index.rb
@@ -8,6 +8,9 @@ module Bundler
i
end
+ attr_reader :specs
+ protected :specs
+
def initialize
@cache = {}
@specs = Hash.new { |h,k| h[k] = [] }
@@ -17,7 +20,10 @@ module Bundler
super
@cache = {}
@specs = Hash.new { |h,k| h[k] = [] }
- merge!(o)
+
+ o.specs.each do |name, array|
+ @specs[name] = array.dup
+ end
end
def empty?
@@ -59,7 +65,7 @@ module Bundler
arr = @specs[spec.name]
arr.delete_if do |s|
- s.version == spec.version && s.platform == spec.platform
+ same_version?(s.version, spec.version) && s.platform == spec.platform
end
arr << spec
@@ -91,10 +97,16 @@ module Bundler
def search_by_spec(spec)
@specs[spec.name].select do |s|
- s.version == spec.version && Gem::Platform.new(s.platform) == Gem::Platform.new(spec.platform)
+ same_version?(s.version, spec.version) && Gem::Platform.new(s.platform) == Gem::Platform.new(spec.platform)
end
end
+ def same_version?(a, b)
+ regex = /^(.*?)(?:\.0)*$/
+
+ ret = a.to_s[regex, 1] == b.to_s[regex, 1]
+ end
+
def spec_satisfies_dependency?(spec, dep)
return false unless dep.name === spec.name
dep.requirement.satisfied_by?(spec.version)
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index 6f3e15e..60a3cb7 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -159,7 +159,7 @@ module Bundler
@installed_specs ||= begin
idx = Index.new
have_bundler = false
- Gem::SourceIndex.from_installed_gems.to_a.reverse.each do |dont_use_this_var, spec|
+ Gem.source_index.to_a.reverse.each do |dont_use_this_var, spec|
next if spec.name == 'bundler' && spec.version.to_s != VERSION
have_bundler = true if spec.name == 'bundler'
spec.source = self
@@ -186,27 +186,24 @@ module Bundler
def cached_specs
@cached_specs ||= begin
- idx = Index.new
- @caches.each do |path|
- Dir["#{path}/*.gem"].each do |gemfile|
- next if gemfile =~ /bundler\-[\d\.]+?\.gem/
-
- # Try to skip decompressing the gem to get at the gemspec if possible
- cached_gemspec = gemfile.gsub(%r{cache/(.*?)\.gem}, 'specifications/\1.gemspec')
- s = Gem::Specification.load(cached_gemspec) if File.exist?(cached_gemspec)
-
- begin
- s ||= Gem::Format.from_file_by_path(gemfile).spec
- rescue Gem::Package::FormatError
- raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted."
- end
+ idx = installed_specs.dup
+
+ path = Bundler.app_cache
+ Dir["#{path}/*.gem"].each do |gemfile|
+ next if gemfile =~ /bundler\-[\d\.]+?\.gem/
- s.source = self
- idx << s
+ begin
+ s ||= Gem::Format.from_file_by_path(gemfile).spec
+ rescue Gem::Package::FormatError
+ raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted."
end
+
+ s.source = self
+ idx << s
end
- idx
end
+
+ idx
end
def remote_specs(dependencies = nil)
diff --git a/spec/support/artifice/endpoint.rb b/spec/support/artifice/endpoint.rb
index e28efe4..d35c1c8 100644
--- a/spec/support/artifice/endpoint.rb
+++ b/spec/support/artifice/endpoint.rb
@@ -7,6 +7,7 @@ $LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/rack-*/lib")].first}"
$LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/rack-*/lib")].last}"
$LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/tilt*/lib")].first}"
$LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/sinatra*/lib")].first}"
+
require 'artifice'
require 'sinatra/base'
diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb
index e07f785..dc213c0 100644
--- a/spec/support/rubygems_ext.rb
+++ b/spec/support/rubygems_ext.rb
@@ -9,8 +9,8 @@ module Spec
unless File.exist?("#{Path.base_system_gems}")
FileUtils.mkdir_p(Path.base_system_gems)
- puts "running `gem install builder rake fakeweb artifice sinatra --no-rdoc --no-ri`"
- `gem install builder rake fakeweb artifice sinatra --no-rdoc --no-ri`
+ puts "running `gem install builder rake fakeweb artifice sinatra ruby-prof --no-rdoc --no-ri`"
+ `gem install builder rake fakeweb artifice sinatra ruby-prof --no-rdoc --no-ri`
end
ENV['HOME'] = Path.home.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment