et generates {out}/{buildName} if missing on et {build|test|query} (flutter/engine#52866)

Closes https://github.com/flutter/flutter/issues/148442.

This restores functionality that existed prior in https://github.com/flutter/engine/pull/52832:

- Splits `runGn` to `ensureBuildDir`, which is in practice what it does.
This commit is contained in:
Matan Lurey
2024-05-15 21:03:21 -07:00
committed by GitHub
parent d810c59879
commit b0e791fce3
4 changed files with 53 additions and 5 deletions

View File

@@ -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<int> runBuild(
return buildResult ? 0 : 1;
}
/// Given a [Build] object, run only its GN step.
Future<int> runGn(
/// Run a [build]'s GN step if the output directory is missing.
Future<bool> ensureBuildDir(
Environment environment,
Build build, {
List<String> extraGnArgs = const <String>[],
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<bool> _runGn(
Environment environment,
Build build, {
List<String> extraGnArgs = const <String>[],
@@ -203,12 +239,11 @@ Future<int> 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;
}

View File

@@ -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<String> 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<Label> allTargets = <Label>{};
for (final String pattern in argResults!.rest) {
for (final String pattern in commandLineTargets) {
final TargetPattern target = TargetPattern.parse(pattern);
final List<BuildTarget> targets = await gn.desc(
'out/${build.ninja.config}',

View File

@@ -195,6 +195,10 @@ et query targets //flutter/fml/... # List all targets under `//flutter/fml`
return 1;
}
if (!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);

View File

@@ -68,6 +68,10 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
return 1;
}
if (!await ensureBuildDir(environment, build, enableRbe: useRbe)) {
return 1;
}
// Builds only accept labels as arguments, so convert patterns to labels.
final Gn gn = Gn.fromEnvironment(environment);