Skip to content

Commit 62c6859

Browse files
authored
Delete unused engine_hash.dart script (and test), simplify engine_hash.sh. (#160549)
Closes flutter/flutter#160527. We don't use the Dart script anyway, and the shell script could be simplified to the single use in g3 (cl/688973229).
1 parent 65ff060 commit 62c6859

File tree

5 files changed

+110
-289
lines changed

5 files changed

+110
-289
lines changed

dev/bots/analyze.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,6 +2579,7 @@ const Set<String> kExecutableAllowlist = <String>{
25792579
'dev/tools/repackage_gradle_wrapper.sh',
25802580
'dev/tools/bin/engine_hash.sh',
25812581
'dev/tools/format.sh',
2582+
'dev/tools/test/mock_git.sh',
25822583

25832584
'packages/flutter_tools/bin/macos_assemble.sh',
25842585
'packages/flutter_tools/bin/tool_backend.sh',

dev/tools/bin/engine_hash.dart

Lines changed: 0 additions & 154 deletions
This file was deleted.

dev/tools/bin/engine_hash.sh

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,65 @@
55

66
# ---------------------------------- NOTE ---------------------------------- #
77
#
8-
# We must keep the logic in this file consistent with the logic in the
9-
# `engine_hash.dart` script in the same directory to ensure that Flutter
10-
# continues to work across all platforms!
8+
# This file will appear unused within the monorepo. It is used internally
9+
# (in google3) as part of the roll process, and care should be put before
10+
# making changes.
11+
#
12+
# See cl/688973229.
1113
#
1214
# -------------------------------------------------------------------------- #
1315

14-
# TODO(codefu): Add a test that this always outputs the same hash as
15-
# `engine_hash.dart` when the repositories are merged
16-
17-
STRATEGY=head
16+
# Needed because if it is set, cd may print the path it changed to.
17+
unset CDPATH
1818

19-
HELP=$(
20-
cat <<EOF
21-
Calculate the hash signature for the Flutter Engine\n
22-
\t-s|--strategy\t<head,mergeBase>\n
23-
\t\tthead: hash from git HEAD\n
24-
\t\tmergeBase: hash from the merge-base of HEAD and upstream/master\n
25-
EOF
19+
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
20+
# link at a time, and then cds into the link destination and find out where it
21+
# ends up.
22+
#
23+
# The returned filesystem path must be a format usable by Dart's URI parser,
24+
# since the Dart command line tool treats its argument as a file URI, not a
25+
# filename. For instance, multiple consecutive slashes should be reduced to a
26+
# single slash, since double-slashes indicate a URI "authority", and these are
27+
# supposed to be filenames. There is an edge case where this will return
28+
# multiple slashes: when the input resolves to the root directory. However, if
29+
# that were the case, we wouldn't be running this shell, so we don't do anything
30+
# about it.
31+
#
32+
# The function is enclosed in a subshell to avoid changing the working directory
33+
# of the caller.
34+
function follow_links() (
35+
cd -P "$(dirname -- "$1")"
36+
file="$PWD/$(basename -- "$1")"
37+
while [[ -h "$file" ]]; do
38+
cd -P "$(dirname -- "$file")"
39+
file="$(readlink -- "$file")"
40+
cd -P "$(dirname -- "$file")"
41+
file="$PWD/$(basename -- "$file")"
42+
done
43+
echo "$file"
2644
)
2745

28-
function print_help() {
29-
if [ "${1:-0}" -eq 0 ]; then
30-
echo -e $HELP
31-
exit 0
32-
else
33-
echo >&2 -e $HELP
34-
exit $1
35-
fi
36-
}
37-
38-
while [[ "$#" -gt 0 ]]; do
39-
case $1 in
40-
-s | --strategy)
41-
STRATEGY="$2"
42-
shift # past argument
43-
shift # past value
44-
;;
45-
-h | --help)
46-
print_help
47-
;;
48-
-* | --*)
49-
echo >&2 -e "Unknown option $1\n"
50-
print_help 1
51-
;;
52-
esac
53-
done
46+
PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
47+
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
48+
FLUTTER_ROOT="$(cd "${BIN_DIR}/../../.." ; pwd -P)"
5449

55-
BASE=HEAD
56-
case $STRATEGY in
57-
head) ;;
58-
mergeBase)
59-
BASE=$(git merge-base upstream/master HEAD)
60-
;;
61-
*)
62-
echo >&2 -e "Unknown strategy $1\n"
63-
print_help 1
64-
;;
65-
esac
50+
# Allow using a mock git for testing.
51+
if [ -z "$GIT" ]; then
52+
# By default, use git on PATH.
53+
GIT_BIN="git"
54+
else
55+
# Use the provide GIT executable.
56+
GIT_BIN="$GIT"
57+
fi
6658

67-
LSTREE=$(git ls-tree -r $BASE engine DEPS)
68-
if [ ${#LSTREE} -eq 0 ]; then
69-
echo >&2 Error calculating engine hash: Not in a monorepo
70-
exit 1
59+
# Test for fusion repository
60+
if [ -f "$FLUTTER_ROOT/DEPS" ]; then
61+
ENGINE_VERSION=$($GIT_BIN -C "$FLUTTER_ROOT" merge-base HEAD origin/master)
62+
elif [ -f "$FLUTTER_ROOT/bin/internal/engine.version" ]; then
63+
ENGINE_VERSION=$(cat "$FLUTTER_ROOT/bin/internal/engine.version")
7164
else
72-
HASH=$(echo "$LSTREE" | sha1sum | head -c 40)
73-
echo $HASH
65+
>&2 echo "Not a valid FLUTTER_ROOT: $FLUTTER_ROOT"
66+
exit 1
7467
fi
68+
69+
echo $ENGINE_VERSION

0 commit comments

Comments
 (0)