-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: add update script for googletest
GoogleTest follows the Abseil Live at Head philosophy, and rarely creates tags or GitHub releases, so instead, follow Google's recommendation and update to the upstream HEAD every once in a while. The tricky bit is properly updating googletest.gyp, and this script might fail doing so in the future. Refs: nodejs/security-wg#828 PR-URL: #47482 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
- Loading branch information
1 parent
4858e19
commit 54b4fc2
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/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) | ||
|
||
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" | ||
|
||
echo "All done!" | ||
echo "" | ||
echo "Please git stage googletest, commit the new version:" | ||
echo "" | ||
echo "$ git stage -A deps/googletest" | ||
echo "$ git commit -m \"deps: update googletest to $NEW_VERSION\"" | ||
echo "" | ||
|
||
# The last line of the script should always print the new version, | ||
# as we need to add it to $GITHUB_ENV variable. | ||
echo "NEW_VERSION=$NEW_VERSION" |