Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support "gem contents" for default gem

  • Loading branch information...
commit 6834877950beb5c631ba49a286585a0fe8867ea0 1 parent abd9937
@kou authored
View
40 lib/rubygems/commands/contents_command.rb
@@ -1,3 +1,4 @@
+require 'English'
require 'rubygems/command'
require 'rubygems/version_option'
@@ -80,19 +81,36 @@ def execute
terminate_interaction 1 if gem_names.length == 1
end
- gem_path = spec.full_gem_path
- extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
- glob = "#{gem_path}#{extra}/**/*"
- files = Dir[glob]
-
- gem_path = File.join gem_path, '' # add trailing / if missing
-
- files.sort.each do |file|
- next if File.directory? file
+ if spec.default_gem?
+ files = spec.files.map do |file|
+ case file
+ when /\A#{spec.bindir}\//
+ [Gem::ConfigMap[:bindir], $POSTMATCH]
+ when /\.so\z/
+ [Gem::ConfigMap[:archdir], file]
+ else
+ [Gem::ConfigMap[:rubylibdir], file]
+ end
+ end
+ else
+ gem_path = spec.full_gem_path
+ extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
+ glob = "#{gem_path}#{extra}/**/*"
+ prefix_re = /#{Regexp.escape(gem_path)}\//
+ files = Dir[glob].map do |file|
+ [gem_path, file.sub(prefix_re, "")]
+ end
+ end
- file = file.sub gem_path, '' unless options[:prefix]
+ files.sort.each do |prefix, basename|
+ absolute_path = File.join(prefix, basename)
+ next if File.directory? absolute_path
- say file
+ if options[:prefix]
+ say absolute_path
+ else
+ say basename
+ end
end
end
end
View
1  lib/rubygems/compatibility.rb
@@ -32,6 +32,7 @@ module Gem
RbConfigPriorities = %w[
EXEEXT RUBY_SO_NAME arch bindir datadir libdir ruby_install_name
ruby_version rubylibprefix sitedir sitelibdir vendordir vendorlibdir
+ rubylibdir
]
unless defined?(ConfigMap)
View
23 test/rubygems/test_gem_commands_contents_command.rb
@@ -127,6 +127,29 @@ def test_execute_no_prefix
assert_equal "", @ui.error
end
+ def test_execute_default_gem
+ default_gem_spec = new_default_spec("default", "2.0.0.0",
+ nil, "default/gem.rb")
+ default_gem_spec.executables = ["default_command"]
+ default_gem_spec.files += ["default_gem.so"]
+ install_default_specs(default_gem_spec)
+
+ @cmd.options[:args] = %w[default]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+#{Gem::ConfigMap[:bindir]}/default_command
+#{Gem::ConfigMap[:rubylibdir]}/default/gem.rb
+#{Gem::ConfigMap[:archdir]}/default_gem.so
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal "", @ui.error
+ end
+
def test_handle_options
refute @cmd.options[:lib_only]
assert @cmd.options[:prefix]
Please sign in to comment.
Something went wrong with that request. Please try again.