From a37864da0fbf6e9d13b3c6a6eb4145d7f8f32144 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 14 May 2024 16:03:35 +0900 Subject: [PATCH] Add HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK This fits the use-case I've heard multiple times where people want to rely exclusively on their artifact provider. Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> --- Library/Homebrew/cmd/vendor-install.sh | 5 +++++ Library/Homebrew/download_strategy.rb | 1 + Library/Homebrew/env_config.rb | 6 ++++++ Library/Homebrew/resource.rb | 6 +++++- Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi | 3 +++ docs/Manpage.md | 6 ++++++ manpages/brew.1 | 3 +++ 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 4e4eabfc6aeef..8f527f9c94397 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -47,6 +47,11 @@ set_ruby_variables() { if [[ -n "${HOMEBREW_ARTIFACT_DOMAIN}" ]] then ruby_URLs+=("${HOMEBREW_ARTIFACT_DOMAIN}/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:${ruby_SHA}") + if [[ -n "${HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK}" ]] + then + ruby_URL="${ruby_URLs[0]}" + return + fi fi if [[ -n "${HOMEBREW_BOTTLE_DOMAIN}" ]] then diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 821ed735f9a52..93d407d833ae0 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -405,6 +405,7 @@ def fetch(timeout: nil) if (domain = Homebrew::EnvConfig.artifact_domain) url = url.sub(%r{^https?://#{GitHubPackages::URL_DOMAIN}/}o, "#{domain.chomp("/")}/") + urls = [] if Homebrew::EnvConfig.artifact_domain_no_fallback? end ohai "Downloading #{url}" diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 38bdb3643634a..f3f5ca26f9824 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -44,6 +44,12 @@ module EnvConfig "to instead be downloaded from " \ "`http://localhost:8080/v2/homebrew/core/gettext/manifests/0.21`", }, + HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK: { + description: "If `HOMEBREW_ARTIFACT_DOMAIN` and `HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK` are both set, " \ + "if the request to `HOMEBREW_ARTIFACT_DOMAIN` fails then it Homebrew will error rather than " \ + "trying any other/default URLs.", + boolean: true, + }, HOMEBREW_AUTO_UPDATE_SECS: { description: "Run `brew update` once every `HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \ "e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, " \ diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 7a7517184e3c5..ad0cca0136d72 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -237,8 +237,12 @@ def determine_url_mirrors # glibc-bootstrap if url.start_with?("https://github.com/Homebrew/glibc-bootstrap/releases/download") if (artifact_domain = Homebrew::EnvConfig.artifact_domain.presence) - extra_urls << url.sub("https://github.com", artifact_domain) + artifact_url = url.sub("https://github.com", artifact_domain) + return [artifact_url] if Homebrew::EnvConfig.artifact_domain_no_fallback? + + extra_urls << artifact_url 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}" diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi index ab3fb62285945..795c49493b297 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi @@ -25,6 +25,9 @@ module Homebrew::EnvConfig sig { returns(T.nilable(::String)) } def artifact_domain; end + sig { returns(T::Boolean) } + def artifact_domain_no_fallback?; end + sig { returns(T.nilable(::String)) } def auto_update_secs; end diff --git a/docs/Manpage.md b/docs/Manpage.md index f0bb10c2ffb1a..b01e1b80212b6 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -3510,6 +3510,12 @@ command execution e.g. `$(cat file)`. downloaded from `http://localhost:8080/v2/homebrew/core/gettext/manifests/0.21` +`HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK` + +: If `HOMEBREW_ARTIFACT_DOMAIN` and `HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK` are + both set, if the request to `HOMEBREW_ARTIFACT_DOMAIN` fails then it Homebrew + will error rather than trying any other/default URLs. + `HOMEBREW_AUTO_UPDATE_SECS` : Run `brew update` once every `HOMEBREW_AUTO_UPDATE_SECS` seconds before some diff --git a/manpages/brew.1 b/manpages/brew.1 index b97b2d11552e6..bb93951de10c7 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -2244,6 +2244,9 @@ Linux only: Pass this value to a type name representing the compiler\[u2019]s \f \fBHOMEBREW_ARTIFACT_DOMAIN\fP Prefix all download URLs, including those for bottles, with this value\. For example, \fBHOMEBREW_ARTIFACT_DOMAIN=http://localhost:8080\fP will cause a formula with the URL \fBhttps://example\.com/foo\.tar\.gz\fP to instead download from \fBhttp://localhost:8080/https://example\.com/foo\.tar\.gz\fP\&\. Bottle URLs however, have their domain replaced with this prefix\. This results in e\.g\. \fBhttps://ghcr\.io/v2/homebrew/core/gettext/manifests/0\.21\fP to instead be downloaded from \fBhttp://localhost:8080/v2/homebrew/core/gettext/manifests/0\.21\fP .TP +\fBHOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK\fP +If \fBHOMEBREW_ARTIFACT_DOMAIN\fP and \fBHOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK\fP are both set, if the request to \fBHOMEBREW_ARTIFACT_DOMAIN\fP fails then it Homebrew will error rather than trying any other/default URLs\. +.TP \fBHOMEBREW_AUTO_UPDATE_SECS\fP Run \fBbrew update\fP once every \fBHOMEBREW_AUTO_UPDATE_SECS\fP seconds before some commands, e\.g\. \fBbrew install\fP, \fBbrew upgrade\fP and \fBbrew tap\fP\&\. Alternatively, disable auto\-update entirely with \fBHOMEBREW_NO_AUTO_UPDATE\fP\&\. .RS