Skip to content
This repository has been archived by the owner on Sep 7, 2019. It is now read-only.

Commit

Permalink
- Fixed gem contents to work with the lightweight specifications
Browse files Browse the repository at this point in the history
- Fixed lightweight specifications so `gem rdoc` will generate proper documentation
  • Loading branch information
drbrain committed Mar 10, 2011
1 parent 2026fbb commit 831f1ca
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 51 deletions.
29 changes: 19 additions & 10 deletions lib/rubygems/commands/contents_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def execute
end

gem_names.each do |name|
gem_spec = si.find_name(name, version).last
spec = si.find_name(name, version).last

unless gem_spec then
unless spec then
say "Unable to find gem '#{name}' in #{path_kind}"

if Gem.configuration.verbose then
Expand All @@ -80,16 +80,25 @@ def execute
terminate_interaction 1 if gem_names.length == 1
end

files = options[:lib_only] ? gem_spec.lib_files : gem_spec.files
gem_path = spec.full_gem_path

files.each do |f|
path = if options[:prefix] then
File.join gem_spec.full_gem_path, f
else
f
end
files = if options[:lib_only] then
glob = File.join(gem_path, "{#{spec.require_paths.join ','}}",
'**/*')

say path
Dir[glob]
else
Dir[File.join(gem_path, '**/*')]
end

gem_path = File.join gem_path, '' # to strip trailing /

files.each do |file|
next if File.directory? file

file = file.sub gem_path, '' unless options[:prefix]

say file
end
end
end
Expand Down
19 changes: 13 additions & 6 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,18 @@ def encode_with coder # :nodoc:
end
end

##
# Creates a duplicate spec without large blobs that aren't used at runtime.

def for_cache
spec = dup

spec.files = nil
spec.test_files = nil

spec
end

def to_yaml(opts = {}) # :nodoc:
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? then
super.gsub(/ !!null \n/, " \n")
Expand Down Expand Up @@ -829,12 +841,7 @@ def to_ruby
end

def to_ruby_for_cache
s = dup
# remove large blobs that aren't used at runtime:
s.files = nil
s.extra_rdoc_files = nil
s.rdoc_options = nil
s.to_ruby
for_cache.to_ruby
end

##
Expand Down
8 changes: 5 additions & 3 deletions lib/rubygems/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,16 @@ def quick_gem(name, version='2')
yield(s) if block_given?
end

installed_spec = spec.for_cache

path = File.join "specifications", spec.spec_name
written_path = write_file path do |io|
io.write(spec.to_ruby)
io.write installed_spec.to_ruby_for_cache
end

spec.loaded_from = written_path
spec.loaded_from = installed_spec.loaded_from = written_path

Gem.source_index.add_spec spec
Gem.source_index.add_spec installed_spec

return spec
end
Expand Down
47 changes: 18 additions & 29 deletions test/rubygems/test_gem_commands_contents_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ def setup
@cmd = Gem::Commands::ContentsCommand.new
end

def gem name
spec = quick_gem name do |gem|
gem.files = %W[lib/#{name}.rb Rakefile]
end
write_file File.join(*%W[gems #{spec.full_name} lib #{name}.rb])
write_file File.join(*%W[gems #{spec.full_name} Rakefile])
end

def test_execute
@cmd.options[:args] = %w[foo]
quick_gem 'foo' do |gem|
gem.files = %w[lib/foo.rb Rakefile]
end

gem 'foo'

use_ui @ui do
@cmd.execute
Expand All @@ -27,13 +34,8 @@ def test_execute
def test_execute_all
@cmd.options[:all] = true

quick_gem 'foo' do |gem|
gem.files = %w[lib/foo.rb Rakefile]
end

quick_gem 'bar' do |gem|
gem.files = %w[lib/bar.rb Rakefile]
end
gem 'foo'
gem 'bar'

use_ui @ui do
@cmd.execute
Expand Down Expand Up @@ -61,13 +63,8 @@ def test_execute_bad_gem

def test_execute_exact_match
@cmd.options[:args] = %w[foo]
quick_gem 'foo' do |gem|
gem.files = %w[lib/foo.rb Rakefile]
end

quick_gem 'foo_bar' do |gem|
gem.files = %w[lib/foo_bar.rb Rakefile]
end
gem 'foo'
gem 'bar'

use_ui @ui do
@cmd.execute
Expand All @@ -82,9 +79,7 @@ def test_execute_lib_only
@cmd.options[:args] = %w[foo]
@cmd.options[:lib_only] = true

quick_gem 'foo' do |gem|
gem.files = %w[lib/foo.rb Rakefile]
end
gem 'foo'

use_ui @ui do
@cmd.execute
Expand All @@ -98,13 +93,9 @@ def test_execute_lib_only

def test_execute_multiple
@cmd.options[:args] = %w[foo bar]
quick_gem 'foo' do |gem|
gem.files = %w[lib/foo.rb Rakefile]
end

quick_gem 'bar' do |gem|
gem.files = %w[lib/bar.rb Rakefile]
end
gem 'foo'
gem 'bar'

use_ui @ui do
@cmd.execute
Expand All @@ -120,9 +111,7 @@ def test_execute_no_prefix
@cmd.options[:args] = %w[foo]
@cmd.options[:prefix] = false

quick_gem 'foo' do |gem|
gem.files = %w[lib/foo.rb Rakefile]
end
gem 'foo'

use_ui @ui do
@cmd.execute
Expand Down
26 changes: 23 additions & 3 deletions test/rubygems/test_gem_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ def test_self__load_future
end

def test_self_load
spec = File.join @gemhome, 'specifications', @a2.spec_name
gs = Gem::Specification.load spec
spec_path = File.join @gemhome, 'specifications', @a2.spec_name
spec = Gem::Specification.load spec_path

assert_equal @a2, gs
@a2.files.clear

assert_equal @a2, spec
end

def test_self_load_legacy_ruby
Expand Down Expand Up @@ -536,6 +538,24 @@ def test_files_non_array_pathological
assert_kind_of Integer, @a1.hash
end

def test_for_cache
@a2.add_runtime_dependency 'b', '1'
@a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
@a2.test_files = %w[test/test_b.rb]

refute_empty @a2.files
refute_empty @a2.test_files

spec = @a2.for_cache

assert_empty spec.files
assert_empty spec.test_files

refute_empty @a2.files
refute_empty @a2.test_files
end

def test_full_gem_path
assert_equal File.join(@gemhome, 'gems', @a1.full_name),
@a1.full_gem_path
Expand Down

0 comments on commit 831f1ca

Please sign in to comment.