Skip to content

Commit

Permalink
Preserve original platform across Gem::Specification serialization.
Browse files Browse the repository at this point in the history
Retry with original platform-named gem on fetch error during insallation.


git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1497 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information
drbrain committed Nov 12, 2007
1 parent ebed448 commit 767b16f
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 21 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
2007-11-11 Eric Hodel <drbrain@segment7.net>

* Rakefile: Tasks for maintaining ruby trunk export of RubyGems.
* lib/rubygems/specification.rb: Preserve original platform across
serialization.
* lib/rubygems/dependency_installer.rb: Retry with original platform
name on fetch error.

2007-11-09 Eric Hodel <drbrain@segment7.net>

Expand Down
22 changes: 18 additions & 4 deletions lib/rubygems/dependency_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,26 @@ def download(spec, source_uri)
case scheme
when 'http' then
unless File.exist? local_gem_path then
say "Downloading gem #{gem_file_name}" if
Gem.configuration.really_verbose
begin
say "Downloading gem #{gem_file_name}" if
Gem.configuration.really_verbose

remote_gem_path = source_uri + "gems/#{gem_file_name}"

gem = Gem::RemoteFetcher.fetcher.fetch_path remote_gem_path
rescue Gem::RemoteFetcher::FetchError
p spec.original_platform => spec.platform
raise if spec.original_platform == spec.platform

remote_gem_path = source_uri + "gems/#{gem_file_name}"
alternate_name = "#{spec.name}-#{spec.version}-#{spec.original_platform}.gem"

gem = Gem::RemoteFetcher.fetcher.fetch_path remote_gem_path
say "Failed, downloading gem #{alternate_name}" if
Gem.configuration.really_verbose

remote_gem_path = source_uri + "gems/#{alternate_name}"

gem = Gem::RemoteFetcher.fetcher.fetch_path remote_gem_path
end

File.open local_gem_path, 'wb' do |fp|
fp.write gem
Expand Down
11 changes: 9 additions & 2 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _dump(limit) # :nodoc:
@summary,
@required_ruby_version,
@required_rubygems_version,
@new_platform,
@original_platform,
@dependencies,
@rubyforge_project,
@email,
Expand Down Expand Up @@ -377,7 +377,10 @@ def test_suite_file=(val)
end

overwrite_accessor :platform= do |platform|
@original_platform = platform if @original_platform.nil?
if @original_platform.nil? or
@original_platform == Gem::Platform::RUBY then
@original_platform = platform
end

case platform
when Gem::Platform::CURRENT then
Expand Down Expand Up @@ -754,6 +757,9 @@ def to_ruby

