File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ BUILD_DATE_STAMP="202001010000.00"
2222function reproducible_tar_gzip() {
2323 local dir=$1
2424 local tar_cmd=tar
25+ local gzip_cmd=gzip
2526
2627 # MacOS has a version of BSD tar which doesn't support setting the --mtime
2728 # flag. We need gnu-tar, or gtar for short to be installed for this script to
@@ -38,12 +39,27 @@ function reproducible_tar_gzip() {
3839 tar_cmd=gtar
3940 fi
4041
42+ # On MacOS, the default BSD gzip produces a different output than the GNU
43+ # gzip on Linux. To ensure reproducible builds, we need to use GNU gzip.
44+ gzip_version=$( gzip --version 2>&1 || true)
45+ if [[ ! " $gzip_version " =~ " GNU" ]]; then
46+ if ! command -v " ggzip" > /dev/null 2>&1 ; then
47+ echo " GNU gzip is required but cannot be found!"
48+ echo " On MacOS please run 'brew install gzip' to install ggzip."
49+ exit 1
50+ fi
51+
52+ # We have ggzip installed, use that instead.
53+ gzip_cmd=ggzip
54+ fi
55+
4156 # Pin down the timestamp time zone.
4257 export TZ=UTC
4358
4459 find " ${dir} " -print0 | LC_ALL=C sort -r -z | $tar_cmd \
4560 " --mtime=${BUILD_DATE} " --no-recursion --null --mode=u+rw,go+r-w,a+X \
46- --owner=0 --group=0 --numeric-owner -c -T - | gzip -9n > " ${dir} .tar.gz"
61+ --owner=0 --group=0 --numeric-owner -c -T - | $gzip_cmd \
62+ -9n > " ${dir} .tar.gz"
4763
4864 rm -r " ${dir} "
4965}
You can’t perform that action at this time.
0 commit comments