diff options
Diffstat (limited to 'lib/rubygems/stub_specification.rb')
-rw-r--r-- | lib/rubygems/stub_specification.rb | 124 |
1 files changed, 66 insertions, 58 deletions
diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb index b4019fefda..7ba0964d15 100644 --- a/lib/rubygems/stub_specification.rb +++ b/lib/rubygems/stub_specification.rb @@ -15,33 +15,65 @@ class Gem::StubSpecification < Gem::BasicSpecification end class StubLine # :nodoc: all - attr_reader :name, :version, :platform, :require_paths - - def initialize(data) - parts = data[PREFIX.length..-1].split(" ") + attr_reader :name, :version, :platform, :require_paths, :extensions, + :full_name + + NO_EXTENSIONS = [].freeze + + # These are common require paths. + REQUIRE_PATHS = { # :nodoc: + 'lib' => 'lib'.freeze, + 'test' => 'test'.freeze, + 'ext' => 'ext'.freeze, + } + + # These are common require path lists. This hash is used to optimize + # and consolidate require_path objects. Most specs just specify "lib" + # in their require paths, so lets take advantage of that by pre-allocating + # a require path list for that case. + REQUIRE_PATH_LIST = { # :nodoc: + 'lib' => ['lib'].freeze + } + + def initialize data, extensions + parts = data[PREFIX.length..-1].split(" ".freeze, 4) @name = parts[0].freeze @version = Gem::Version.new parts[1] @platform = Gem::Platform.new parts[2] - @require_paths = parts.drop(3).join(" ").split("\0") + @extensions = extensions + @full_name = if platform == Gem::Platform::RUBY + "#{name}-#{version}" + else + "#{name}-#{version}-#{platform}" + end + + path_list = parts.last + @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0".freeze).map! { |x| + REQUIRE_PATHS[x] || x + } end end - def self.default_gemspec_stub filename - new filename, true + def self.default_gemspec_stub filename, base_dir, gems_dir + new filename, base_dir, gems_dir, true end - def self.gemspec_stub filename - new filename, false + def self.gemspec_stub filename, base_dir, gems_dir + new filename, base_dir, gems_dir, false end - def initialize filename, default_gem + attr_reader :base_dir, :gems_dir + + def initialize filename, base_dir, gems_dir, default_gem + super() filename.untaint self.loaded_from = filename @data = nil - @extensions = nil @name = nil @spec = nil + @base_dir = base_dir + @gems_dir = gems_dir @default_gem = default_gem end @@ -73,8 +105,6 @@ class Gem::StubSpecification < Gem::BasicSpecification def data unless @data - @extensions = [] - begin saved_lineno = $. open loaded_from, OPEN_MODE do |file| @@ -82,10 +112,13 @@ class Gem::StubSpecification < Gem::BasicSpecification file.readline # discard encoding line stubline = file.readline.chomp if stubline.start_with?(PREFIX) then - @data = StubLine.new stubline + extensions = if /\A#{PREFIX}/ =~ file.readline.chomp + $'.split "\0" + else + StubLine::NO_EXTENSIONS + end - @extensions = $'.split "\0" if - /\A#{PREFIX}/ =~ file.readline.chomp + @data = StubLine.new stubline, extensions end rescue EOFError end @@ -100,41 +133,14 @@ class Gem::StubSpecification < Gem::BasicSpecification private :data - ## - # Extensions for this gem - - def extensions - return @extensions if @extensions - - data # load - - @extensions - end - - ## - # If a gem has a stub specification it doesn't need to bother with - # compatibility with original_name gems. It was installed with the - # normalized name. - - def find_full_gem_path # :nodoc: - path = File.expand_path File.join gems_dir, full_name - path.untaint - path - end - - ## - # Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is - # activated. - - def full_require_paths - @require_paths ||= data.require_paths - - super + def raw_require_paths # :nodoc: + data.require_paths end def missing_extensions? return false if default_gem? return false if extensions.empty? + return false if File.exist? gem_build_complete_path to_spec.missing_extensions? end @@ -154,12 +160,21 @@ class Gem::StubSpecification < Gem::BasicSpecification end ## - # Require paths of the gem + # Extensions for this gem + + def extensions + data.extensions + end + + ## + # Version of the gem - def require_paths - @require_paths ||= data.require_paths + def version + data.version + end - super + def full_name + data.full_name end ## @@ -173,7 +188,7 @@ class Gem::StubSpecification < Gem::BasicSpecification end @spec ||= Gem::Specification.load(loaded_from) - @spec.ignored = @ignored if instance_variable_defined? :@ignored + @spec.ignored = @ignored if @spec @spec end @@ -187,13 +202,6 @@ class Gem::StubSpecification < Gem::BasicSpecification end ## - # Version of the gem - - def version - @version ||= data.version - end - - ## # Is there a stub line present for this StubSpecification? def stubbed? |