result << " s.name = #{ruby_code name}"
result << " s.version = #{ruby_code version}"
unless platform.nil? or platform == Gem::Platform::RUBY then
result << " s.platform = #{ruby_code original_platform}"
end
result << ""
result << " s.specification_version = #{specification_version} if s.respond_to? :specification_version="
result << ""
Expand All @@ -762,6 +768,7 @@ def to_ruby
handled = [
:dependencies,
:name,
:platform,
:required_rubygems_version,
:specification_version,
:version,
Expand Down
4 changes: 2 additions & 2 deletions test/gemutilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def fetch_path(path)
@paths << path
raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
data = @data[path]
raise OpenURI::HTTPError.new("no data for #{path}", nil) if data.nil?
raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil?
data.respond_to?(:call) ? data.call : data
end

Expand All @@ -48,7 +48,7 @@ def fetch_size(path)
@paths << path
raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
data = @data[path]
raise OpenURI::HTTPError.new("no data for #{path}", nil) if data.nil?
raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil?
data.respond_to?(:call) ? data.call : data.length
end

Expand Down
47 changes: 35 additions & 12 deletions test/test_gem_dependency_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ def test_install_dependency_existing
end

def test_install_dependency_old
@e1, @e1_gem = util_gem 'e', '1'
@f1, @f1_gem = util_gem 'f', '1' do |s| s.add_dependency 'e' end
@f2, @f2_gem = util_gem 'f', '2'
e1, e1_gem = util_gem 'e', '1'
f1, f1_gem = util_gem 'f', '1' do |s| s.add_dependency 'e' end
f2, f2_gem = util_gem 'f', '2'

FileUtils.mv @e1_gem, @tempdir
FileUtils.mv @f1_gem, @tempdir
FileUtils.mv @f2_gem, @tempdir
FileUtils.mv e1_gem, @tempdir
FileUtils.mv f1_gem, @tempdir
FileUtils.mv f2_gem, @tempdir
inst = nil

Dir.chdir @tempdir do
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_install_version_default
assert_equal %w[d-2], inst.installed_gems.map { |s| s.full_name }
end

def test_download_gem
def test_download
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
Expand All @@ -349,7 +349,7 @@ def test_download_gem
assert File.exist?(a1_cache_gem)
end

def test_download_gem_cached
def test_download_cached
FileUtils.mv @a1_gem, @cache_dir

inst = Gem::DependencyInstaller.new 'a'
Expand All @@ -358,7 +358,7 @@ def test_download_gem_cached
inst.download(@a1, 'http://gems.example.com')
end

def test_download_gem_local
def test_download_local
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, "#{@a1.full_name}.gem"
inst = nil
Expand All @@ -371,7 +371,7 @@ def test_download_gem_local
inst.download(@a1, local_path)
end

def test_download_gem_install_dir
def test_download_install_dir
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
a1_data = fp.read
Expand All @@ -390,7 +390,7 @@ def test_download_gem_install_dir
end

unless win_platform? then # File.chmod doesn't work
def test_download_gem_local_read_only
def test_download_local_read_only
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, "#{@a1.full_name}.gem"
inst = nil
Expand All @@ -407,7 +407,30 @@ def test_download_gem_local_read_only
end
end

def test_download_gem_unsupported
def test_download_platform_legacy
original_platform = 'old-platform'

e1, e1_gem = util_gem 'e', '1' do |s|
s.platform = Gem::Platform::CURRENT
s.instance_variable_set :@original_platform, original_platform
end

e1_data = nil
File.open e1_gem, 'rb' do |fp|
e1_data = fp.read
end

@fetcher.data["http://gems.example.com/gems/e-1-#{original_platform}.gem"] = e1_data

inst = Gem::DependencyInstaller.new 'a'

e1_cache_gem = File.join(@gemhome, 'cache', "#{e1.full_name}.gem")
assert_equal e1_cache_gem, inst.download(e1, 'http://gems.example.com')

assert File.exist?(e1_cache_gem)
end

def test_download_unsupported
inst = Gem::DependencyInstaller.new 'a'

e = assert_raise Gem::InstallError do
Expand Down
24 changes: 23 additions & 1 deletion test/test_gem_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ def test_initialize_future
assert_equal "1.3.5", spec.version.to_s
end

def test__dump
@a0_0_2.platform = Gem::Platform.local
@a0_0_2.instance_variable_set :@original_platform, 'old_platform'

data = Marshal.dump @a0_0_2

same_spec = Marshal.load data

assert_equal 'old_platform', same_spec.original_platform
end

def test_author
assert_equal 'A User', @a0_0_1.author
end
Expand Down Expand Up @@ -573,6 +584,7 @@ def test_to_ruby_fancy
expected = "Gem::Specification.new do |s|
s.name = %q{a}
s.version = \"0.0.1\"
s.platform = Gem::Platform.new([\"ppc\", \"darwin\", nil])
s.specification_version = 2 if s.respond_to? :specification_version=
Expand All @@ -587,7 +599,6 @@ def test_to_ruby_fancy
s.files = [\"lib/code.rb\", \"test/suite.rb\", \"bin/exec\", \"ext/a/extconf.rb\"]
s.has_rdoc = %q{true}
s.homepage = %q{http://example.com}
s.platform = Gem::Platform.new([\"ppc\", \"darwin\", nil])
s.require_paths = [\"lib\"]
s.requirements = [\"A working computer\"]
s.rubygems_version = %q{0.9.4.6}
Expand Down Expand Up @@ -615,6 +626,17 @@ def test_to_ruby_legacy
assert_equal gemspec1, gemspec2
end

def test_to_ruby_platform
@a0_0_2.platform = Gem::Platform.local
@a0_0_2.instance_variable_set :@original_platform, 'old_platform'

ruby_code = @a0_0_2.to_ruby

same_spec = eval ruby_code

assert_equal 'old_platform', same_spec.original_platform
end

def test_to_yaml
yaml_str = @a0_0_1.to_yaml
same_spec = YAML.load(yaml_str)
Expand Down

0 comments on commit 767b16f

Please sign in to comment.