Merge pull request #2965 from reitermarkus/cask-tap
Detect `Tap` in `CaskLoader`.
This commit is contained in:
commit
c26c9204fa
@ -7,9 +7,16 @@ module Hbc
|
|||||||
include Metadata
|
include Metadata
|
||||||
|
|
||||||
attr_reader :token, :sourcefile_path
|
attr_reader :token, :sourcefile_path
|
||||||
def initialize(token, sourcefile_path: nil, &block)
|
|
||||||
|
def tap
|
||||||
|
return super if block_given? # Object#tap
|
||||||
|
@tap
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(token, sourcefile_path: nil, tap: nil, &block)
|
||||||
@token = token
|
@token = token
|
||||||
@sourcefile_path = sourcefile_path
|
@sourcefile_path = sourcefile_path
|
||||||
|
@tap = tap
|
||||||
@dsl = DSL.new(@token)
|
@dsl = DSL.new(@token)
|
||||||
return unless block_given?
|
return unless block_given?
|
||||||
@dsl.instance_eval(&block)
|
@dsl.instance_eval(&block)
|
||||||
|
|||||||
@ -13,8 +13,8 @@ module Hbc
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def cask(header_token, &block)
|
def cask(header_token, **options, &block)
|
||||||
Cask.new(header_token, &block)
|
Cask.new(header_token, **options, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -45,12 +45,12 @@ module Hbc
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def cask(header_token, &block)
|
def cask(header_token, **options, &block)
|
||||||
if token != header_token
|
if token != header_token
|
||||||
raise CaskTokenMismatchError.new(token, header_token)
|
raise CaskTokenMismatchError.new(token, header_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
Cask.new(header_token, sourcefile_path: path, &block)
|
super(header_token, **options, sourcefile_path: path, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -80,18 +80,33 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class FromTapLoader < FromPathLoader
|
class FromTapPathLoader < FromPathLoader
|
||||||
def self.can_load?(ref)
|
def self.can_load?(ref)
|
||||||
ref.to_s.match?(HOMEBREW_TAP_CASK_REGEX)
|
ref.to_s.match?(HOMEBREW_TAP_PATH_REGEX) && super
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :tap
|
attr_reader :tap
|
||||||
|
|
||||||
|
def initialize(tap_path)
|
||||||
|
@tap = Tap.from_path(tap_path)
|
||||||
|
super tap_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def cask(*args, &block)
|
||||||
|
super(*args, tap: tap, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class FromTapLoader < FromTapPathLoader
|
||||||
|
def self.can_load?(ref)
|
||||||
|
ref.to_s.match?(HOMEBREW_TAP_CASK_REGEX)
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(tapped_name)
|
def initialize(tapped_name)
|
||||||
user, repo, token = tapped_name.split("/", 3)
|
user, repo, token = tapped_name.split("/", 3)
|
||||||
@tap = Tap.fetch(user, repo)
|
super Tap.fetch(user, repo).cask_dir/"#{token}.rb"
|
||||||
|
|
||||||
super @tap.cask_dir/"#{token}.rb"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def load
|
def load
|
||||||
@ -136,19 +151,26 @@ module Hbc
|
|||||||
[
|
[
|
||||||
FromURILoader,
|
FromURILoader,
|
||||||
FromTapLoader,
|
FromTapLoader,
|
||||||
|
FromTapPathLoader,
|
||||||
FromPathLoader,
|
FromPathLoader,
|
||||||
].each do |loader_class|
|
].each do |loader_class|
|
||||||
return loader_class.new(ref) if loader_class.can_load?(ref)
|
return loader_class.new(ref) if loader_class.can_load?(ref)
|
||||||
end
|
end
|
||||||
|
|
||||||
if FromPathLoader.can_load?(default_path(ref))
|
if FromTapPathLoader.can_load?(default_path(ref))
|
||||||
return FromPathLoader.new(default_path(ref))
|
return FromTapPathLoader.new(default_path(ref))
|
||||||
end
|
end
|
||||||
|
|
||||||
possible_tap_casks = tap_paths(ref)
|
case (possible_tap_casks = tap_paths(ref)).count
|
||||||
if possible_tap_casks.count == 1
|
when 1
|
||||||
possible_tap_cask = possible_tap_casks.first
|
return FromTapPathLoader.new(possible_tap_casks.first)
|
||||||
return FromPathLoader.new(possible_tap_cask)
|
when 2..Float::INFINITY
|
||||||
|
loaders = possible_tap_casks.map(&FromTapPathLoader.method(:new))
|
||||||
|
|
||||||
|
raise CaskError, <<-EOS.undent
|
||||||
|
Cask #{ref} exists in multiple taps:
|
||||||
|
#{loaders.map { |loader| " #{loader.tap}/#{loader.token}" }.join("\n")}
|
||||||
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
possible_installed_cask = Cask.new(ref)
|
possible_installed_cask = Cask.new(ref)
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
module CaskLoaderCompatibilityLayer
|
module CaskLoaderCompatibilityLayer
|
||||||
private
|
private
|
||||||
|
|
||||||
def cask(header_token, &block)
|
def cask(header_token, **options, &block)
|
||||||
if header_token.is_a?(Hash) && header_token.key?(:v1)
|
if header_token.is_a?(Hash) && header_token.key?(:v1)
|
||||||
odeprecated %q("cask :v1 => 'token'"), %q("cask 'token'")
|
odeprecated %q("cask :v1 => 'token'"), %q("cask 'token'")
|
||||||
header_token = header_token[:v1]
|
header_token = header_token[:v1]
|
||||||
end
|
end
|
||||||
|
|
||||||
super(header_token, &block)
|
super(header_token, **options, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -181,8 +181,8 @@ class TapFormulaAmbiguityError < RuntimeError
|
|||||||
@name = name
|
@name = name
|
||||||
@paths = paths
|
@paths = paths
|
||||||
@formulae = paths.map do |path|
|
@formulae = paths.map do |path|
|
||||||
path.to_s =~ HOMEBREW_TAP_PATH_REGEX
|
match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX)
|
||||||
"#{Tap.fetch(Regexp.last_match(1), Regexp.last_match(2))}/#{path.basename(".rb")}"
|
"#{Tap.fetch(match[:user], match[:repo])}/#{path.basename(".rb")}"
|
||||||
end
|
end
|
||||||
|
|
||||||
super <<-EOS.undent
|
super <<-EOS.undent
|
||||||
|
|||||||
@ -177,8 +177,8 @@ class Formula
|
|||||||
|
|
||||||
@tap = if path == Formulary.core_path(name)
|
@tap = if path == Formulary.core_path(name)
|
||||||
CoreTap.instance
|
CoreTap.instance
|
||||||
elsif path.to_s =~ HOMEBREW_TAP_PATH_REGEX
|
elsif match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX)
|
||||||
Tap.fetch(Regexp.last_match(1), Regexp.last_match(2))
|
Tap.fetch(match[:user], match[:repo])
|
||||||
end
|
end
|
||||||
|
|
||||||
@full_name = full_name_with_optional_tap(name)
|
@full_name = full_name_with_optional_tap(name)
|
||||||
|
|||||||
@ -42,9 +42,9 @@ class Tap
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.from_path(path)
|
def self.from_path(path)
|
||||||
path.to_s =~ HOMEBREW_TAP_PATH_REGEX
|
match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX)
|
||||||
raise "Invalid tap path '#{path}'" unless Regexp.last_match(1)
|
raise "Invalid tap path '#{path}'" unless match
|
||||||
fetch(Regexp.last_match(1), Regexp.last_match(2))
|
fetch(match[:user], match[:repo])
|
||||||
rescue
|
rescue
|
||||||
# No need to error as a nil tap is sufficient to show failure.
|
# No need to error as a nil tap is sufficient to show failure.
|
||||||
nil
|
nil
|
||||||
|
|||||||
@ -3,7 +3,7 @@ HOMEBREW_TAP_FORMULA_REGEX = %r{^([\w-]+)/([\w-]+)/([\w+-.@]+)$}
|
|||||||
# match taps' casks, e.g. someuser/sometap/somecask
|
# match taps' casks, e.g. someuser/sometap/somecask
|
||||||
HOMEBREW_TAP_CASK_REGEX = %r{^([\w-]+)/([\w-]+)/([a-z0-9\-]+)$}
|
HOMEBREW_TAP_CASK_REGEX = %r{^([\w-]+)/([\w-]+)/([a-z0-9\-]+)$}
|
||||||
# match taps' directory paths, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap
|
# match taps' directory paths, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap
|
||||||
HOMEBREW_TAP_DIR_REGEX = %r{#{Regexp.escape(HOMEBREW_LIBRARY)}/Taps/([\w-]+)/([\w-]+)}
|
HOMEBREW_TAP_DIR_REGEX = %r{#{Regexp.escape(HOMEBREW_LIBRARY)}/Taps/(?<user>[\w-]+)/(?<repo>[\w-]+)}
|
||||||
# match taps' formula paths, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula
|
# match taps' formula paths, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula
|
||||||
HOMEBREW_TAP_PATH_REGEX = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{/(.*)}.source)
|
HOMEBREW_TAP_PATH_REGEX = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{/(.*)}.source)
|
||||||
# match the default and the versions brew-cask tap e.g. Caskroom/cask or Caskroom/versions
|
# match the default and the versions brew-cask tap e.g. Caskroom/cask or Caskroom/versions
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user