dev-cmd/bottle: Refactor setup_tar_and_args! to extend/os

This commit is contained in:
Ruiyang Wu 2023-04-10 16:18:56 -04:00
parent d7427ab762
commit 73a1380055
4 changed files with 47 additions and 13 deletions

View File

@ -231,26 +231,29 @@ module Homebrew
system "/usr/bin/sudo", "--non-interactive", "/usr/sbin/purge" system "/usr/bin/sudo", "--non-interactive", "/usr/sbin/purge"
end end
def self.setup_tar_and_args!(args, mtime) sig { returns(T::Array[String]) }
# TODO: Refactor and move to extend/os def self.tar_args
# Without --only-json-tab bottles are never reproducible [].freeze
tar_args = end
OS.mac? ? ["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze : ["--no-acls", "--no-xattrs"].freeze # rubocop:disable Homebrew/MoveToExtendOS
default_tar_args = ["tar", tar_args].freeze
return default_tar_args unless args.only_json_tab?
# Ensure tar is set up for reproducibility. sig { params(mtime: String).returns(T::Array[String]) }
def self.reproducible_gnutar_args(mtime)
# Ensure gnu tar is set up for reproducibility.
# https://reproducible-builds.org/docs/archives/ # https://reproducible-builds.org/docs/archives/
gnutar_args = [ [
"--format", "pax", "--owner", "0", "--group", "0", "--sort", "name", "--mtime=#{mtime}", "--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. # 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" "--pax-option", "globexthdr.name=/GlobalHead.%n,exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime"
].freeze ].freeze
end
# TODO: Refactor and move to extend/os sig { params(args: T.untyped, mtime: String).returns([String, T::Array[String]]) }
return ["tar", gnutar_args].freeze if OS.linux? # rubocop:disable Homebrew/MoveToExtendOS def self.setup_tar_and_args!(args, mtime)
# Without --only-json-tab bottles are never reproducible
default_tar_args = ["tar", tar_args].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. # Use gnu-tar as it can be set up for reproducibility better than libarchive.
begin begin
gnu_tar = Formula["gnu-tar"] gnu_tar = Formula["gnu-tar"]
rescue FormulaUnavailableError rescue FormulaUnavailableError
@ -259,7 +262,7 @@ module Homebrew
ensure_formula_installed!(gnu_tar, reason: "bottling") ensure_formula_installed!(gnu_tar, reason: "bottling")
["#{gnu_tar.opt_bin}/gtar", gnutar_args].freeze ["#{gnu_tar.opt_bin}/gtar", reproducible_gnutar_args(mtime)].freeze
end end
def self.formula_ignores(formula) def self.formula_ignores(formula)
@ -802,3 +805,5 @@ module Homebrew
checksums checksums
end end
end end
require "extend/os/dev-cmd/bottle"

View File

@ -0,0 +1,8 @@
# 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

View File

@ -0,0 +1,12 @@
# typed: true
# frozen_string_literal: true
module Homebrew
sig { params(args: T.untyped, mtime: String).returns([String, T::Array[String]]) }
def self.setup_tar_and_args!(args, mtime)
# Without --only-json-tab bottles are never reproducible
return ["tar", tar_args].freeze unless args.only_json_tab?
["tar", reproducible_gnutar_args(mtime)].freeze
end
end

View File

@ -0,0 +1,9 @@
# typed: true
# frozen_string_literal: true
module Homebrew
sig { returns(T::Array[String]) }
def self.tar_args
["--no-mac-metadata", "--no-acls", "--no-xattrs"].freeze
end
end