Skip to content

Commit

Permalink
Merge pull request #11167 from MikeMcQuaid/bottle-uid-gid-gtar
Browse files Browse the repository at this point in the history
dev-cmd/bottle: set uid/gid, use libarchive on macOS.
  • Loading branch information
MikeMcQuaid committed Apr 21, 2021
2 parents 1bcf347 + 4a3fc2a commit 3156b53
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,35 @@ def sudo_purge
system "/usr/bin/sudo", "--non-interactive", "/usr/sbin/purge"
end

def setup_tar_owner_group_args!
# Unset the owner/group for reproducible bottles.
# Use gnu-tar on Linux
return ["--owner", "0", "--group", "0"].freeze if OS.linux?

bsdtar_args = ["--uid", "0", "--gid", "0"].freeze

# System bsdtar is new enough on macOS Catalina and above.
return bsdtar_args if OS.mac? && MacOS.version >= :catalina

# Use newish libarchive on older macOS versions for reproducibility.
begin
libarchive = Formula["libarchive"]
rescue FormulaUnavailableError
return [].freeze
end

unless libarchive.installed?
ohai "Installing `libarchive` for bottling..."
safe_system HOMEBREW_BREW_FILE, "install", "--formula", libarchive.full_name
end

path = PATH.new(ENV["PATH"])
path.prepend(libarchive.opt_bin.to_s)
ENV["PATH"] = path

bsdtar_args
end

def bottle_formula(f, args:)
local_bottle_json = args.json? && f.local_bottle_path.present?

Expand Down Expand Up @@ -387,9 +416,11 @@ def bottle_formula(f, args:)

cd cellar do
sudo_purge
# Unset the owner/group for reproducible bottles.
# Tar then gzip for reproducible bottles.
safe_system "tar", "--create", "--numeric-owner", "--file", tar_path, "#{f.name}/#{f.pkg_version}"
owner_group_args = setup_tar_owner_group_args!
safe_system "tar", "--create", "--numeric-owner",
*owner_group_args,
"--file", tar_path, "#{f.name}/#{f.pkg_version}"
sudo_purge
# Set more times for reproducible bottles.
tar_path.utime(tab.source_modified_time, tab.source_modified_time)
Expand Down

0 comments on commit 3156b53

Please sign in to comment.