From 021b2b36275342ad94a1ef44f9748b1e6153b0a3 Mon Sep 17 00:00:00 2001 From: John McDole Date: Fri, 20 Dec 2024 12:17:27 -0800 Subject: [PATCH] Ensure engine.version is up to date in the monorepo (#160668) `update_dart_sdk.(ps1|sh)` is called too late and needs to be called from `shared.(bat|sh)`. Fixes #160640 --- bin/internal/shared.bat | 31 +++++++++++++++++ bin/internal/shared.sh | 3 ++ bin/internal/update_dart_sdk.ps1 | 32 ----------------- bin/internal/update_dart_sdk.sh | 31 ----------------- bin/internal/update_engine_version.ps1 | 48 ++++++++++++++++++++++++++ bin/internal/update_engine_version.sh | 48 ++++++++++++++++++++++++++ dev/bots/analyze.dart | 1 + 7 files changed, 131 insertions(+), 63 deletions(-) create mode 100644 bin/internal/update_engine_version.ps1 create mode 100755 bin/internal/update_engine_version.sh diff --git a/bin/internal/shared.bat b/bin/internal/shared.bat index 504540b230..3fa3a3be23 100644 --- a/bin/internal/shared.bat +++ b/bin/internal/shared.bat @@ -82,6 +82,7 @@ GOTO :after_subroutine REM The following IF conditions are all linked with a logical OR. However, REM there is no OR operator in batch and a GOTO construct is used as replacement. + CALL :do_ensure_engine_version IF NOT EXIST "%engine_stamp%" GOTO do_sdk_update_and_snapshot SET /P dart_required_version=<"%engine_version_path%" SET /P dart_installed_version=<"%engine_stamp%" @@ -101,6 +102,36 @@ GOTO :after_subroutine REM Everything is up-to-date - exit subroutine EXIT /B + :do_ensure_engine_version + REM Detect which PowerShell executable is available on the Host + REM PowerShell version <= 5: PowerShell.exe + REM PowerShell version >= 6: pwsh.exe + WHERE /Q pwsh.exe && ( + SET powershell_executable=pwsh.exe + ) || WHERE /Q PowerShell.exe && ( + SET powershell_executable=PowerShell.exe + ) || ( + ECHO Error: PowerShell executable not found. 1>&2 + ECHO Either pwsh.exe or PowerShell.exe must be in your PATH. 1>&2 + EXIT 1 + ) + SET update_engine_bin=%FLUTTER_ROOT%\bin\internal\update_engine_version.ps1 + REM Escape apostrophes from the executable path + SET "update_engine_bin=%update_engine_bin:'=''%" + REM PowerShell command must have exit code set in order to prevent all non-zero exit codes from being translated + REM into 1. The exit code 2 is used to detect the case where the major version is incorrect and there should be + REM no subsequent retries. + %powershell_executable% -ExecutionPolicy Bypass -NoProfile -Command "Unblock-File -Path '%update_engine_bin%'; & '%update_engine_bin%'; exit $LASTEXITCODE;" + IF "%ERRORLEVEL%" EQU "2" ( + EXIT 1 + ) + IF "%ERRORLEVEL%" NEQ "0" ( + ECHO Error: Unable to determine engine version... 1>&2 + EXIT 1 + ) + REM Do not fall through - return from subroutine + EXIT /B + :do_sdk_update_and_snapshot REM Detect which PowerShell executable is available on the Host REM PowerShell version <= 5: PowerShell.exe diff --git a/bin/internal/shared.sh b/bin/internal/shared.sh index d761436a29..f97a75d778 100644 --- a/bin/internal/shared.sh +++ b/bin/internal/shared.sh @@ -113,6 +113,9 @@ function _wait_for_lock () { function upgrade_flutter () ( mkdir -p "$FLUTTER_ROOT/bin/cache" + # Ensure the engine.version is populated + "$FLUTTER_ROOT/bin/internal/update_engine_version.sh" + local revision="$(cd "$FLUTTER_ROOT"; git rev-parse HEAD)" local compilekey="$revision:$FLUTTER_TOOL_ARGS" diff --git a/bin/internal/update_dart_sdk.ps1 b/bin/internal/update_dart_sdk.ps1 index 57240d4806..cb95257d92 100644 --- a/bin/internal/update_dart_sdk.ps1 +++ b/bin/internal/update_dart_sdk.ps1 @@ -20,38 +20,6 @@ $cachePath = "$flutterRoot\bin\cache" $dartSdkPath = "$cachePath\dart-sdk" $dartSdkLicense = "$cachePath\LICENSE.dart_sdk_archive.md" $engineStamp = "$cachePath\engine-dart-sdk.stamp" -$engineRealm = "" - -# Test for fusion repository -if ((Test-Path "$flutterRoot\DEPS" -PathType Leaf) -and (Test-Path "$flutterRoot\engine\src\.gn" -PathType Leaf)) { - # Calculate the engine hash from tracked git files. - $branch = (git -C "$flutterRoot" rev-parse --abbrev-ref HEAD) - 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) - } - - if (($branch -ne "stable" -and $branch -ne "beta")) { - # 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\internal\engine.version", $engineVersion, $utf8NoBom) - - # The realm on CI is passed in. - if ($Env:FLUTTER_REALM) { - [System.IO.File]::WriteAllText("$flutterRoot\bin\internal\engine.realm", $Env:FLUTTER_REALM, $utf8NoBom) - } - } -} $engineVersion = (Get-Content "$flutterRoot\bin\internal\engine.version") $engineRealm = (Get-Content "$flutterRoot\bin\internal\engine.realm") diff --git a/bin/internal/update_dart_sdk.sh b/bin/internal/update_dart_sdk.sh index cd6eac0f4f..8a186bfbcd 100755 --- a/bin/internal/update_dart_sdk.sh +++ b/bin/internal/update_dart_sdk.sh @@ -19,39 +19,8 @@ FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")" DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk" DART_SDK_PATH_OLD="$DART_SDK_PATH.old" ENGINE_STAMP="$FLUTTER_ROOT/bin/cache/engine-dart-sdk.stamp" -ENGINE_REALM="" OS="$(uname -s)" -# Test for fusion repository -if [ -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 - - 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 -fi ENGINE_VERSION=$(cat "$FLUTTER_ROOT/bin/internal/engine.version") ENGINE_REALM=$(cat "$FLUTTER_ROOT/bin/internal/engine.realm" | tr -d '[:space:]') diff --git a/bin/internal/update_engine_version.ps1 b/bin/internal/update_engine_version.ps1 new file mode 100644 index 0000000000..77bedc81f9 --- /dev/null +++ b/bin/internal/update_engine_version.ps1 @@ -0,0 +1,48 @@ +# 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 ---------------------------------- # +# +# Please keep the logic in this file consistent with the logic in the +# `update_engine_version.sh` script in the same directory to ensure that Flutter +# continues to work across all platforms! +# +# -------------------------------------------------------------------------- # + +$ErrorActionPreference = "Stop" + +$progName = Split-Path -parent $MyInvocation.MyCommand.Definition +$flutterRoot = (Get-Item $progName).parent.parent.FullName + +# Test for fusion repository +if ((Test-Path "$flutterRoot\DEPS" -PathType Leaf) -and (Test-Path "$flutterRoot\engine\src\.gn" -PathType Leaf)) { + # Calculate the engine hash from tracked git files. + $branch = (git -C "$flutterRoot" rev-parse --abbrev-ref HEAD) + 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) + } + + if (($branch -ne "stable" -and $branch -ne "beta")) { + # 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\internal\engine.version", $engineVersion, $utf8NoBom) + + # The realm on CI is passed in. + if ($Env:FLUTTER_REALM) { + [System.IO.File]::WriteAllText("$flutterRoot\bin\internal\engine.realm", $Env:FLUTTER_REALM, $utf8NoBom) + } + } +} \ No newline at end of file diff --git a/bin/internal/update_engine_version.sh b/bin/internal/update_engine_version.sh new file mode 100755 index 0000000000..db05771c28 --- /dev/null +++ b/bin/internal/update_engine_version.sh @@ -0,0 +1,48 @@ +#!/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 ---------------------------------- # +# +# 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 + +FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")" + +# Test for fusion repository +if [ -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 + + 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 +fi diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index a34ac82aff..f6e08e8646 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -2556,6 +2556,7 @@ const Set kExecutableAllowlist = { 'bin/flutter', 'bin/flutter-dev', 'bin/internal/update_dart_sdk.sh', + 'bin/internal/update_engine_version.sh', 'dev/bots/accept_android_sdk_licenses.sh', 'dev/bots/codelabs_build_test.sh',