resource: automatic determine mirrors for glibc-bootstrap

This commit is contained in:
Xuehai Pan 2022-09-16 01:50:44 +08:00
parent 7a14ae6187
commit 46b3d24dd3

View File

@ -78,8 +78,11 @@ class Resource
end end
def downloader def downloader
@downloader ||= download_strategy.new(url, download_name, version, return @downloader if @downloader.present?
mirrors: mirrors.dup, **specs)
url, *mirrors = determine_url_mirrors
@downloader = download_strategy.new(url, download_name, version,
mirrors: mirrors, **specs)
end end
# Removes /s from resource names; this allows Go package names # Removes /s from resource names; this allows Go package names
@ -277,6 +280,23 @@ class Resource
version unless version.null? version unless version.null?
end 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
[*extra_urls, url, *mirrors].uniq
end
# A resource containing a Go package. # A resource containing a Go package.
class Go < Resource class Go < Resource
def stage(target, &block) def stage(target, &block)