|
5 | 5 |
|
6 | 6 | # ---------------------------------- NOTE ---------------------------------- # |
7 | 7 | # |
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. |
11 | 13 | # |
12 | 14 | # -------------------------------------------------------------------------- # |
13 | 15 |
|
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 |
18 | 18 |
|
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" |
26 | 44 | ) |
27 | 45 |
|
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)" |
54 | 49 |
|
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 |
66 | 58 |
|
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") |
71 | 64 | 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 |
74 | 67 | fi |
| 68 | + |
| 69 | +echo $ENGINE_VERSION |
0 commit comments