separate setup_tar_and_args method

This commit is contained in:
hyuraku 2023-02-06 21:15:38 +09:00
parent fde7ca31b8
commit ec1a1566bc
4 changed files with 41 additions and 23 deletions

View File

@ -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)

View File

@ -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

View File

@ -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/

View File

@ -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