Skip to content

Commit 8346181

Browse files
authored
tools: fix zlib updater script
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #63707 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent af2e68b commit 8346181

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

tools/dep_updaters/update-zlib.sh

Lines changed: 22 additions & 23 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,13 +12,13 @@ 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"
1919
git stash -- "$DEPS_DIR/zlib/zconf.h"
2020

21-
DIFF_TREE=$(git diff --diff-filter=d 'stash@{0}:deps/zlib' FETCH_HEAD)
21+
DIFF_TREE=$(git diff --quiet --diff-filter=d 'stash@{0}:deps/zlib' FETCH_HEAD || echo "Changes detected")
2222

2323
git stash drop
2424

@@ -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,31 @@ 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+
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"
59+
ZLIB_TARBALL="zlib-$LATEST_COMMIT.tar"
5660

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
61+
echo "Packing zlib source archive"
62+
git archive --prefix=zlib/ -o "$WORKSPACE/$ZLIB_TARBALL" --format=tar FETCH_HEAD
5963

60-
log_and_verify_sha256sum "zlib" "$ZLIB_TARBALL"
64+
log_and_verify_sha256sum "zlib" "$WORKSPACE/$ZLIB_TARBALL"
6165

62-
gzip -dc "$ZLIB_TARBALL" | tar xf - -C zlib/
66+
mv "$DEPS_DIR/zlib/zlib.gyp" "$WORKSPACE/."
67+
mv "$DEPS_DIR/zlib/win32/zlib.def" "$WORKSPACE/."
6368

64-
rm "$ZLIB_TARBALL"
69+
rm -rf "$DEPS_DIR/zlib"
70+
tar -xf "$WORKSPACE/$ZLIB_TARBALL" -C "$DEPS_DIR" --exclude='zlib/doc/'
6571

66-
cp "$DEPS_DIR/zlib/zlib.gyp" "$DEPS_DIR/zlib/win32/zlib.def" "$DEPS_DIR"
72+
mv "$WORKSPACE/zlib.gyp" "$DEPS_DIR/zlib/."
6773

68-
rm -rf "$DEPS_DIR/zlib" zlib/.git
69-
70-
mv zlib "$DEPS_DIR/"
71-
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"
74+
mkdir -p "$DEPS_DIR/zlib/win32"
75+
mv "$WORKSPACE/zlib.def" "$DEPS_DIR/zlib/win32/."
7776

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

@@ -82,7 +81,7 @@ VERSION_NUMBER=$(grep "#define ZLIB_VERSION" "$DEPS_DIR/zlib/zlib.h" | sed -n "s
8281
NEW_VERSION="$VERSION_NUMBER-$LATEST_COMMIT"
8382

8483
# update version information in src/zlib_version.h
85-
cat > "$ROOT/src/zlib_version.h" <<EOF
84+
cat -> "$BASE_DIR/src/zlib_version.h" <<EOF
8685
// This is an auto generated file, please do not edit.
8786
// Refer to tools/dep_updaters/update-zlib.sh
8887
#ifndef SRC_ZLIB_VERSION_H_

0 commit comments

Comments
 (0)