Merge pull request #13875 from XuehaiPan/resource-url-mirrors-mapping

resource: automatic determine mirrors for `glibc-bootstrap` and PyPI resources
This commit is contained in:
Mike McQuaid 2022-09-18 13:14:59 +01:00 committed by GitHub
commit 8a4826a49e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 2 deletions

View File

@ -793,6 +793,9 @@ module Cask
else
host_uri.host
end
return false if homepage.blank?
home = homepage.downcase
if (split_host = host.split(".")).length >= 3
host = split_host[-2..].join(".")

View File

@ -318,6 +318,10 @@ module Homebrew
"outdated.",
boolean: true,
},
HOMEBREW_PIP_INDEX_URL: {
description: "If set, `brew install <formula>` will use this URL to download PyPI package resources.",
default_text: "`https://pypi.org/simple`.",
},
HOMEBREW_PRY: {
description: "If set, use Pry for the `brew irb` command.",
boolean: true,

View File

@ -78,8 +78,11 @@ class Resource
end
def downloader
@downloader ||= download_strategy.new(url, download_name, version,
mirrors: mirrors.dup, **specs)
return @downloader if @downloader.present?
url, *mirrors = determine_url_mirrors
@downloader = download_strategy.new(url, download_name, version,
mirrors: mirrors, **specs)
end
# Removes /s from resource names; this allows Go package names
@ -277,6 +280,31 @@ class Resource
version unless version.null?
end
def determine_url_mirrors
extra_urls = []
# glibc-bootstrap
if url.start_with?("https://github.com/Homebrew/glibc-bootstrap/releases/download")
if Homebrew::EnvConfig.artifact_domain.present?
extra_urls << url.sub("https://github.com", Homebrew::EnvConfig.artifact_domain)
end
if Homebrew::EnvConfig.bottle_domain != HOMEBREW_BOTTLE_DEFAULT_DOMAIN
tag, filename = url.split("/").last(2)
extra_urls << "#{Homebrew::EnvConfig.bottle_domain}/glibc-bootstrap/#{tag}/#{filename}"
end
end
# PyPI packages: PEP 503 Simple Repository API <https://peps.python.org/pep-0503>
if Homebrew::EnvConfig.pip_index_url.present?
pip_index_base_url = Homebrew::EnvConfig.pip_index_url.chomp("/").chomp("/simple")
%w[https://files.pythonhosted.org https://pypi.org].each do |base_url|
extra_urls << url.sub(base_url, pip_index_base_url) if url.start_with?("#{base_url}/packages")
end
end
[*extra_urls, url, *mirrors].uniq
end
# A resource containing a Go package.
class Go < Resource
def stage(target, &block)

View File

@ -2655,6 +2655,8 @@ module Homebrew::EnvConfig
def self.no_proxy(); end
def self.pip_index_url(); end
def self.pry?(); end
def self.simulate_macos_on_linux?(); end