Skip to content

Commit 6d8872f

Browse files
committed
release.sh: reproducible gzip on Mac
Make sure we use GNU gzip. Mac by default uses BSD gzip.
1 parent a34b46c commit 6d8872f

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

docs/release.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ other tools:
5858
sudo apt-get install build-essential git make zip perl gpg
5959
```
6060

61+
On MacOS, you will need to install GNU tar and GNU gzip, which can be done with
62+
`brew`:
63+
64+
```bash
65+
brew install gnu-tar gzip
66+
```
67+
6168
Add GPG key of Alex Bosworth to verify release tag signature:
6269
```bash
6370
gpg --keyserver keys.openpgp.org --recv-keys DE23E73BFA8A0AD5587D2FCDE80D2F3F311FD87E

release.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ function reproducible_tar_gzip() {
102102
local dir=$1
103103
local dst=$2
104104
local tar_cmd=tar
105+
local gzip_cmd=gzip
105106

106107
# MacOS has a version of BSD tar which doesn't support setting the --mtime
107108
# flag. We need gnu-tar, or gtar for short to be installed for this script to
108109
# work properly.
109-
tar_version=$(tar --version)
110+
tar_version=$(tar --version 2>&1 || true)
110111
if [[ ! "$tar_version" =~ "GNU tar" ]]; then
111-
if ! command -v "gtar"; then
112+
if ! command -v "gtar" >/dev/null 2>&1; then
112113
red "GNU tar is required but cannot be found!"
113114
red "On MacOS please run 'brew install gnu-tar' to install gtar."
114115
exit 1
@@ -118,12 +119,26 @@ function reproducible_tar_gzip() {
118119
tar_cmd=gtar
119120
fi
120121

122+
# On MacOS, the default BSD gzip produces a different output than the GNU
123+
# gzip on Linux. To ensure reproducible builds, we need to use GNU gzip.
124+
gzip_version=$(gzip --version 2>&1 || true)
125+
if [[ ! "$gzip_version" =~ "GNU" ]]; then
126+
if ! command -v "ggzip" >/dev/null 2>&1; then
127+
red "GNU gzip is required but cannot be found!"
128+
red "On MacOS please run 'brew install gzip' to install ggzip."
129+
exit 1
130+
fi
131+
132+
# We have ggzip installed, use that instead.
133+
gzip_cmd=ggzip
134+
fi
135+
121136
# Pin down the timestamp time zone.
122137
export TZ=UTC
123138

124139
find "${dir}" -print0 | LC_ALL=C sort -r -z | $tar_cmd \
125140
"--mtime=${BUILD_DATE}" --no-recursion --null --mode=u+rw,go+r-w,a+X \
126-
--owner=0 --group=0 --numeric-owner -c -T - | gzip -9n > "$dst"
141+
--owner=0 --group=0 --numeric-owner -c -T - | $gzip_cmd -9n > "$dst"
127142
}
128143

129144
# reproducible_zip creates a reproducible zip file of a directory. This

0 commit comments

Comments
 (0)