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
34 changes: 17 additions & 17 deletions tools/engine_tool/lib/src/gn.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:process_runner/process_runner.dart';

import 'environment.dart';
import 'label.dart';
Expand All @@ -19,13 +18,15 @@ interface class Gn {

final Environment _environment;

String get _gnPath => p.join(
_environment.engine.srcDir.path,
'flutter',
'third_party',
'gn',
_environment.platform.isWindows ? 'gn.exe' : 'gn',
);
String get _gnPath {
return p.join(
_environment.engine.srcDir.path,
'flutter',
'third_party',
'gn',
_environment.platform.isWindows ? 'gn.exe' : 'gn',
);
}

/// Returns a list of build targets that match the given [pattern].
///
Expand All @@ -41,15 +42,14 @@ interface class Gn {
String outDir,
TargetPattern pattern,
) async {
final List<String> command = <String>[
final command = [
_gnPath,
'desc',
'--format=json',
outDir,
pattern.toGnPattern(),
];
final ProcessRunnerResult process =
await _environment.processRunner.runProcess(
final process = await _environment.processRunner.runProcess(
command,
workingDirectory: _environment.engine.srcDir,
failOk: true,
Expand All @@ -72,7 +72,7 @@ interface class Gn {
'No targets matched the pattern `${pattern.toGnPattern()}`',
);
}
return <BuildTarget>[];
return [];
}

_environment.logger.fatal(
Expand All @@ -95,13 +95,13 @@ interface class Gn {
return result
.asMap()
.entries
.map((MapEntry<String, Object?> entry) {
final String label = entry.key;
final Object? properties = entry.value;
.map((entry) {
final label = entry.key;
final properties = entry.value;
if (properties is! Map<String, Object?>) {
return null;
}
final BuildTarget? target = BuildTarget._fromJson(
final target = BuildTarget._fromJson(
label,
JsonObject(properties),
);
Expand Down Expand Up @@ -130,7 +130,7 @@ sealed class BuildTarget {
final (
String type,
bool testOnly,
) = json.map((JsonObject json) => (
) = json.map((json) => (
json.string('type'),
json.boolean('testonly'),
));
Expand Down
103 changes: 56 additions & 47 deletions tools/engine_tool/test/build_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,9 @@ import 'src/test_build_configs.dart';
import 'utils.dart';

void main() {
final cannedProcesses = [
CannedProcess(
(command) => command.contains('desc'),
stdout: fixtures.gnDescOutput(),
),
];

test('can find host runnable build', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -61,7 +53,6 @@ void main() {
test('build command invokes gn', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -96,7 +87,6 @@ void main() {
test('build command invokes ninja', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -130,7 +120,6 @@ void main() {
test('build command invokes generator', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -167,7 +156,6 @@ void main() {
test('build command does not invoke tests', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -205,7 +193,6 @@ void main() {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
withRbe: true,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -254,7 +241,6 @@ void main() {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
withRbe: true,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -298,7 +284,6 @@ void main() {
test('build command fails when rbe is enabled but not supported', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
// Intentionally omit withRbe: true.
// That means the //flutter/build/rbe directory will not be created.
);
Expand Down Expand Up @@ -335,7 +320,6 @@ void main() {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
withRbe: true,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -383,7 +367,6 @@ void main() {
() async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -423,9 +406,7 @@ void main() {
});

test('mangleConfigName removes the OS and adds ci/ as needed', () {
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
final testEnv = TestEnvironment.withTestEngine();
addTearDown(testEnv.cleanup);

final env = testEnv.environment;
Expand All @@ -434,9 +415,7 @@ void main() {
});

test('mangleConfigName throws when the input config name is malformed', () {
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
final testEnv = TestEnvironment.withTestEngine();
addTearDown(testEnv.cleanup);

final env = testEnv.environment;
Expand All @@ -447,9 +426,7 @@ void main() {
});

test('demangleConfigName adds the OS and removes ci/ as needed', () {
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
final testEnv = TestEnvironment.withTestEngine();
addTearDown(testEnv.cleanup);

final env = testEnv.environment;
Expand All @@ -467,9 +444,7 @@ void main() {
final configs = <String, BuilderConfig>{
'namespace_test_config': namespaceTestConfigs,
};
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
final testEnv = TestEnvironment.withTestEngine();
addTearDown(testEnv.cleanup);

final runner = ToolCommandRunner(
Expand All @@ -496,9 +471,7 @@ void main() {
final configs = <String, BuilderConfig>{
'namespace_test_config': namespaceTestConfigs,
};
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
final testEnv = TestEnvironment.withTestEngine();
addTearDown(testEnv.cleanup);

final runner = ToolCommandRunner(
Expand All @@ -519,7 +492,20 @@ void main() {
test('build command invokes ninja with the specified target', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
cannedProcesses: [
CannedProcess(
(command) => command.contains('desc'),
stdout: convert.jsonEncode({
'//flutter/fml:fml_arc_unittests': {
'outputs': [
'//out/host_debug/fml_arc_unittests',
],
'testonly': true,
'type': 'executable',
},
}),
),
],
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -571,7 +557,34 @@ void main() {
test('build command invokes ninja with all matched targets', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
cannedProcesses: [
CannedProcess(
(command) => command.contains('desc'),
stdout: convert.jsonEncode({
'//flutter/display_list:display_list_unittests': {
'outputs': [
'//out/host_debug/display_list_unittests',
],
'testonly': true,
'type': 'executable',
},
'//flutter/flow:flow_unittests': {
'outputs': [
'//out/host_debug/flow_unittests',
],
'testonly': true,
'type': 'executable',
},
'//flutter/fml:fml_arc_unittests': {
'outputs': [
'//out/host_debug/fml_arc_unittests',
],
'testonly': true,
'type': 'executable',
},
}),
),
],
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -623,18 +636,17 @@ void main() {
});

test('build command gracefully handles no matched targets', () async {
final cannedProcesses = [
CannedProcess(
(command) => command.contains('desc'),
stdout: fixtures.gnDescOutputEmpty(
gnPattern: 'testing/scenario_app:sceario_app',
),
exitCode: 1,
),
];
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
cannedProcesses: [
CannedProcess(
(command) => command.contains('desc'),
stdout: '''
The input testing/scenario_app:sceario_app matches no targets, configs or files.
''',
exitCode: 1,
),
],
);
addTearDown(testEnv.cleanup);

Expand Down Expand Up @@ -671,7 +683,6 @@ void main() {

test('et help build line length is not too big', () async {
final testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
verbose: true,
);
addTearDown(testEnv.cleanup);
Expand Down Expand Up @@ -699,7 +710,6 @@ void main() {
test('verbose "et help build" contains CI builds', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
verbose: true,
);
addTearDown(testEnv.cleanup);
Expand Down Expand Up @@ -740,7 +750,6 @@ void main() {
test('non-verbose "et help build" does not contain ci builds', () async {
final testEnv = TestEnvironment.withTestEngine(
abi: Abi.macosArm64,
cannedProcesses: cannedProcesses,
);
addTearDown(testEnv.cleanup);

Expand Down
Loading