|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | +# Shell script to update GoogleTest in the source tree to the most recent version. |
| 4 | +# GoogleTest follows the Abseil Live at Head philosophy and rarely creates tags |
| 5 | +# or GitHub releases, so instead, we use the latest commit on the main branch. |
| 6 | + |
| 7 | +BASE_DIR=$(cd "$(dirname "$0")/../.."&& pwd) |
| 8 | +DEPS_DIR="$BASE_DIR/deps" |
| 9 | + |
| 10 | +NEW_UPSTREAM_SHA1=$(git ls-remote "https://github.com/google/googletest.git" HEAD | awk '{print $1}') |
| 11 | +NEW_VERSION=$(echo "$NEW_UPSTREAM_SHA1"| head -c 7) |
| 12 | + |
| 13 | +echo"Comparing $NEW_VERSION with current revision" |
| 14 | + |
| 15 | +git remote add googletest-upstream https://github.com/google/googletest.git |
| 16 | +git fetch googletest-upstream "$NEW_UPSTREAM_SHA1" |
| 17 | +git remote remove googletest-upstream |
| 18 | + |
| 19 | +DIFF_TREE=$( |
| 20 | + git diff HEAD:deps/googletest/LICENSE "$NEW_UPSTREAM_SHA1:LICENSE" |
| 21 | + git diff-tree HEAD:deps/googletest/include "$NEW_UPSTREAM_SHA1:googletest/include" |
| 22 | + git diff-tree HEAD:deps/googletest/src "$NEW_UPSTREAM_SHA1:googletest/src" |
| 23 | +) |
| 24 | + |
| 25 | +if [ -z"$DIFF_TREE" ];then |
| 26 | +echo"Skipped because googletest is on the latest version." |
| 27 | +exit 0 |
| 28 | +fi |
| 29 | + |
| 30 | +# This is a rather arbitrary restriction. This script is assumed to run on |
| 31 | +# Sunday, shortly after midnight UTC. This check thus prevents pulling in the |
| 32 | +# most recent commits if any changes were made on Friday or Saturday (UTC). |
| 33 | +# Because of Google's own "Live at Head" philosophy, new bugs that are likely to |
| 34 | +# affect Node.js tend to be fixed quickly, so we don't want to pull in a commit |
| 35 | +# that was just pushed, and instead rather wait for the next week's update. If |
| 36 | +# no commits have been pushed in the last two days, we assume that the most |
| 37 | +# recent commit is stable enough to be pulled in. |
| 38 | +LAST_CHANGE_DATE=$(git log -1 --format=%ct "$NEW_UPSTREAM_SHA1" -- LICENSE googletest/include googletest/src) |
| 39 | +TWO_DAYS_AGO=$(date -d 'now - 2 days''+%s') |
| 40 | +if [ "$LAST_CHANGE_DATE"-gt"$TWO_DAYS_AGO" ];then |
| 41 | +echo"Skipped because the latest version is too recent." |
| 42 | +exit 0 |
| 43 | +fi |
| 44 | + |
| 45 | +echo"Creating temporary work tree" |
| 46 | + |
| 47 | +WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') |
| 48 | +WORKTREE="$WORKSPACE/googletest" |
| 49 | + |
| 50 | +cleanup () { |
| 51 | + EXIT_CODE=$? |
| 52 | + [ -d"$WORKTREE" ] && git worktree remove -f "$WORKTREE" |
| 53 | + [ -d"$WORKSPACE" ] && rm -rf "$WORKSPACE" |
| 54 | +exit$EXIT_CODE |
| 55 | +} |
| 56 | + |
| 57 | +trap cleanup INT TERM EXIT |
| 58 | + |
| 59 | +git worktree add "$WORKTREE""$NEW_UPSTREAM_SHA1" |
| 60 | + |
| 61 | +echo"Copying LICENSE, include and src to deps/googletest" |
| 62 | +forpin LICENSE googletest/include googletest/src ;do |
| 63 | + rm -rf "$DEPS_DIR/googletest/$(basename "$p")" |
| 64 | + cp -R "$WORKTREE/$p""$DEPS_DIR/googletest/$(basename "$p")" |
| 65 | +done |
| 66 | + |
| 67 | +echo"Updating googletest.gyp" |
| 68 | + |
| 69 | +NEW_GYP=$( |
| 70 | + sed "/'googletest_sources': \[/q""$DEPS_DIR/googletest/googletest.gyp" |
| 71 | +forfin$( (cd deps/googletest/ && find include src -type f \( -iname '*.h' -o -iname '*.cc'\) ) | LANG=C LC_ALL=C sort --stable );do |
| 72 | +if [ "$(basename "$f")"!="gtest_main.cc" ] && |
| 73 | + [ "$(basename "$f")"!="gtest-all.cc" ] && |
| 74 | + [ "$(basename "$f")"!="gtest_prod.h" ] ;then |
| 75 | +echo" '$f'," |
| 76 | +fi |
| 77 | +done |
| 78 | + sed -ne '/\]/,$ p'"$DEPS_DIR/googletest/googletest.gyp" |
| 79 | +) |
| 80 | + |
| 81 | +echo"$NEW_GYP">"$DEPS_DIR/googletest/googletest.gyp" |
| 82 | + |
| 83 | +echo"All done!" |
| 84 | +echo"" |
| 85 | +echo"Please git stage googletest, commit the new version:" |
| 86 | +echo"" |
| 87 | +echo"$ git stage -A deps/googletest" |
| 88 | +echo"$ git commit -m \"deps: update googletest to $NEW_VERSION\"" |
| 89 | +echo"" |
| 90 | + |
| 91 | +# The last line of the script should always print the new version, |
| 92 | +# as we need to add it to $GITHUB_ENV variable. |
| 93 | +echo"NEW_VERSION=$NEW_VERSION" |
0 commit comments