mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Taps: cleanup regexps around Taps
Closes Homebrew/homebrew#29139. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
858da0063d
commit
d1f15e967b
@ -107,7 +107,7 @@ module Homebrew extend self
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tap_args
|
def tap_args
|
||||||
ARGV.first =~ %r{^([\w-]+)/(homebrew-)?([\w-]+)$}
|
ARGV.first =~ HOMEBREW_TAP_ARGS_REGEX
|
||||||
raise "Invalid tap name" unless $1 && $3
|
raise "Invalid tap name" unless $1 && $3
|
||||||
[$1, $3]
|
[$1, $3]
|
||||||
end
|
end
|
||||||
@ -122,7 +122,7 @@ module Homebrew extend self
|
|||||||
|
|
||||||
def tap_ref(path)
|
def tap_ref(path)
|
||||||
case path.to_s
|
case path.to_s
|
||||||
when %r{^#{HOMEBREW_LIBRARY}/Taps/([\w-]+)/([\w-]+)/(.+)}
|
when HOMEBREW_TAP_PATH_REGEX
|
||||||
"#$1/#$2/#{File.basename($3, '.rb')}"
|
"#$1/#$2/#{File.basename($3, '.rb')}"
|
||||||
when %r{^#{HOMEBREW_LIBRARY}/Formula/(.+)}
|
when %r{^#{HOMEBREW_LIBRARY}/Formula/(.+)}
|
||||||
"Homebrew/homebrew/#{File.basename($1, '.rb')}"
|
"Homebrew/homebrew/#{File.basename($1, '.rb')}"
|
||||||
|
@ -218,9 +218,9 @@ class Report < Hash
|
|||||||
|
|
||||||
def tapped_formula_for key
|
def tapped_formula_for key
|
||||||
fetch(key, []).select do |path|
|
fetch(key, []).select do |path|
|
||||||
case path.relative_path_from(HOMEBREW_REPOSITORY).to_s
|
case path.to_s
|
||||||
when %r{^Library/Taps/([\w-]+/[\w-]+/.*)}
|
when HOMEBREW_TAP_PATH_REGEX
|
||||||
valid_formula_location?($1)
|
valid_formula_location?("#{$1}/#{$2}/#{$3}")
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@ -247,11 +247,11 @@ class Report < Hash
|
|||||||
|
|
||||||
def select_formula key
|
def select_formula key
|
||||||
fetch(key, []).map do |path|
|
fetch(key, []).map do |path|
|
||||||
case path.relative_path_from(HOMEBREW_REPOSITORY).to_s
|
case path.to_s
|
||||||
when %r{^Library/Formula}
|
when Regexp.new(HOMEBREW_LIBRARY + "/Formula")
|
||||||
path.basename(".rb").to_s
|
path.basename(".rb").to_s
|
||||||
when %r{^Library/Taps/([\w-]+)/(homebrew-)?([\w-]+)/(.*)\.rb}
|
when HOMEBREW_TAP_PATH_REGEX
|
||||||
"#$1/#$3/#{path.basename(".rb")}"
|
"#$1/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}"
|
||||||
end
|
end
|
||||||
end.compact.sort
|
end.compact.sort
|
||||||
end
|
end
|
||||||
|
@ -85,10 +85,7 @@ HOMEBREW_USER_AGENT = "Homebrew #{HOMEBREW_VERSION} (Ruby #{RUBY_VERSION}-#{RUBY
|
|||||||
|
|
||||||
HOMEBREW_CURL_ARGS = '-f#LA'
|
HOMEBREW_CURL_ARGS = '-f#LA'
|
||||||
|
|
||||||
HOMEBREW_TAP_FORMULA_REGEX = %r{^([\w-]+)/([\w-]+)/([\w-]+)$}
|
require 'tap_constants'
|
||||||
HOMEBREW_TAP_DIR_REGEX = %r{#{HOMEBREW_LIBRARY}/Taps/([\w-]+)/([\w-]+)}
|
|
||||||
HOMEBREW_TAP_PATH_REGEX = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source \
|
|
||||||
+ %r{/(.*)}.source)
|
|
||||||
|
|
||||||
module Homebrew extend self
|
module Homebrew extend self
|
||||||
include FileUtils
|
include FileUtils
|
||||||
|
8
Library/Homebrew/tap_constants.rb
Normal file
8
Library/Homebrew/tap_constants.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# match expressions when taps are given as ARGS, e.g. someuser/sometap
|
||||||
|
HOMEBREW_TAP_ARGS_REGEX = %r{^([\w-]+)/(homebrew-)?([\w-]+)$}
|
||||||
|
# match taps' formula, e.g. someuser/sometap/someformula
|
||||||
|
HOMEBREW_TAP_FORMULA_REGEX = %r{^([\w-]+)/([\w-]+)/([\w-]+)$}
|
||||||
|
# match taps' directory path, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap
|
||||||
|
HOMEBREW_TAP_DIR_REGEX = %r{#{HOMEBREW_LIBRARY}/Taps/([\w-]+)/([\w-]+)}
|
||||||
|
# match taps' formula path, e.g. HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula
|
||||||
|
HOMEBREW_TAP_PATH_REGEX = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{/(.*)}.source)
|
@ -27,7 +27,7 @@ HOMEBREW_WWW = 'http://example.com'
|
|||||||
HOMEBREW_CURL_ARGS = '-fsLA'
|
HOMEBREW_CURL_ARGS = '-fsLA'
|
||||||
HOMEBREW_VERSION = '0.9-test'
|
HOMEBREW_VERSION = '0.9-test'
|
||||||
|
|
||||||
HOMEBREW_TAP_FORMULA_REGEX = %r{^([\w-]+)/([\w-]+)/([\w-]+)$}
|
require 'tap_constants'
|
||||||
|
|
||||||
RUBY_BIN = Pathname.new(RbConfig::CONFIG['bindir'])
|
RUBY_BIN = Pathname.new(RbConfig::CONFIG['bindir'])
|
||||||
RUBY_PATH = RUBY_BIN + RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']
|
RUBY_PATH = RUBY_BIN + RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user