From 30b2a546e5de26bf49a8faaf5322206bf4ea8406 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 10 Feb 2023 17:01:22 +0000 Subject: [PATCH] Revert "move `dev-cmd/bottle` methods to extend/os" --- Library/Homebrew/dev-cmd/bottle.rb | 42 ++++++++++++++----- Library/Homebrew/extend/os/dev-cmd/bottle.rb | 8 ---- .../extend/os/linux/dev-cmd/bottle.rb | 34 --------------- .../Homebrew/extend/os/mac/dev-cmd/bottle.rb | 24 ----------- 4 files changed, 32 insertions(+), 76 deletions(-) delete mode 100644 Library/Homebrew/extend/os/dev-cmd/bottle.rb delete mode 100644 Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb delete mode 100644 Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index ecd61f2375..3af859eb19 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -11,7 +11,6 @@ require "utils/inreplace" require "erb" require "utils/gzip" require "api" -require "extend/os/dev-cmd/bottle" BOTTLE_ERB = <<-EOS bottle do @@ -234,26 +233,38 @@ module Homebrew system "/usr/bin/sudo", "--non-interactive", "/usr/sbin/purge" end - def setup_tar_and_args!(_args, _mtime) + def setup_tar_and_args!(args, mtime) # Without --only-json-tab bottles are never reproducible - ["tar", [].freeze].freeze - end + default_tar_args = ["tar", [].freeze].freeze + return default_tar_args unless args.only_json_tab? - alias generic_setup_tar_and_args! setup_tar_and_args! - - def gnutar_args(mtime) # Ensure tar is set up for reproducibility. # https://reproducible-builds.org/docs/archives/ - [ + gnutar_args = [ "--format", "pax", "--owner", "0", "--group", "0", "--sort", "name", "--mtime=#{mtime}", # Set exthdr names to exclude PID (for GNU tar <1.33). Also don't store atime and ctime. "--pax-option", "globexthdr.name=/GlobalHead.%n,exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime" ].freeze + + # TODO: Refactor and move to extend/os + return ["tar", gnutar_args].freeze if OS.linux? # rubocop:disable Homebrew/MoveToExtendOS + + # Use gnu-tar on macOS as it can be set up for reproducibility better than libarchive. + begin + gnu_tar = Formula["gnu-tar"] + rescue FormulaUnavailableError + return default_tar_args + end + + ensure_formula_installed!(gnu_tar, reason: "bottling") + + ["#{gnu_tar.opt_bin}/gtar", gnutar_args].freeze end def formula_ignores(f) ignores = [] cellar_regex = Regexp.escape(HOMEBREW_CELLAR) + prefix_regex = Regexp.escape(HOMEBREW_PREFIX) # Ignore matches to go keg, because all go binaries are statically linked. any_go_deps = f.deps.any? do |dep| @@ -264,11 +275,22 @@ module Homebrew ignores << %r{#{cellar_regex}/#{go_regex}/[\d.]+/libexec} end + # TODO: Refactor and move to extend/os + # rubocop:disable Homebrew/MoveToExtendOS + ignores << case f.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 + # rubocop:enable Homebrew/MoveToExtendOS + ignores.compact end - alias generic_formula_ignores formula_ignores - def bottle_formula(f, args:) local_bottle_json = args.json? && f.local_bottle_path.present? diff --git a/Library/Homebrew/extend/os/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/dev-cmd/bottle.rb deleted file mode 100644 index d87c5e5843..0000000000 --- a/Library/Homebrew/extend/os/dev-cmd/bottle.rb +++ /dev/null @@ -1,8 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -if OS.mac? - require "extend/os/mac/dev-cmd/bottle" -elsif OS.linux? - require "extend/os/linux/dev-cmd/bottle" -end diff --git a/Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb deleted file mode 100644 index b1d6afe18b..0000000000 --- a/Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb +++ /dev/null @@ -1,34 +0,0 @@ -# typed: false -# frozen_string_literal: true - -module Homebrew - extend T::Sig - - module_function - - def setup_tar_and_args!(args, mtime) - default_tar_args = generic_setup_tar_and_args!(args, mtime) - return default_tar_args unless args.only_json_tab? - - ["tar", gnutar_args(mtime)].freeze - end - - def formula_ignores(f) - cellar_regex = Regexp.escape(HOMEBREW_CELLAR) - prefix_regex = Regexp.escape(HOMEBREW_PREFIX) - - ignores = generic_formula_ignores(f) - - ignores << case f.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 diff --git a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb deleted file mode 100644 index d81f7fd824..0000000000 --- a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb +++ /dev/null @@ -1,24 +0,0 @@ -# typed: false -# frozen_string_literal: true - -module Homebrew - extend T::Sig - - module_function - - def setup_tar_and_args!(args, mtime) - default_tar_args = generic_setup_tar_and_args!(args, mtime) - return default_tar_args unless args.only_json_tab? - - # Use gnu-tar on macOS as it can be set up for reproducibility better than libarchive. - begin - gnu_tar = Formula["gnu-tar"] - rescue FormulaUnavailableError - return default_tar_args - end - - ensure_formula_installed!(gnu_tar, reason: "bottling") - - ["#{gnu_tar.opt_bin}/gtar", gnutar_args(mtime)].freeze - end -end