flutter/bin/internal/update_engine_version.sh
Matan Lurey a3f0704f25
Formalize update_engine_version.{sh|ps1}. (#162118)
Towards https://github.com/flutter/flutter/issues/162201.

**NOTE**: This renames the environment variable to
`FLUTTER_PREBUILT_ENGINE_VERSION`.

---

We occasionally break ourselves, our users, and the Dart up (or is it
down? side-ways) stream repos (i.e. HHH) when we change how the
undocumented
[`update_engine_version.sh`](https://github.com/flutter/flutter/blob/master/bin/internal/update_engine_version.sh)
script, and it's Windows counterpart
[`update_engine_version.ps1`](https://github.com/flutter/flutter/blob/master/bin/internal/update_engine_version.ps1)
work, but have no way of knowing until N days/weeks later when someone
tells us.

For example,
<https://flutter-review.googlesource.com/c/recipes/+/62400>.

This is my attempt to encode "this is what you can guarantee by calling
this script".

It _still_ will be an internal only API that we might rev at any time,
but at least we:

1. Can tell the Dart team "this is tested and how it works"
2. If we want to change it, the tests will keep us from changing it
without informing folks it changed

These tests should (in theory) cover both Linux/MacOS and Windows.

/cc @a-siva
2025-01-25 19:53:17 +00:00

67 lines
2.6 KiB
Bash
Executable File

#!/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.
# Want to test this script?
# $ cd dev/tools
# $ dart test test/update_engine_version_test.dart
# ---------------------------------- NOTE ---------------------------------- #
#
# Please keep the logic in this file consistent with the logic in the
# `update_engine_version.ps1` script in the same directory to ensure that Flutter
# continues to work across all platforms!
#
# -------------------------------------------------------------------------- #
set -e
# Allow overriding the intended engine version via FLUTTER_PREBUILT_ENGINE_VERSION.
#
# This is for systems, such as Github Actions, where we know ahead of time the
# base-ref we want to use (to download the engine binaries and avoid trying
# to compute one below), or for the Dart HH bot, which wants to try the current
# Flutter framework/engine with a different Dart SDK.
#
# This environment variable is EXPERIMENTAL. If you are not on the Flutter infra
# or Dart infra teams, this code path might be removed at anytime and cease
# functioning. Please file an issue if you have workflow needs.
if [ -n "${FLUTTER_PREBUILT_ENGINE_VERSION}" ]; then
ENGINE_VERSION="${FLUTTER_PREBUILT_ENGINE_VERSION}"
echo "[Unstable] Override: Setting engine SHA to $ENGINE_VERSION" 1>&2
fi
FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")"
# Test for fusion repository and no environment variable override.
if [ -z "$ENGINE_VERSION" ] && [ -f "$FLUTTER_ROOT/DEPS" ] && [ -f "$FLUTTER_ROOT/engine/src/.gn" ]; then
BRANCH=$(git -C "$FLUTTER_ROOT" rev-parse --abbrev-ref HEAD)
# In a fusion repository; the engine.version comes from the git hashes.
if [ -z "${LUCI_CONTEXT}" ]; then
set +e
# Run the git command and capture the exit code
git -C "$FLUTTER_ROOT" remote get-url upstream > /dev/null 2>&1
exit_code=$?
set -e
if [[ $exit_code -eq 0 ]]; then
ENGINE_VERSION=$(git -C "$FLUTTER_ROOT" merge-base HEAD upstream/master)
else
ENGINE_VERSION=$(git -C "$FLUTTER_ROOT" merge-base HEAD origin/master)
fi
else
ENGINE_VERSION=$(git -C "$FLUTTER_ROOT" rev-parse HEAD)
fi
fi
if [[ "$BRANCH" != "stable" && "$BRANCH" != "beta" ]]; then
# Write the engine version out so downstream tools know what to look for.
echo $ENGINE_VERSION > "$FLUTTER_ROOT/bin/internal/engine.version"
# The realm on CI is passed in.
if [ -n "${FLUTTER_REALM}" ]; then
echo $FLUTTER_REALM > "$FLUTTER_ROOT/bin/internal/engine.realm"
fi
fi