Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for ENV GEM_SPEC #489

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rubygems.rb
Expand Up @@ -374,6 +374,10 @@ def self.path
paths.path
end

def self.spec_cache_dir
paths.spec_cache_dir
end

##
# Quietly ensure the Gem directory +dir+ contains all the proper
# subdirectories. If we can't create a directory due to a permission
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/commands/environment_command.rb
Expand Up @@ -99,6 +99,8 @@ def execute

out << " - EXECUTABLE DIRECTORY: #{Gem.bindir}\n"

out << " - SPEC CACHE DIRECTORY: #{Gem.spec_cache_dir}\n"

out << " - RUBYGEMS PLATFORMS:\n"
Gem.platforms.each do |platform|
out << " - #{platform}\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/commands/sources_command.rb
Expand Up @@ -48,7 +48,7 @@ def execute
options[:update])

if options[:clear_all] then
path = File.join Gem.user_home, '.gem', 'specs'
path = Gem.spec_cache_dir
FileUtils.rm_rf path

unless File.exist? path then
Expand Down
8 changes: 8 additions & 0 deletions lib/rubygems/defaults.rb
Expand Up @@ -14,6 +14,14 @@ def self.default_sources
%w[https://rubygems.org/]
end

##
# Default spec directory path to be used if an alternate value is not
# specified in the environment

def self.default_spec_cache_dir
File.join Gem.user_home, '.gem', 'specs'
end

##
# Default home directory path to be used if an alternate value is not
# specified in the environment
Expand Down
6 changes: 6 additions & 0 deletions lib/rubygems/path_support.rb
Expand Up @@ -12,6 +12,10 @@ class Gem::PathSupport
# Array of paths to search for Gems.
attr_reader :path

##
# Directory with spec cache
attr_reader :spec_cache_dir # :nodoc:

##
#
# Constructor. Takes a single argument which is to be treated like a
Expand All @@ -28,6 +32,8 @@ def initialize(env=ENV)
end

self.path = env["GEM_PATH"] || ENV["GEM_PATH"]

@spec_cache_dir = env["GEM_SPEC"] || ENV["GEM_SPEC"] || Gem.default_spec_cache_dir
end

private
Expand Down
3 changes: 1 addition & 2 deletions lib/rubygems/source.rb
Expand Up @@ -58,8 +58,7 @@ def hash
def cache_dir(uri)
# Correct for windows paths
escaped_path = uri.path.sub(/^\/([a-z]):\//i, '/\\1-/')
root = File.join Gem.user_home, '.gem', 'specs'
File.join root, "#{uri.host}%#{uri.port}", File.dirname(escaped_path)
File.join Gem.spec_cache_dir, "#{uri.host}%#{uri.port}", File.dirname(escaped_path)
end

def update_cache?
Expand Down
1 change: 0 additions & 1 deletion lib/rubygems/spec_fetcher.rb
Expand Up @@ -38,7 +38,6 @@ def self.fetcher=(fetcher) # :nodoc:
end

def initialize
@dir = File.join Gem.user_home, '.gem', 'specs'
@update_cache = File.stat(Gem.user_home).uid == Process.uid

@specs = {}
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/test_case.rb
Expand Up @@ -142,6 +142,7 @@ def setup

@gemhome = File.join @tempdir, 'gemhome'
@userhome = File.join @tempdir, 'userhome'
ENV["GEM_SPEC"] = File.join @tempdir, 'spec_cache'

@orig_ruby = if ENV['RUBY'] then
ruby = Gem.instance_variable_get :@ruby
Expand Down
3 changes: 1 addition & 2 deletions test/rubygems/test_gem_commands_install_command.rb
Expand Up @@ -167,8 +167,7 @@ def test_execute_bad_source

# This is needed because we need to exercise the cache path
# within SpecFetcher
path = File.join Gem.user_home, '.gem', 'specs', "not-there.nothing%80",
"latest_specs.4.8"
path = File.join Gem.spec_cache_dir, "not-there.nothing%80", "latest_specs.4.8"

FileUtils.mkdir_p File.dirname(path)

Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_commands_sources_command.rb
Expand Up @@ -194,7 +194,7 @@ def test_execute_clear_all
assert_equal expected, @ui.output
assert_equal '', @ui.error

dir = File.join Gem.user_home, '.gem', 'specs'
dir = Gem.spec_cache_dir
refute File.exist?(dir), 'cache dir removed'
end

Expand Down
14 changes: 14 additions & 0 deletions test/rubygems/test_gem_path_support.rb
Expand Up @@ -64,4 +64,18 @@ def test_initialize_home_path
def util_path
ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
end

def test_initialize_spec
ENV["GEM_SPEC"] = nil
ps = Gem::PathSupport.new
assert_equal Gem.default_spec_cache_dir, ps.spec_cache_dir

ENV["GEM_SPEC"] = 'bar'
ps = Gem::PathSupport.new
assert_equal ENV["GEM_SPEC"], ps.spec_cache_dir
ENV["GEM_SPEC"] = File.join @tempdir, 'spec_cache'

ps = Gem::PathSupport.new "GEM_SPEC" => "foo"
assert_equal "foo", ps.spec_cache_dir
end
end
8 changes: 4 additions & 4 deletions test/rubygems/test_gem_source.rb
Expand Up @@ -63,7 +63,7 @@ def test_api_uri_resolved_from_remote_fetcher

def test_cache_dir_escapes_windows_paths
uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo")
root = File.join Gem.user_home, '.gem', 'specs'
root = Gem.spec_cache_dir
cache_dir = @source.cache_dir(uri).gsub(root, '')
assert cache_dir !~ /:/, "#{cache_dir} should not contain a :"
end
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_load_specs
expected = @released
assert_equal expected, @source.load_specs(:released)

cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
cache_dir = File.join Gem.spec_cache_dir, 'gems.example.com%80'
assert File.exist?(cache_dir), "#{cache_dir} does not exist"

cache_file = File.join cache_dir, "specs.#{Gem.marshal_version}"
Expand All @@ -138,7 +138,7 @@ def test_load_specs_cached
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
' ' * Marshal.dump(@latest_specs).length

cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
cache_dir = File.join Gem.spec_cache_dir, 'gems.example.com%80'

FileUtils.mkdir_p cache_dir

Expand All @@ -160,7 +160,7 @@ def test_load_specs_cached_empty
@fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
util_gzip(Marshal.dump(@latest_specs))

cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
cache_dir = File.join Gem.spec_cache_dir, 'gems.example.com%80'

FileUtils.mkdir_p cache_dir

Expand Down