diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index 8bf5836aeb6..49a4e1f0fa1 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -2238,6 +2238,7 @@ const Set kExecutableAllowlist = { 'dev/tools/gen_keycodes/bin/gen_keycodes', 'dev/tools/repackage_gradle_wrapper.sh', + 'dev/tools/bin/engine_hash.sh', 'packages/flutter_tools/bin/macos_assemble.sh', 'packages/flutter_tools/bin/tool_backend.sh', diff --git a/dev/tools/bin/engine_hash.dart b/dev/tools/bin/engine_hash.dart index 5e8692ccead..b8a520fab6f 100644 --- a/dev/tools/bin/engine_hash.dart +++ b/dev/tools/bin/engine_hash.dart @@ -2,6 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ---------------------------------- NOTE ---------------------------------- +// +// We must keep the logic in this file consistent with the logic in the +// `engine_hash.sh` script in the same directory to ensure that Flutter +// continues to work across all platforms! +// +// -------------------------------------------------------------------------- + import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -91,7 +99,7 @@ Future engineHash( [ 'git', 'merge-base', - 'upstream/main', + 'upstream/master', 'HEAD', ], ); diff --git a/dev/tools/bin/engine_hash.sh b/dev/tools/bin/engine_hash.sh new file mode 100755 index 00000000000..c3e71bee6ae --- /dev/null +++ b/dev/tools/bin/engine_hash.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# ---------------------------------- NOTE ---------------------------------- # +# +# We must keep the logic in this file consistent with the logic in the +# `engine_hash.dart` script in the same directory to ensure that Flutter +# continues to work across all platforms! +# +# -------------------------------------------------------------------------- # + +# TODO(codefu): Add a test that this always outputs the same hash as +# `engine_hash.dart` when the repositories are merged + +STRATEGY=head + +HELP=$( + cat <\n +\t\tthead: hash from git HEAD\n +\t\tmergeBase: hash from the merge-base of HEAD and upstream/master\n +EOF +) + +function print_help() { + if [ "${1:-0}" -eq 0 ]; then + echo -e $HELP + exit 0 + else + echo >&2 -e $HELP + exit $1 + fi +} + +while [[ "$#" -gt 0 ]]; do + case $1 in + -s | --strategy) + STRATEGY="$2" + shift # past argument + shift # past value + ;; + -h | --help) + print_help + ;; + -* | --*) + echo >&2 -e "Unknown option $1\n" + print_help 1 + ;; + esac +done + +BASE=HEAD +case $STRATEGY in +head) ;; +mergeBase) + BASE=$(git merge-base upstream/master HEAD) + ;; +*) + echo >&2 -e "Unknown strategy $1\n" + print_help 1 + ;; +esac + +LSTREE=$(git ls-tree -r $BASE engine DEPS) +if [ ${#LSTREE} -eq 0 ]; then + echo >&2 Error calculating engine hash: Not in a monorepo + exit 1 +else + HASH=$(echo "$LSTREE" | sha1sum | head -c 40) + echo $HASH +fi diff --git a/dev/tools/test/engine_hash_test.dart b/dev/tools/test/engine_hash_test.dart index 6578a1b3fdc..fac29b91a2b 100644 --- a/dev/tools/test/engine_hash_test.dart +++ b/dev/tools/test/engine_hash_test.dart @@ -16,7 +16,7 @@ void main() { ( exe: 'git', command: 'merge-base', - rest: ['upstream/main', 'HEAD'], + rest: ['upstream/master', 'HEAD'], exitCode: 0, stdout: 'abcdef1234', stderr: null