From ec1a1566bc340dd17e2e7ee0ba3cbca07aa3a3ca Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:15:38 +0900 Subject: [PATCH] separate setup_tar_and_args method --- Library/Homebrew/dev-cmd/bottle.rb | 23 ++------------ Library/Homebrew/extend/os/dev-cmd/bottle.rb | 6 ++++ .../extend/os/linux/dev-cmd/bottle.rb | 4 +-- .../Homebrew/extend/os/mac/dev-cmd/bottle.rb | 31 +++++++++++++++++++ 4 files changed, 41 insertions(+), 23 deletions(-) create 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 a4aed67ad6..9ed113632d 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -234,31 +234,14 @@ 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 default_tar_args = ["tar", [].freeze].freeze 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") - - # 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 - - ["#{gnu_tar.opt_bin}/gtar", gnutar_args].freeze end + alias generic_setup_tar_and_args! setup_tar_and_args! + def formula_ignores(f) ignores = [] cellar_regex = Regexp.escape(HOMEBREW_CELLAR) diff --git a/Library/Homebrew/extend/os/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/dev-cmd/bottle.rb index 0ac282d690..a8e3bb68e5 100644 --- a/Library/Homebrew/extend/os/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/dev-cmd/bottle.rb @@ -2,3 +2,9 @@ # frozen_string_literal: true require "extend/os/linux/dev-cmd/bottle" if OS.linux? + +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 index 2187c0d751..81dee4eaf9 100644 --- a/Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb +++ b/Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb @@ -7,9 +7,7 @@ module Homebrew module_function def setup_tar_and_args!(args, mtime) - # Without --only-json-tab bottles are never reproducible - default_tar_args = ["tar", [].freeze].freeze - return default_tar_args unless args.only_json_tab? + generic_setup_tar_and_args!(args, mtime) # Ensure tar is set up for reproducibility. # https://reproducible-builds.org/docs/archives/ diff --git a/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb new file mode 100644 index 0000000000..c28ef48b2c --- /dev/null +++ b/Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb @@ -0,0 +1,31 @@ +# typed: false +# frozen_string_literal: true + +module Homebrew + extend T::Sig + + module_function + + def setup_tar_and_args!(args, mtime) + generic_setup_tar_and_args!(args, mtime) + + # 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") + + # 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 + + ["#{gnu_tar.opt_bin}/gtar", gnutar_args].freeze + end +end