stage: fix block signature back-compatibility under Ruby 1.8.7
The new stage() signature introduced by #66 breaks back-compatibility under Ruby 1.8.7. This fixes it by switching back to a one-argument block signature and using a new class to wrap both the Resource and Mktemp info for the staging context, in a signature-back-compatible way. Addresses homebrew/homebrew-core#529. Closes #135. Signed-off-by: Andrew Janke <andrew@apjanke.net>
This commit is contained in:
parent
2921795668
commit
258a764f67
@ -179,7 +179,7 @@ end
|
||||
unless File.respond_to?(:write)
|
||||
class File
|
||||
def self.write(filename, contents)
|
||||
File.open(filename, 'w') do |file|
|
||||
File.open(filename, "w") do |file|
|
||||
file.write contents
|
||||
end
|
||||
end
|
||||
|
||||
@ -1548,7 +1548,7 @@ class Formula
|
||||
end
|
||||
|
||||
def stage
|
||||
active_spec.stage do |_resource, staging|
|
||||
active_spec.stage do |staging|
|
||||
@source_modified_time = active_spec.source_modified_time
|
||||
@buildpath = Pathname.pwd
|
||||
env_home = buildpath/".brew_home"
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
require "download_strategy"
|
||||
require "checksum"
|
||||
require "version"
|
||||
require "forwardable"
|
||||
|
||||
# Resource is the fundamental representation of an external resource. The
|
||||
# primary formula download, along with other declared resources, are instances
|
||||
@ -86,15 +87,15 @@ class Resource
|
||||
end
|
||||
|
||||
# If a target is given, unpack there; else unpack to a temp folder.
|
||||
# If block is given, yield to that block with |self, staging|, where staging
|
||||
# is a staging context that responds to retain!().
|
||||
# If block is given, yield to that block with |stage|, where stage
|
||||
# is a ResourceStagingContext.
|
||||
# A target or a block must be given, but not both.
|
||||
def unpack(target = nil)
|
||||
mktemp(download_name) do |staging|
|
||||
downloader.stage
|
||||
@source_modified_time = downloader.source_modified_time
|
||||
if block_given?
|
||||
yield self, staging
|
||||
yield ResourceStageContext.new(self, staging)
|
||||
elsif target
|
||||
target = Pathname.new(target) unless target.is_a? Pathname
|
||||
target.install Dir["*"]
|
||||
@ -186,3 +187,27 @@ class Resource
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The context in which a Resource.stage() occurs. Supports access to both
|
||||
# the Resource and associated Mktemp in a single block argument. The interface
|
||||
# is back-compatible with Resource itself as used in that context.
|
||||
class ResourceStageContext
|
||||
extend Forwardable
|
||||
|
||||
# The Resource that is being staged
|
||||
attr_reader :resource
|
||||
# The Mktemp in which @resource is staged
|
||||
attr_reader :staging
|
||||
|
||||
def_delegators :@resource, :version, :url, :mirrors, :specs, :using, :source_modified_time
|
||||
def_delegators :@staging, :retain!
|
||||
|
||||
def initialize(resource, staging)
|
||||
@resource = resource
|
||||
@staging = staging
|
||||
end
|
||||
|
||||
def to_s
|
||||
"<#{self.class}: resource=#{resource} staging=#{staging}>"
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user