mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Move bottle filename construction to a class
This commit is contained in:
parent
7d28a6c54b
commit
a87d2108ea
@ -3,14 +3,6 @@ require 'os/mac'
|
|||||||
require 'extend/ARGV'
|
require 'extend/ARGV'
|
||||||
require 'bottle_version'
|
require 'bottle_version'
|
||||||
|
|
||||||
def bottle_filename options={}
|
|
||||||
name = options.fetch(:name)
|
|
||||||
version = options.fetch(:version)
|
|
||||||
tag = options.fetch(:tag)
|
|
||||||
revision = options.fetch(:revision)
|
|
||||||
"#{name}-#{version}.#{tag}#{bottle_suffix(revision)}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def built_as_bottle? f
|
def built_as_bottle? f
|
||||||
return false unless f.installed?
|
return false unless f.installed?
|
||||||
tab = Tab.for_keg(f.installed_prefix)
|
tab = Tab.for_keg(f.installed_prefix)
|
||||||
@ -36,8 +28,9 @@ def bottle_native_regex
|
|||||||
/(\.#{bottle_tag}\.bottle\.(\d+\.)?tar\.gz)$/o
|
/(\.#{bottle_tag}\.bottle\.(\d+\.)?tar\.gz)$/o
|
||||||
end
|
end
|
||||||
|
|
||||||
def bottle_url(root_url, filename_options)
|
def bottle_url(root_url, *filename_args)
|
||||||
"#{root_url}/#{bottle_filename(filename_options)}"
|
filename = Bottle::Filename.new(*filename_args)
|
||||||
|
"#{root_url}/#{filename}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def bottle_tag
|
def bottle_tag
|
||||||
|
@ -125,12 +125,7 @@ module Homebrew
|
|||||||
bottle_revision = max ? max + 1 : 0
|
bottle_revision = max ? max + 1 : 0
|
||||||
end
|
end
|
||||||
|
|
||||||
filename = bottle_filename(
|
filename = Bottle::Filename.new(f.name, f.pkg_version, bottle_tag, bottle_revision)
|
||||||
:name => f.name,
|
|
||||||
:version => f.pkg_version,
|
|
||||||
:revision => bottle_revision,
|
|
||||||
:tag => bottle_tag
|
|
||||||
)
|
|
||||||
|
|
||||||
if bottle_filename_formula_name(filename).empty?
|
if bottle_filename_formula_name(filename).empty?
|
||||||
return ofail "Add a new regex to bottle_version.rb to parse #{f.version} from #{filename}"
|
return ofail "Add a new regex to bottle_version.rb to parse #{f.version} from #{filename}"
|
||||||
@ -197,7 +192,7 @@ module Homebrew
|
|||||||
puts output
|
puts output
|
||||||
|
|
||||||
if ARGV.include? '--rb'
|
if ARGV.include? '--rb'
|
||||||
bottle_base = filename.gsub(bottle_suffix(bottle_revision), '')
|
bottle_base = filename.to_s.gsub(bottle_suffix(bottle_revision), '')
|
||||||
File.open "#{bottle_base}.bottle.rb", 'w' do |file|
|
File.open "#{bottle_base}.bottle.rb", 'w' do |file|
|
||||||
file.write output
|
file.write output
|
||||||
end
|
end
|
||||||
|
@ -113,6 +113,22 @@ class HeadSoftwareSpec < SoftwareSpec
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Bottle
|
class Bottle
|
||||||
|
class Filename
|
||||||
|
attr_reader :name, :version, :tag, :revision
|
||||||
|
|
||||||
|
def initialize(name, version, tag, revision)
|
||||||
|
@name = name
|
||||||
|
@version = version
|
||||||
|
@tag = tag
|
||||||
|
@revision = revision
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"#{name}-#{version}.#{tag}#{bottle_suffix(revision)}"
|
||||||
|
end
|
||||||
|
alias_method :to_str, :to_s
|
||||||
|
end
|
||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
||||||
attr_reader :name, :resource, :prefix, :cellar, :revision
|
attr_reader :name, :resource, :prefix, :cellar, :revision
|
||||||
@ -127,13 +143,7 @@ class Bottle
|
|||||||
|
|
||||||
checksum, tag = spec.checksum_for(bottle_tag)
|
checksum, tag = spec.checksum_for(bottle_tag)
|
||||||
|
|
||||||
@resource.url = bottle_url(
|
@resource.url = bottle_url(spec.root_url, formula.name, formula.pkg_version, tag, spec.revision)
|
||||||
spec.root_url,
|
|
||||||
:name => formula.name,
|
|
||||||
:version => formula.pkg_version,
|
|
||||||
:revision => spec.revision,
|
|
||||||
:tag => tag
|
|
||||||
)
|
|
||||||
@resource.download_strategy = CurlBottleDownloadStrategy
|
@resource.download_strategy = CurlBottleDownloadStrategy
|
||||||
@resource.version = formula.pkg_version
|
@resource.version = formula.pkg_version
|
||||||
@resource.checksum = checksum
|
@resource.checksum = checksum
|
||||||
|
14
Library/Homebrew/test/test_bottle_filename.rb
Normal file
14
Library/Homebrew/test/test_bottle_filename.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require "testing_env"
|
||||||
|
require "software_spec"
|
||||||
|
|
||||||
|
class BottleFilenameTests < Homebrew::TestCase
|
||||||
|
def fn(revision)
|
||||||
|
Bottle::Filename.new("foo", "1.0", :tag, revision)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_str
|
||||||
|
expected = "foo-1.0.tag.bottle.tar.gz"
|
||||||
|
assert_equal expected, fn(0).to_s
|
||||||
|
assert_equal expected, fn(0).to_str
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user