From 5f76bfb4aff470bf9f786f464c4fc8e0836cfa53 Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Tue, 29 Sep 2020 19:24:21 +0100 Subject: [PATCH] Add the ability to inject a bootstrap script (#66897) --- .gitignore | 2 ++ bin/internal/shared.bat | 6 +++++ bin/internal/shared.sh | 6 +++++ .../command_output_test.dart | 24 +++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/.gitignore b/.gitignore index 62d9ea064c4..e71f2bc5df8 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,8 @@ # Flutter repo-specific /bin/cache/ +/bin/internal/bootstrap.bat +/bin/internal/bootstrap.sh /bin/mingit/ /dev/benchmarks/mega_gallery/ /dev/bots/.recipe_deps diff --git a/bin/internal/shared.bat b/bin/internal/shared.bat index 36b2885a232..d5ddc20c3e9 100644 --- a/bin/internal/shared.bat +++ b/bin/internal/shared.bat @@ -61,6 +61,12 @@ IF NOT EXIST "%cache_dir%" ( GOTO :after_subroutine :subroutine + REM If present, run the bootstrap script first + SET bootstrap_path=%FLUTTER_ROOT%\bin\internal\bootstrap.bat + IF EXIST "%bootstrap_path%" ( + CALL "%bootstrap_path%" + ) + PUSHD "%flutter_root%" FOR /f %%r IN ('git rev-parse HEAD') DO SET revision=%%r POPD diff --git a/bin/internal/shared.sh b/bin/internal/shared.sh index 22efe874433..de2ca9076e2 100644 --- a/bin/internal/shared.sh +++ b/bin/internal/shared.sh @@ -166,6 +166,12 @@ function upgrade_flutter () ( function shared::execute() { export FLUTTER_ROOT="$(cd "${BIN_DIR}/.." ; pwd -P)" + # If present, run the bootstrap script first + BOOTSTRAP_PATH="$FLUTTER_ROOT/bin/internal/bootstrap.sh" + if [ -f "$BOOTSTRAP_PATH" ]; then + source "$BOOTSTRAP_PATH" + fi + FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools" SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot" STAMP_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.stamp" diff --git a/packages/flutter_tools/test/integration.shard/command_output_test.dart b/packages/flutter_tools/test/integration.shard/command_output_test.dart index d3ef28f5eed..b984076ad2c 100644 --- a/packages/flutter_tools/test/integration.shard/command_output_test.dart +++ b/packages/flutter_tools/test/integration.shard/command_output_test.dart @@ -170,4 +170,28 @@ void main() { expect(result.exitCode, 1); expect(result.stderr, contains('Invalid `--debug-uri`: http://127.0.0.1:3333*/')); }); + + testWithoutContext('will load bootstrap script before starting', () async { + final String flutterBin = + fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter'); + + final File bootstrap = fileSystem.file(fileSystem.path.join( + getFlutterRoot(), + 'bin', + 'internal', + platform.isWindows ? 'bootstrap.bat' : 'bootstrap.sh')); + + try { + bootstrap.writeAsStringSync('echo TESTING 1 2 3'); + + final ProcessResult result = await processManager.run([ + flutterBin, + ...getLocalEngineArguments(), + ]); + + expect(result.stdout, contains('TESTING 1 2 3')); + } finally { + bootstrap.deleteSync(); + } + }); }