Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't save mac metadata/extended attributes for brew bottle #15173

Merged
merged 2 commits into from Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions Library/Homebrew/dev-cmd/bottle.rb
Expand Up @@ -231,23 +231,29 @@ def self.sudo_purge
system "/usr/bin/sudo", "--non-interactive", "/usr/sbin/purge"
end

def self.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?
sig { returns(T::Array[String]) }
def self.tar_args
[].freeze
end

# 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/
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
end

# TODO: Refactor and move to extend/os
return ["tar", gnutar_args].freeze if OS.linux? # rubocop:disable Homebrew/MoveToExtendOS
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
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
gnu_tar = Formula["gnu-tar"]
rescue FormulaUnavailableError
Expand All @@ -256,7 +262,7 @@ def self.setup_tar_and_args!(args, mtime)

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

def self.formula_ignores(formula)
Expand Down Expand Up @@ -799,3 +805,5 @@ def self.old_checksums(formula, formula_ast, bottle_hash, args:)
checksums
end
end

require "extend/os/dev-cmd/bottle"
8 changes: 8 additions & 0 deletions Library/Homebrew/extend/os/dev-cmd/bottle.rb
@@ -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
12 changes: 12 additions & 0 deletions Library/Homebrew/extend/os/linux/dev-cmd/bottle.rb
@@ -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?
Comment on lines +7 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to share this with generic if possible. Not sure if it is though 🤔. Feel free to leave it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible, but I end up with more lines of code and more complicated logic so I guess it is better to leave as is.


["tar", reproducible_gnutar_args(mtime)].freeze
end
end
9 changes: 9 additions & 0 deletions Library/Homebrew/extend/os/mac/dev-cmd/bottle.rb
@@ -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