From 732fed7ca714d88dc4bc5a77afab45375ff7f413 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Sun, 26 Oct 2008 02:25:52 -0400 Subject: [PATCH] Make refresh_specs more resilient. Always add vendor/gems to gem search path. Use Gem.clear_paths to ensure we get a current searcher. --- railties/lib/initializer.rb | 1 + railties/lib/rails/gem_dependency.rb | 37 ++++++++++++++++++++++------------ railties/lib/tasks/gems.rake | 3 +- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 6500b2d..e3a0e3b 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -267,6 +267,7 @@ module Rails end def add_gem_load_paths + Rails::GemDependency.add_frozen_gem_path unless @configuration.gems.empty? require "rubygems" @configuration.gems.each { |gem| gem.add_load_paths } diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 46d5fd3..3e5b3ff 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -18,11 +18,14 @@ module Rails def self.add_frozen_gem_path @@paths_loaded ||= begin - Gem.source_index = Rails::VendorGemSourceIndex.new(Gem.source_index) + source_index = Rails::VendorGemSourceIndex.new(Gem.source_index) + Gem.clear_paths + Gem.source_index = source_index # loaded before us - we can't change them, so mark them Gem.loaded_specs.each do |name, spec| @@framework_gems[name] = spec end + true end end @@ -170,19 +173,27 @@ module Rails exact_dep = Gem::Dependency.new(name, "= #{specification.version}") matches = real_gems.search(exact_dep) installed_spec = matches.first - if installed_spec - # we have a real copy - # get a fresh spec - matches should only have one element - # note that there is no reliable method to check that the loaded - # spec is the same as the copy from real_gems - Gem.activate changes - # some of the fields - real_spec = Gem::Specification.load(matches.first.loaded_from) - write_spec(directory, real_spec) - puts "Reloaded specification for #{name} from installed gems." + if File.exist?(File.dirname(spec_filename(directory))) + if installed_spec + # we have a real copy + # get a fresh spec - matches should only have one element + # note that there is no reliable method to check that the loaded + # spec is the same as the copy from real_gems - Gem.activate changes + # some of the fields + real_spec = Gem::Specification.load(matches.first.loaded_from) + write_spec(directory, real_spec) + puts "Reloaded specification for #{name} from installed gems." + else + # the gem isn't installed locally - write out our current specs + write_spec(directory, specification) + puts "Gem #{name} not loaded locally - writing out current spec." + end else - # the gem isn't installed locally - write out our current specs - write_spec(directory, specification) - puts "Gem #{name} not loaded locally - writing out current spec." + if framework_gem? + puts "Gem directory for #{name} not found - check if loading before initializer.rb." + else + puts "Something bad is going on - gem directory not found for #{name}." + end end end diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake index e2cb4b9..12c30ce 100644 --- a/railties/lib/tasks/gems.rake +++ b/railties/lib/tasks/gems.rake @@ -6,10 +6,11 @@ task :gems => 'gems:base' do puts puts "I = Installed" puts "F = Frozen" + puts "R = Framework (loaded before add_gem_load_paths)" end def print_gem_status(gem, indent=1) - code = gem.loaded? ? (gem.frozen? ? "F" : "I") : " " + code = gem.loaded? ? (gem.frozen? ? (gem.framework_gem? ? "R" : "F") : "I") : " " puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}" gem.dependencies.each { |g| print_gem_status(g, indent+1)} if gem.loaded? end -- 1.5.3.1