From 46b3d24dd3a28bc9f3b6208957aaf848ec4f9633 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Fri, 16 Sep 2022 01:50:44 +0800 Subject: [PATCH] resource: automatic determine mirrors for glibc-bootstrap --- Library/Homebrew/resource.rb | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 1c6c5b2342..d09025f804 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -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,23 @@ 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 + + [*extra_urls, url, *mirrors].uniq + end + # A resource containing a Go package. class Go < Resource def stage(target, &block)