Skip to content

Commit 9e17588

Browse files
authored
et generates {out}/{buildName} if missing on et {build|test|query} (flutter#52866)
Closes flutter#148442. This restores functionality that existed prior in flutter/engine#52832: - Splits `runGn` to `ensureBuildDir`, which is in practice what it does.
1 parent a620531 commit 9e17588

4 files changed

Lines changed: 53 additions & 5 deletions

File tree

tools/engine_tool/lib/src/build_utils.dart

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:io' as io;
6+
57
import 'package:engine_build_configs/engine_build_configs.dart';
8+
import 'package:path/path.dart' as p;
69

710
import 'environment.dart';
811
import 'label.dart';
@@ -179,8 +182,41 @@ Future<int> runBuild(
179182
return buildResult ? 0 : 1;
180183
}
181184

182-
/// Given a [Build] object, run only its GN step.
183-
Future<int> runGn(
185+
/// Run a [build]'s GN step if the output directory is missing.
186+
Future<bool> ensureBuildDir(
187+
Environment environment,
188+
Build build, {
189+
List<String> extraGnArgs = const <String>[],
190+
required bool enableRbe,
191+
}) async {
192+
// TODO(matanlurey): https://github.com/flutter/flutter/issues/148442.
193+
final io.Directory buildDir = io.Directory(
194+
p.join(
195+
environment.engine.outDir.path,
196+
build.ninja.config,
197+
),
198+
);
199+
if (buildDir.existsSync()) {
200+
return true;
201+
}
202+
203+
final bool built = await _runGn(
204+
environment,
205+
build,
206+
extraGnArgs: extraGnArgs,
207+
enableRbe: enableRbe,
208+
);
209+
if (built && !buildDir.existsSync()) {
210+
environment.logger.error(
211+
'The specified build did not produce the expected output directory: '
212+
'${buildDir.path}',
213+
);
214+
return false;
215+
}
216+
return built;
217+
}
218+
219+
Future<bool> _runGn(
184220
Environment environment,
185221
Build build, {
186222
List<String> extraGnArgs = const <String>[],
@@ -203,12 +239,11 @@ Future<int> runGn(
203239
runTests: false,
204240
);
205241

206-
final bool buildResult = await buildRunner.run((RunnerEvent event) {
242+
return buildRunner.run((RunnerEvent event) {
207243
switch (event) {
208244
case RunnerResult(ok: false):
209245
environment.logger.error(event);
210246
default:
211247
}
212248
});
213-
return buildResult ? 0 : 1;
214249
}

tools/engine_tool/lib/src/commands/build_command.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ et build //flutter/fml:fml_benchmarks # Build a specific target in `//flutter/f
7676
if (useLto) '--lto' else '--no-lto',
7777
];
7878

79+
final List<String> commandLineTargets = argResults!.rest;
80+
if (commandLineTargets.isNotEmpty && !await ensureBuildDir(environment, build, enableRbe: useRbe)) {
81+
return 1;
82+
}
83+
7984
// Builds only accept labels as arguments, so convert patterns to labels.
8085
// TODO(matanlurey): Can be optimized in cases where wildcards are not used.
8186
final Gn gn = Gn.fromEnvironment(environment);
8287
final Set<Label> allTargets = <Label>{};
83-
for (final String pattern in argResults!.rest) {
88+
for (final String pattern in commandLineTargets) {
8489
final TargetPattern target = TargetPattern.parse(pattern);
8590
final List<BuildTarget> targets = await gn.desc(
8691
'out/${build.ninja.config}',

tools/engine_tool/lib/src/commands/query_command.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ et query targets //flutter/fml/... # List all targets under `//flutter/fml`
195195
return 1;
196196
}
197197

198+
if (!await ensureBuildDir(environment, build, enableRbe: useRbe)) {
199+
return 1;
200+
}
201+
198202
// Builds only accept labels as arguments, so convert patterns to labels.
199203
// TODO(matanlurey): Can be optimized in cases where wildcards are not used.
200204
final Gn gn = Gn.fromEnvironment(environment);

tools/engine_tool/lib/src/commands/test_command.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
6868
return 1;
6969
}
7070

71+
if (!await ensureBuildDir(environment, build, enableRbe: useRbe)) {
72+
return 1;
73+
}
74+
7175
// Builds only accept labels as arguments, so convert patterns to labels.
7276
final Gn gn = Gn.fromEnvironment(environment);
7377

0 commit comments

Comments
 (0)