diff --git a/tools/engine_tool/lib/src/build_utils.dart b/tools/engine_tool/lib/src/build_utils.dart index 0674129dd368c..0f5a537e82f80 100644 --- a/tools/engine_tool/lib/src/build_utils.dart +++ b/tools/engine_tool/lib/src/build_utils.dart @@ -2,7 +2,10 @@ // 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_build_configs/engine_build_configs.dart'; +import 'package:path/path.dart' as p; import 'environment.dart'; import 'label.dart'; @@ -179,8 +182,41 @@ Future runBuild( return buildResult ? 0 : 1; } -/// Given a [Build] object, run only its GN step. -Future runGn( +/// Run a [build]'s GN step if the output directory is missing. +Future ensureBuildDir( + Environment environment, + Build build, { + List extraGnArgs = const [], + required bool enableRbe, +}) async { + // TODO(matanlurey): https://github.com/flutter/flutter/issues/148442. + final io.Directory buildDir = io.Directory( + p.join( + environment.engine.outDir.path, + build.ninja.config, + ), + ); + if (buildDir.existsSync()) { + return true; + } + + final bool built = await _runGn( + environment, + build, + extraGnArgs: extraGnArgs, + enableRbe: enableRbe, + ); + if (built && !buildDir.existsSync()) { + environment.logger.error( + 'The specified build did not produce the expected output directory: ' + '${buildDir.path}', + ); + return false; + } + return built; +} + +Future _runGn( Environment environment, Build build, { List extraGnArgs = const [], @@ -203,12 +239,11 @@ Future runGn( runTests: false, ); - final bool buildResult = await buildRunner.run((RunnerEvent event) { + return buildRunner.run((RunnerEvent event) { switch (event) { case RunnerResult(ok: false): environment.logger.error(event); default: } }); - return buildResult ? 0 : 1; } diff --git a/tools/engine_tool/lib/src/commands/build_command.dart b/tools/engine_tool/lib/src/commands/build_command.dart index 91f024732dc1c..9dc0c42c4ed3a 100644 --- a/tools/engine_tool/lib/src/commands/build_command.dart +++ b/tools/engine_tool/lib/src/commands/build_command.dart @@ -76,11 +76,16 @@ et build //flutter/fml:fml_benchmarks # Build a specific target in `//flutter/f if (useLto) '--lto' else '--no-lto', ]; + final List commandLineTargets = argResults!.rest; + if (commandLineTargets.isNotEmpty && !await ensureBuildDir(environment, build, enableRbe: useRbe)) { + return 1; + } + // Builds only accept labels as arguments, so convert patterns to labels. // TODO(matanlurey): Can be optimized in cases where wildcards are not used. final Gn gn = Gn.fromEnvironment(environment); final Set