forked from firka/flutter
Overhaul update_engine_version.{sh|ps1} to reflect the new computation flow (#164513)
Closes https://github.com/flutter/flutter/issues/164030. Closes https://github.com/flutter/flutter/issues/164315. Towards https://github.com/flutter/flutter/issues/163896. Significantly simplified! We removed: - Conditional checks for monorepo (it's always a monorepo) - Conditional checks for `LUCI_CONTEXT` (LUCI takes care of itself now, see https://github.com/flutter/cocoon/pull/4261) - ... and made the branching logic easier to follow as a result You can see the results first hand in the tests, which are now much simpler. Canonical docs: https://github.com/flutter/flutter/blob/master/docs/tool/Engine-artifacts.md.
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
# 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
|
||||
# Based on the current repository state, writes the following two files to disk:
|
||||
#
|
||||
# bin/cache/engine.stamp <-- SHA of the commit that engine artifacts were built
|
||||
# bin/cache/engine.realm <-- optional; ; whether the SHA is from presubmit builds or staging (bringup: true).
|
||||
|
||||
# ---------------------------------- NOTE ---------------------------------- #
|
||||
#
|
||||
@@ -12,6 +13,12 @@
|
||||
# `update_engine_version.sh` script in the same directory to ensure that Flutter
|
||||
# continues to work across all platforms!
|
||||
#
|
||||
# https://github.com/flutter/flutter/blob/main/docs/tool/Engine-artifacts.md.
|
||||
#
|
||||
# Want to test this script?
|
||||
# $ cd dev/tools
|
||||
# $ dart test test/update_engine_version_test.dart
|
||||
#
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -22,58 +29,47 @@ $flutterRoot = (Get-Item $progName).parent.parent.FullName
|
||||
# Generate a bin/cache directory, which won't initially exist for a fresh checkout.
|
||||
New-Item -Path "$flutterRoot/bin/cache" -ItemType Directory -Force | Out-Null
|
||||
|
||||
# On stable, beta, and release tags, the engine.version is tracked by git - do not override it.
|
||||
$trackedEngine = (git -C "$flutterRoot" ls-files bin/internal/engine.version) | Out-String
|
||||
if ($trackedEngine.length -ne 0) {
|
||||
Copy-Item -Path "$flutterRoot/bin/internal/engine.version" -Destination "$flutterRoot/bin/cache/engine.stamp" -Force
|
||||
return
|
||||
}
|
||||
|
||||
# Allow overriding the intended engine version via FLUTTER_PREBUILT_ENGINE_VERSION.
|
||||
# Check if FLUTTER_PREBUILT_ENGINE_VERSION is set
|
||||
#
|
||||
# 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 is intended for systems where we intentionally want to (ephemerally) use
|
||||
# a specific engine artifacts version (which includes the Flutter engine and
|
||||
# the Dart SDK), such as on CI.
|
||||
#
|
||||
# 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 set, it takes precedence over any other source of engine version.
|
||||
if (![string]::IsNullOrEmpty($env:FLUTTER_PREBUILT_ENGINE_VERSION)) {
|
||||
$engineVersion = $env:FLUTTER_PREBUILT_ENGINE_VERSION
|
||||
}
|
||||
|
||||
# Test for fusion repository
|
||||
if ([string]::IsNullOrEmpty($engineVersion) -and (Test-Path "$flutterRoot/DEPS" -PathType Leaf) -and (Test-Path "$flutterRoot/engine/src/.gn" -PathType Leaf)) {
|
||||
if ($null -eq $Env:LUCI_CONTEXT) {
|
||||
$ErrorActionPreference = "Continue"
|
||||
git -C "$flutterRoot" remote get-url upstream *> $null
|
||||
$exitCode = $?
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($exitCode) {
|
||||
$engineVersion = (git -C "$flutterRoot" merge-base HEAD upstream/master)
|
||||
} else {
|
||||
$engineVersion = (git -C "$flutterRoot" merge-base HEAD origin/master)
|
||||
}
|
||||
}
|
||||
else {
|
||||
$engineVersion = (git -C "$flutterRoot" rev-parse HEAD)
|
||||
}
|
||||
# Check if bin/internal/engine.version exists and is a tracked file in git.
|
||||
#
|
||||
# This is intended for a user-shipped stable or beta release, where the release
|
||||
# has a specific (pinned) engine artifacts version.
|
||||
#
|
||||
# If set, it takes precedence over the git hash.
|
||||
} elseif (git -C "$flutterRoot" ls-files bin/internal/engine.version) {
|
||||
$engineVersion = Get-Content -Path "$flutterRoot/bin/internal/engine.version"
|
||||
|
||||
# Fallback to using git to triangulate which upstream/master (or origin/master)
|
||||
# the current branch is forked from, which would be the last version of the
|
||||
# engine artifacts built from CI.
|
||||
} else {
|
||||
$ErrorActionPreference = "Continue"
|
||||
git -C "$flutterRoot" remote get-url upstream *> $null
|
||||
$exitCode = $?
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($exitCode) {
|
||||
$engineVersion = (git -C "$flutterRoot" merge-base HEAD upstream/master)
|
||||
} else {
|
||||
$engineVersion = (git -C "$flutterRoot" merge-base HEAD origin/master)
|
||||
}
|
||||
}
|
||||
|
||||
# Write the engine version out so downstream tools know what to look for.
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||
[System.IO.File]::WriteAllText("$flutterRoot/bin/cache/engine.stamp", $engineVersion, $utf8NoBom)
|
||||
# TODO(matanlurey): Stop writing to internal/engine.version. https://github.com/flutter/flutter/issues/164315.
|
||||
[System.IO.File]::WriteAllText("$flutterRoot/bin/internal/engine.version", $engineVersion, $utf8NoBom)
|
||||
|
||||
# The realm on CI is passed in.
|
||||
if ($Env:FLUTTER_REALM) {
|
||||
[System.IO.File]::WriteAllText("$flutterRoot/bin/cache/engine.realm", $Env:FLUTTER_REALM, $utf8NoBom)
|
||||
# TODO(matanlurey): Stop writing to internal/engine.realm. https://github.com/flutter/flutter/issues/164315.
|
||||
[System.IO.File]::WriteAllText("$flutterRoot/bin/internal/engine.realm", $Env:FLUTTER_REALM, $utf8NoBom)
|
||||
} else {
|
||||
[System.IO.File]::WriteAllText("$flutterRoot/bin/cache/engine.realm", "", $utf8NoBom)
|
||||
# TODO(matanlurey): Stop writing to internal/engine.realm. https://github.com/flutter/flutter/issues/164315.
|
||||
[System.IO.File]::WriteAllText("$flutterRoot/bin/internal/engine.realm", "", $utf8NoBom)
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
# 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
|
||||
# Based on the current repository state, writes the following two files to disk:
|
||||
#
|
||||
# bin/cache/engine.stamp <-- SHA of the commit that engine artifacts were built
|
||||
# bin/cache/engine.realm <-- optional; whether the SHA is from presubmit builds or staging (bringup: true).
|
||||
|
||||
# ---------------------------------- NOTE ---------------------------------- #
|
||||
#
|
||||
@@ -13,68 +14,63 @@
|
||||
# `update_engine_version.ps1` script in the same directory to ensure that Flutter
|
||||
# continues to work across all platforms!
|
||||
#
|
||||
# https://github.com/flutter/flutter/blob/main/docs/tool/Engine-artifacts.md.
|
||||
#
|
||||
# Want to test this script?
|
||||
# $ cd dev/tools
|
||||
# $ dart test test/update_engine_version_test.dart
|
||||
#
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
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}"
|
||||
fi
|
||||
|
||||
FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")"
|
||||
|
||||
# Generate a bin/cache directory, which won't initially exist for a fresh checkout.
|
||||
mkdir -p "$FLUTTER_ROOT/bin/cache"
|
||||
|
||||
# On stable, beta, and release tags, the engine.version is tracked by git - do not override it.
|
||||
TRACKED_ENGINE="$(git -C "$FLUTTER_ROOT" ls-files bin/internal/engine.version)"
|
||||
if [[ -n "$TRACKED_ENGINE" ]]; then
|
||||
cp $FLUTTER_ROOT/bin/internal/engine.version $FLUTTER_ROOT/bin/cache/engine.stamp
|
||||
exit
|
||||
fi
|
||||
# Check if FLUTTER_PREBUILT_ENGINE_VERSION is set
|
||||
#
|
||||
# This is intended for systems where we intentionally want to (ephemerally) use
|
||||
# a specific engine artifacts version (which includes the Flutter engine and
|
||||
# the Dart SDK), such as on CI.
|
||||
#
|
||||
# If set, it takes precedence over any other source of engine version.
|
||||
if [ -n "${FLUTTER_PREBUILT_ENGINE_VERSION}" ]; then
|
||||
ENGINE_VERSION="${FLUTTER_PREBUILT_ENGINE_VERSION}"
|
||||
|
||||
# Test for fusion repository and no environment variable override.
|
||||
if [ -z "$ENGINE_VERSION" ] && [ -f "$FLUTTER_ROOT/DEPS" ] && [ -f "$FLUTTER_ROOT/engine/src/.gn" ]; then
|
||||
# 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
|
||||
# Check if bin/internal/engine.version exists and is a tracked file in git.
|
||||
#
|
||||
# This is intended for a user-shipped stable or beta release, where the release
|
||||
# has a specific (pinned) engine artifacts version.
|
||||
#
|
||||
# If set, it takes precedence over the git hash.
|
||||
elif [ -n "$(git -C "$FLUTTER_ROOT" ls-files bin/internal/engine.version)" ]; then
|
||||
ENGINE_VERSION="$(cat "$FLUTTER_ROOT/bin/internal/engine.version")"
|
||||
|
||||
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
|
||||
# Fallback to using git to triangulate which upstream/master (or origin/master)
|
||||
# the current branch is forked from, which would be the last version of the
|
||||
# engine artifacts built from CI.
|
||||
else
|
||||
set +e
|
||||
# We fallback to origin/master if upstream is not detected.
|
||||
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" rev-parse HEAD)
|
||||
ENGINE_VERSION=$(git -C "$FLUTTER_ROOT" merge-base HEAD origin/master)
|
||||
fi
|
||||
fi
|
||||
|
||||
# Write the engine version out so downstream tools know what to look for.
|
||||
echo $ENGINE_VERSION > "$FLUTTER_ROOT/bin/cache/engine.stamp"
|
||||
# TODO(matanlurey): Stop writing to internal/engine.version. https://github.com/flutter/flutter/issues/164315.
|
||||
echo $ENGINE_VERSION > "$FLUTTER_ROOT/bin/internal/engine.version"
|
||||
echo $ENGINE_VERSION >"$FLUTTER_ROOT/bin/cache/engine.stamp"
|
||||
|
||||
# The realm on CI is passed in.
|
||||
if [ -n "${FLUTTER_REALM}" ]; then
|
||||
echo $FLUTTER_REALM > "$FLUTTER_ROOT/bin/cache/engine.realm"
|
||||
# TODO(matanlurey): Stop writing to internal/engine.realm. https://github.com/flutter/flutter/issues/164315.
|
||||
echo $FLUTTER_REALM > "$FLUTTER_ROOT/bin/internal/engine.realm"
|
||||
echo $FLUTTER_REALM >"$FLUTTER_ROOT/bin/cache/engine.realm"
|
||||
else
|
||||
echo "" > "$FLUTTER_ROOT/bin/cache/engine.realm"
|
||||
# TODO(matanlurey): Stop writing to internal/engine.realm. https://github.com/flutter/flutter/issues/164315.
|
||||
echo "" > "$FLUTTER_ROOT/bin/internal/engine.realm"
|
||||
echo "" >"$FLUTTER_ROOT/bin/cache/engine.realm"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user