File: update-googletest.sh

package info (click to toggle)
nodejs 22.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 246,928 kB
  • sloc: cpp: 1,582,349; javascript: 582,017; ansic: 82,400; python: 60,561; sh: 4,009; makefile: 2,263; asm: 1,732; pascal: 1,565; perl: 248; lisp: 222; xml: 42
file content (89 lines) | stat: -rwxr-xr-x 3,387 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
set -e
# Shell script to update GoogleTest in the source tree to the most recent version.
# GoogleTest follows the Abseil Live at Head philosophy and rarely creates tags
# or GitHub releases, so instead, we use the latest commit on the main branch.

BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
DEPS_DIR="$BASE_DIR/deps"

NEW_UPSTREAM_SHA1=$(git ls-remote "https://github.com/google/googletest.git" HEAD | awk '{print $1}')
NEW_VERSION=$(echo "$NEW_UPSTREAM_SHA1" | head -c 7)

# shellcheck disable=SC1091
. "$BASE_DIR/tools/dep_updaters/utils.sh"

echo "Comparing $NEW_VERSION with current revision"

git remote add googletest-upstream https://github.com/google/googletest.git
git fetch googletest-upstream "$NEW_UPSTREAM_SHA1"
git remote remove googletest-upstream

DIFF_TREE=$(
  git diff HEAD:deps/googletest/LICENSE "$NEW_UPSTREAM_SHA1:LICENSE"
  git diff-tree HEAD:deps/googletest/include "$NEW_UPSTREAM_SHA1:googletest/include"
  git diff-tree HEAD:deps/googletest/src "$NEW_UPSTREAM_SHA1:googletest/src"
)

if [ -z "$DIFF_TREE" ]; then
  echo "Skipped because googletest is on the latest version."
  exit 0
fi

# This is a rather arbitrary restriction. This script is assumed to run on
# Sunday, shortly after midnight UTC. This check thus prevents pulling in the
# most recent commits if any changes were made on Friday or Saturday (UTC).
# Because of Google's own "Live at Head" philosophy, new bugs that are likely to
# affect Node.js tend to be fixed quickly, so we don't want to pull in a commit
# that was just pushed, and instead rather wait for the next week's update. If
# no commits have been pushed in the last two days, we assume that the most
# recent commit is stable enough to be pulled in.
LAST_CHANGE_DATE=$(git log -1 --format=%ct "$NEW_UPSTREAM_SHA1" -- LICENSE googletest/include googletest/src)
TWO_DAYS_AGO=$(date -d 'now - 2 days' '+%s')
if [ "$LAST_CHANGE_DATE" -gt "$TWO_DAYS_AGO" ]; then
  echo "Skipped because the latest version is too recent."
  exit 0
fi

echo "Creating temporary work tree"

WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
WORKTREE="$WORKSPACE/googletest"

cleanup () {
  EXIT_CODE=$?
  [ -d "$WORKTREE" ] && git worktree remove -f "$WORKTREE"
  [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
  exit $EXIT_CODE
}

trap cleanup INT TERM EXIT

git worktree add "$WORKTREE" "$NEW_UPSTREAM_SHA1"

echo "Copying LICENSE, include and src to deps/googletest"
for p in LICENSE googletest/include googletest/src ; do
  rm -rf "$DEPS_DIR/googletest/$(basename "$p")"
  cp -R "$WORKTREE/$p" "$DEPS_DIR/googletest/$(basename "$p")"
done

echo "Updating googletest.gyp"

NEW_GYP=$(
  sed "/'googletest_sources': \[/q" "$DEPS_DIR/googletest/googletest.gyp"
  for f in $( (cd deps/googletest/ && find include src -type f \( -iname '*.h' -o -iname '*.cc' \) ) | LANG=C LC_ALL=C sort --stable ); do
    if [ "$(basename "$f")" != "gtest_main.cc" ] &&
       [ "$(basename "$f")" != "gtest-all.cc" ] &&
       [ "$(basename "$f")" != "gtest_prod.h" ] ; then
      echo "      '$f',"
    fi
  done
  sed -ne '/\]/,$ p' "$DEPS_DIR/googletest/googletest.gyp"
)

echo "$NEW_GYP" >"$DEPS_DIR/googletest/googletest.gyp"

# Update the version number on maintaining-dependencies.md
# and print the new version as the last line of the script as we need
# to add it to $GITHUB_ENV variable
finalize_version_update "googletest" "$NEW_VERSION"