Merge pull request #7051 from EricFromCanada/bump-formula-mirrors

bump-formula-pr: improve mirror handling
This commit is contained in:
Mike McQuaid 2020-02-25 16:17:12 +00:00 committed by GitHub
commit 2e1a9f8bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 17 deletions

View File

@ -40,8 +40,9 @@ module Homebrew
description: "Print the pull request URL instead of opening in a browser." description: "Print the pull request URL instead of opening in a browser."
switch "--no-fork", switch "--no-fork",
description: "Don't try to fork the repository." description: "Don't try to fork the repository."
flag "--mirror=", comma_array "--mirror=",
description: "Use the specified <URL> as a mirror URL." description: "Use the specified <URL> as a mirror URL. If <URL> is a comma-separated list "\
"of URLs, multiple mirrors will be added."
flag "--version=", flag "--version=",
description: "Use the specified <version> to override the value parsed from the URL or tag. Note "\ description: "Use the specified <version> to override the value parsed from the URL or tag. Note "\
"that `--version=0` can be used to delete an existing version override from a "\ "that `--version=0` can be used to delete an existing version override from a "\
@ -146,7 +147,7 @@ module Homebrew
if guesses.count == 1 if guesses.count == 1
formula = guesses.shift formula = guesses.shift
elsif guesses.count > 1 elsif guesses.count > 1
odie "Couldn't guess formula for sure; could be one of these:\n#{guesses}" odie "Couldn't guess formula for sure; could be one of these:\n#{guesses.map(&:name).join(", ")}"
end end
end end
raise FormulaUnspecifiedError unless formula raise FormulaUnspecifiedError unless formula
@ -168,7 +169,18 @@ module Homebrew
new_hash = args[hash_type] if hash_type new_hash = args[hash_type] if hash_type
new_tag = args.tag new_tag = args.tag
new_revision = args.revision new_revision = args.revision
new_mirror = args.mirror new_mirrors ||= args.mirror
new_mirror ||= case new_url
when requested_spec != :devel && %r{.*ftp.gnu.org/gnu.*}
new_url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org"
when %r{.*download.savannah.gnu.org/*}
new_url.sub "download.savannah.gnu.org", "download-mirror.savannah.gnu.org"
when %r{.*www.apache.org/dyn/closer.lua\?path=.*}
new_url.sub "www.apache.org/dyn/closer.lua?path=", "archive.apache.org/dist/"
when %r{.*mirrors.ocf.berkeley.edu/debian.*}
new_url.sub "mirrors.ocf.berkeley.edu/debian", "mirrorservice.org/sites/ftp.debian.org/debian"
end
new_mirrors ||= [new_mirror] unless new_mirror.nil?
forced_version = args.version forced_version = args.version
new_url_hash = if new_url && new_hash new_url_hash = if new_url && new_hash
true true
@ -179,12 +191,6 @@ module Homebrew
elsif !new_url elsif !new_url
odie "#{formula}: no --url= argument specified!" odie "#{formula}: no --url= argument specified!"
else else
new_mirror ||= case new_url
when requested_spec != :devel && %r{.*ftp.gnu.org/gnu.*}
new_url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org"
when %r{.*mirrors.ocf.berkeley.edu/debian.*}
new_url.sub "mirrors.ocf.berkeley.edu/debian", "mirrorservice.org/sites/ftp.debian.org/debian"
end
resource = Resource.new { @url = new_url } resource = Resource.new { @url = new_url }
resource.download_strategy = DownloadStrategyDetector.detect_from_url(new_url) resource.download_strategy = DownloadStrategyDetector.detect_from_url(new_url)
resource.owner = Resource.new(formula.name) resource.owner = Resource.new(formula.name)
@ -249,10 +255,10 @@ module Homebrew
backup_file = File.read(formula.path) unless args.dry_run? backup_file = File.read(formula.path) unless args.dry_run?
if new_mirror if new_mirrors
replacement_pairs << [ replacement_pairs << [
/^( +)(url \"#{Regexp.escape(new_url)}\"\n)/m, /^( +)(url \"#{Regexp.escape(new_url)}\"\n)/m,
"\\1\\2\\1mirror \"#{new_mirror}\"\n", "\\1\\2\\1mirror \"#{new_mirrors.join("\"\n\\1mirror \"")}\"\n",
] ]
end end
@ -274,9 +280,9 @@ module Homebrew
old_formula_version.to_s, old_formula_version.to_s,
forced_version, forced_version,
] ]
elsif new_mirror elsif new_mirrors
replacement_pairs << [ replacement_pairs << [
/^( +)(mirror \"#{new_mirror}\"\n)/m, /^( +)(mirror \"#{new_mirrors.last}\"\n)/m,
"\\1\\2\\1version \"#{forced_version}\"\n", "\\1\\2\\1version \"#{forced_version}\"\n",
] ]
else else
@ -308,6 +314,17 @@ module Homebrew
new_formula_version = formula_version(formula, requested_spec, new_contents) new_formula_version = formula_version(formula, requested_spec, new_contents)
if !new_mirrors && !formula_spec.mirrors.empty?
if Homebrew.args.force?
opoo "#{formula}: Removing all mirrors because a --mirror= argument was not specified."
else
odie <<~EOS
#{formula}: a --mirror= argument for updating the mirror URL was not specified.
Use --force to remove all mirrors.
EOS
end
end
if new_formula_version < old_formula_version if new_formula_version < old_formula_version
formula.path.atomic_write(backup_file) unless args.dry_run? formula.path.atomic_write(backup_file) unless args.dry_run?
odie <<~EOS odie <<~EOS

View File

@ -41,6 +41,11 @@ module RuboCop
problem "Please don't use fossies.org in the url (using as a mirror is fine)" problem "Please don't use fossies.org in the url (using as a mirror is fine)"
end end
apache_pattern = %r{^https?://(?:[^/]*\.)?apache\.org/(?:dyn/closer\.cgi\?path=/?|dist/)(.*)}i
audit_urls(urls, apache_pattern) do |match, url|
problem "#{url} should be `https://www.apache.org/dyn/closer.lua?path=#{match[1]}`"
end
audit_urls(mirrors, /.*/) do |_, mirror| audit_urls(mirrors, /.*/) do |_, mirror|
urls.each do |url| urls.each do |url|
url_string = string_content(parameters(url).first) url_string = string_content(parameters(url).first)
@ -58,7 +63,7 @@ module RuboCop
%r{^http://ftpmirror\.gnu\.org/}, %r{^http://ftpmirror\.gnu\.org/},
%r{^http://download\.savannah\.gnu\.org/}, %r{^http://download\.savannah\.gnu\.org/},
%r{^http://download-mirror\.savannah\.gnu\.org/}, %r{^http://download-mirror\.savannah\.gnu\.org/},
%r{^http://[^/]*\.apache\.org/}, %r{^http://(?:[^/]*\.)?apache\.org/},
%r{^http://code\.google\.com/}, %r{^http://code\.google\.com/},
%r{^http://fossies\.org/}, %r{^http://fossies\.org/},
%r{^http://mirrors\.kernel\.org/}, %r{^http://mirrors\.kernel\.org/},
@ -78,6 +83,11 @@ module RuboCop
problem "Please use https:// for #{url}" problem "Please use https:// for #{url}"
end end
apache_mirror_pattern = %r{^https?://(?:[^/]*\.)?apache\.org/dyn/closer\.(?:cgi|lua)\?path=/?(.*)}i
audit_urls(mirrors, apache_mirror_pattern) do |match, mirror|
problem "Please use `https://archive.apache.org/dist/#{match[1]}` as a mirror instead of #{mirror}."
end
cpan_pattern = %r{^http://search\.mcpan\.org/CPAN/(.*)}i cpan_pattern = %r{^http://search\.mcpan\.org/CPAN/(.*)}i
audit_urls(urls, cpan_pattern) do |match, url| audit_urls(urls, cpan_pattern) do |match, url|
problem "#{url} should be `https://cpan.metacpan.org/#{match[1]}`" problem "#{url} should be `https://cpan.metacpan.org/#{match[1]}`"

View File

@ -18,6 +18,11 @@ describe RuboCop::Cop::FormulaAudit::Urls do
"url" => "http://tools.ietf.org/tools/rfcmarkup/rfcmarkup-1.119.tgz", "url" => "http://tools.ietf.org/tools/rfcmarkup/rfcmarkup-1.119.tgz",
"msg" => "Please use https:// for http://tools.ietf.org/tools/rfcmarkup/rfcmarkup-1.119.tgz", "msg" => "Please use https:// for http://tools.ietf.org/tools/rfcmarkup/rfcmarkup-1.119.tgz",
"col" => 2, "col" => 2,
}, {
"url" => "https://apache.org/dyn/closer.cgi?path=/apr/apr-1.7.0.tar.bz2",
"msg" => "https://apache.org/dyn/closer.cgi?path=/apr/apr-1.7.0.tar.bz2 should be " \
"`https://www.apache.org/dyn/closer.lua?path=apr/apr-1.7.0.tar.bz2`",
"col" => 2,
}, { }, {
"url" => "http://search.mcpan.org/CPAN/authors/id/Z/ZE/ZEFRAM/Perl4-CoreLibs-0.003.tar.gz", "url" => "http://search.mcpan.org/CPAN/authors/id/Z/ZE/ZEFRAM/Perl4-CoreLibs-0.003.tar.gz",
"msg" => "http://search.mcpan.org/CPAN/authors/id/Z/ZE/ZEFRAM/Perl4-CoreLibs-0.003.tar.gz should be " \ "msg" => "http://search.mcpan.org/CPAN/authors/id/Z/ZE/ZEFRAM/Perl4-CoreLibs-0.003.tar.gz should be " \

View File

@ -767,7 +767,7 @@ uses.
* `--no-fork`: * `--no-fork`:
Don't try to fork the repository. Don't try to fork the repository.
* `--mirror`: * `--mirror`:
Use the specified *`URL`* as a mirror URL. Use the specified *`URL`* as a mirror URL. If *`URL`* is a comma-separated list of URLs, multiple mirrors will be added.
* `--version`: * `--version`:
Use the specified *`version`* to override the value parsed from the URL or tag. Note that `--version=0` can be used to delete an existing version override from a formula if it has become redundant. Use the specified *`version`* to override the value parsed from the URL or tag. Note that `--version=0` can be used to delete an existing version override from a formula if it has become redundant.
* `--message`: * `--message`:

View File

@ -975,7 +975,7 @@ Don\'t try to fork the repository\.
. .
.TP .TP
\fB\-\-mirror\fR \fB\-\-mirror\fR
Use the specified \fIURL\fR as a mirror URL\. Use the specified \fIURL\fR as a mirror URL\. If \fIURL\fR is a comma\-separated list of URLs, multiple mirrors will be added\.
. .
.TP .TP
\fB\-\-version\fR \fB\-\-version\fR