From f55a6391a57db3bb6e77318dac7eeec676c2bdd8 Mon Sep 17 00:00:00 2001 From: Zach Anderson Date: Tue, 20 Feb 2024 08:28:44 -0800 Subject: [PATCH] [et] Adds a .bat entrypoint for Windows --- bin/et.bat | 40 +++++++++++++++++++ tools/engine_tool/README.md | 1 - .../lib/src/commands/command_runner.dart | 2 +- tools/engine_tool/test/entry_point_test.dart | 40 +++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 bin/et.bat create mode 100644 tools/engine_tool/test/entry_point_test.dart diff --git a/bin/et.bat b/bin/et.bat new file mode 100644 index 0000000000000..b1236e284f715 --- /dev/null +++ b/bin/et.bat @@ -0,0 +1,40 @@ +@ECHO off +REM Copyright 2013 The Flutter Authors. All rights reserved. +REM Use of this source code is governed by a BSD-style license that can be +REM found in the LICENSE file. + +REM ---------------------------------- NOTE ---------------------------------- +REM +REM Please keep the logic in this file consistent with the logic in the +REM `et` script in the same directory to ensure that it continues to +REM work across all platforms! +REM +REM -------------------------------------------------------------------------- + +SETLOCAL ENABLEDELAYEDEXPANSION + +FOR %%i IN ("%~dp0..\..") DO SET SRC_DIR=%%~fi + +REM Test if Git is available on the Host +where /q git || ECHO Error: Unable to find git in your PATH. && EXIT /B 1 + +SET repo_dir=%SRC_DIR%\flutter +SET engine_tool_dir=%repo_dir%\tools\engine_tool + +REM Determine which platform we are on and use the right prebuilt Dart SDK +IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" ( + SET dart_sdk_path=%SRC_DIR%\flutter\prebuilts\windows-x64\dart-sdk +) ELSE IF "%PROCESSOR_ARCHITECTURE%"=="ARM64" ( + SET dart_sdk_path=%SRC_DIR%\flutter\prebuilts\windows-arm64\dart-sdk +) ELSE ( + ECHO "Windows x86 (32-bit) is not supported" && EXIT /B 1 +) + +SET dart=%dart_sdk_path%\bin\dart.exe + +cd "%engine_tool_dir%" + +REM Do not use the CALL command in the next line to execute Dart. CALL causes +REM Windows to re-read the line from disk after the CALL command has finished +REM regardless of the ampersand chain. +"%dart%" --disable-dart-dev bin\et.dart %* & exit /B !ERRORLEVEL! diff --git a/tools/engine_tool/README.md b/tools/engine_tool/README.md index 496824acdcb8d..2a36eb9c24101 100644 --- a/tools/engine_tool/README.md +++ b/tools/engine_tool/README.md @@ -23,7 +23,6 @@ There are currently many missing features. Some overall goals are listed in the GitHub issue [here](https://github.com/flutter/flutter/issues/132807). Some desirable new features would do the following: -* Support Windows hosts. * Add a `doctor` command. * Update the engine checkout so that engine developers no longer have to remeber to run `gclient sync -D`. diff --git a/tools/engine_tool/lib/src/commands/command_runner.dart b/tools/engine_tool/lib/src/commands/command_runner.dart index 360e649aef775..48e306d5098ab 100644 --- a/tools/engine_tool/lib/src/commands/command_runner.dart +++ b/tools/engine_tool/lib/src/commands/command_runner.dart @@ -41,7 +41,7 @@ final class ToolCommandRunner extends CommandRunner { @override Future run(Iterable args) async { try{ - return await runCommand(parse(args)) ?? 1; + return await runCommand(parse(args)) ?? 0; } on FormatException catch (e) { environment.logger.error(e); return 1; diff --git a/tools/engine_tool/test/entry_point_test.dart b/tools/engine_tool/test/entry_point_test.dart new file mode 100644 index 0000000000000..052b36106dd82 --- /dev/null +++ b/tools/engine_tool/test/entry_point_test.dart @@ -0,0 +1,40 @@ +// Copyright 2013 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. + +import 'dart:io' as io; + +import 'package:engine_repo_tools/engine_repo_tools.dart'; +import 'package:litetest/litetest.dart'; +import 'package:path/path.dart' as path; +import 'package:platform/platform.dart'; +import 'package:process_runner/process_runner.dart'; + +void main() { + final Engine engine; + try { + engine = Engine.findWithin(); + } catch (e) { + io.stderr.writeln(e); + io.exitCode = 1; + return; + } + + test('The entry points under bin/ work', () async { + const Platform platform = LocalPlatform(); + final ProcessRunner runner = ProcessRunner(); + final String exe = platform.isWindows ? '.bat' : ''; + final String entrypointPath = path.join( + engine.flutterDir.path, 'bin', 'et$exe', + ); + final ProcessRunnerResult processResult = await runner.runProcess( + [entrypointPath, 'help'], + failOk: true, + ); + if (processResult.exitCode != 0) { + io.stdout.writeln(processResult.stdout); + io.stderr.writeln(processResult.stderr); + } + expect(processResult.exitCode, equals(0)); + }); +}