Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions tools/engine_tool/lib/src/build_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest keeping runGn and maybe making it lib private (_runGn), and then implementing ensureBuildDir() as a public wrapper around it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

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>[],
Expand All @@ -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;
}
7 changes: 6 additions & 1 deletion tools/engine_tool/lib/src/commands/build_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand Down
4 changes: 4 additions & 0 deletions tools/engine_tool/lib/src/commands/query_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tools/engine_tool/lib/src/commands/test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down