From 3fbfff20a235917475e75d600b679536c2b2ce7f Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Sat, 20 Sep 2025 20:44:50 +0800 Subject: [PATCH] dev-cmd/bottle: fix relocatable bottling for GCC and Binutils on Linux Since dc71b7c8f6c16cd9a4d6a910326d9914101130a2, bottles for GCC and Binutils are no longer relocatable due to a misplacement of the relevant code in `extend/os`. Fix this by moving the code to the correct location. --- Library/Homebrew/extend/os/dev-cmd/bottle.rb | 1 + .../extend/os/linux/dev-cmd/bottle.rb | 32 +++++++++++++++++++ .../Homebrew/extend/os/mac/dev-cmd/bottle.rb | 20 ------------ 3 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb diff --git a/Library/Homebrew/extend/os/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/dev-cmd/bottle.rb index 7aec276a06fd8..7f757127bab69 100644 --- a/Library/Homebrew/extend/os/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/dev-cmd/bottle.rb @@ -1,4 +1,5 @@ # typed: strict # frozen_string_literal: true +require "extend/os/linux/dev-cmd/bottle" if OS.linux? require "extend/os/mac/dev-cmd/bottle" if OS.mac? diff --git a/Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb new file mode 100644 index 0000000000000..482bec79f5102 --- /dev/null +++ b/Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb @@ -0,0 +1,32 @@ +# typed: strict +# frozen_string_literal: true + +module OS + module Linux + module DevCmd + module Bottle + sig { params(formula: Formula).returns(T::Array[Regexp]) } + def formula_ignores(formula) + ignores = super + + cellar_regex = Regexp.escape(HOMEBREW_CELLAR) + prefix_regex = Regexp.escape(HOMEBREW_PREFIX) + + ignores << case formula.name + # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: + # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. + when Version.formula_optionally_versioned_regex(:gcc) + Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) + # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. + when Version.formula_optionally_versioned_regex(:binutils) + %r{#{cellar_regex}/binutils} + end + + ignores.compact + end + end + end + end +end + +Homebrew::DevCmd::Bottle.prepend(OS::Linux::DevCmd::Bottle) diff --git a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb index e75eeab739608..9d07b436956cd 100644 --- a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb @@ -18,26 +18,6 @@ def tar_args def gnu_tar(gnu_tar_formula) "#{gnu_tar_formula.opt_bin}/gtar" end - - sig { params(formula: Formula).returns(T::Array[Regexp]) } - def formula_ignores(formula) - ignores = super - - cellar_regex = Regexp.escape(HOMEBREW_CELLAR) - prefix_regex = Regexp.escape(HOMEBREW_PREFIX) - - ignores << case formula.name - # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: - # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. - when Version.formula_optionally_versioned_regex(:gcc) - Regexp.union(%r{#{cellar_regex}/gcc}, %r{#{prefix_regex}/opt/gcc}) if OS.linux? - # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. - when Version.formula_optionally_versioned_regex(:binutils) - %r{#{cellar_regex}/binutils} if OS.linux? - end - - ignores.compact - end end end end