Skip to content

Commit 7330847

Browse files
committed
tools: fix zlib updater script
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent f30139e commit 7330847

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

tools/dep_updaters/update-zlib.sh

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
set -e
2+
set -ex
33
# Shell script to update zlib in the source tree to the most recent version.
44
# Zlib rarely creates tags or releases, so we use the latest commit on the main branch.
55
# See: https://github.com/nodejs/node/pull/47417
@@ -12,7 +12,7 @@ DEPS_DIR="$BASE_DIR/deps"
1212

1313
echo "Comparing latest upstream with current revision"
1414

15-
git fetch https://chromium.googlesource.com/chromium/src/third_party/zlib.git HEAD
15+
git fetch --no-tags https://chromium.googlesource.com/chromium/src/third_party/zlib.git HEAD
1616

1717
# Revert zconf.h changes before checking diff
1818
perl -i -pe 's|^//#include "chromeconf.h"|#include "chromeconf.h"|' "$DEPS_DIR/zlib/zconf.h"
@@ -35,7 +35,7 @@ fi
3535
# two days, we assume that the most recent commit is stable enough to be
3636
# pulled in.
3737
LAST_CHANGE_DATE=$(git log -1 --format=%ct FETCH_HEAD)
38-
TWO_DAYS_AGO=$(date -d 'now - 2 days' '+%s')
38+
TWO_DAYS_AGO=$(date -d '2 days ago' '+%s' 2>/dev/null || date -v-2d '+%s')
3939

4040
if [ "$LAST_CHANGE_DATE" -gt "$TWO_DAYS_AGO" ]; then
4141
echo "Skipped because the latest version is too recent."
@@ -48,32 +48,35 @@ echo "Making temporary workspace..."
4848

4949
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
5050

51-
cd "$WORKSPACE"
51+
cleanup () {
52+
EXIT_CODE=$?
53+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
54+
exit $EXIT_CODE
55+
}
5256

53-
mkdir zlib
57+
trap cleanup INT TERM EXIT
5458

55-
ZLIB_TARBALL="zlib-v$NEW_VERSION.tar.gz"
5659

57-
echo "Fetching zlib source archive"
58-
curl -sL -o "$ZLIB_TARBALL" https://chromium.googlesource.com/chromium/src/+archive/refs/heads/main/third_party/zlib.tar.gz
60+
ZLIB_TARBALL="zlib-v$NEW_VERSION.tar"
5961

60-
log_and_verify_sha256sum "zlib" "$ZLIB_TARBALL"
62+
echo "Packing zlib source archive"
63+
git archive -o "$WORKSPACE/$ZLIB_TARBALL" --format=tar FETCH_HEAD
6164

62-
gzip -dc "$ZLIB_TARBALL" | tar xf - -C zlib/
65+
log_and_verify_sha256sum "zlib" "$WORKSPACE/$ZLIB_TARBALL"
6366

64-
rm "$ZLIB_TARBALL"
67+
mkdir "$WORKSPACE/zlib"
68+
tar -xf "$WORKSPACE/$ZLIB_TARBALL" -C "$WORKSPACE/zlib"
6569

66-
cp "$DEPS_DIR/zlib/zlib.gyp" "$DEPS_DIR/zlib/win32/zlib.def" "$DEPS_DIR"
70+
mv "$DEPS_DIR/zlib/zlib.gyp" "$WORKSPACE/."
71+
mv "$DEPS_DIR/zlib/win32/zlib.def" "$WORKSPACE/."
6772

68-
rm -rf "$DEPS_DIR/zlib" zlib/.git
73+
rm -rf "$DEPS_DIR/zlib"
6974

70-
mv zlib "$DEPS_DIR/"
75+
mv "$WORKSPACE/zlib" "$DEPS_DIR/."
76+
mv "$WORKSPACE/zlib.gyp" "$DEPS_DIR/zlib/."
7177

72-
mv "$DEPS_DIR/zlib.gyp" "$DEPS_DIR/zlib/"
73-
74-
mkdir "$DEPS_DIR/zlib/win32"
75-
76-
mv "$DEPS_DIR/zlib.def" "$DEPS_DIR/zlib/win32"
78+
mkdir -p "$DEPS_DIR/zlib/win32"
79+
mv "$WORKSPACE/zlib.def" "$DEPS_DIR/zlib/win32/."
7780

7881
perl -i -pe 's|^#include "chromeconf.h"|//#include "chromeconf.h"|' "$DEPS_DIR/zlib/zconf.h"
7982

0 commit comments

Comments
 (0)