This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Expand file tree
/
Copy pathrun.dart
More file actions
165 lines (150 loc) · 4.83 KB
/
run.dart
File metadata and controls
165 lines (150 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ffi' as ffi;
import 'dart:io' as io;
import 'package:engine_build_configs/engine_build_configs.dart';
import 'package:engine_repo_tools/engine_repo_tools.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:process_runner/process_runner.dart';
// This is an example of how to use the APIs of this library to parse and
// execute the build configurations json files under ci/builders.
//
// Usage:
// $ dart bin/run.dart [build config name] [build name]
// For example:
// $ dart bin/run.dart mac_unopt host_debug_unopt
//
// The build config names are the names of the json files under ci/builders
// The build names are the "name" fields of the maps in the list of "builds".
void main(List<String> args) async {
final String? configName;
final String? buildName;
if (args.length >= 2) {
configName = args[0];
buildName = args[1];
} else {
io.stderr.writeln(r'''
Usage:
$ dart bin/run.dart [build config name] [build name]
For example:
$ dart bin/run.dart mac_unopt host_debug_unopt
The build config names are the names of the json files under ci/builders.
The build names are the "name" fields of the maps in the list of "builds".
''');
io.exitCode = 1;
return;
}
// Find the engine repo.
final Engine engine;
try {
engine = Engine.findWithin();
} catch (e) {
io.stderr.writeln(e);
io.exitCode = 1;
return;
}
// Find and parse the engine build configs.
final io.Directory buildConfigsDir = io.Directory(p.join(
engine.flutterDir.path,
'ci',
'builders',
));
final BuildConfigLoader loader = BuildConfigLoader(
buildConfigsDir: buildConfigsDir,
);
// Treat it as an error if no build configs were found. The caller likely
// expected to find some.
final Map<String, BuilderConfig> configs = loader.configs;
if (configs.isEmpty) {
io.stderr.writeln(
'Error: No build configs found under ${buildConfigsDir.path}',
);
io.exitCode = 1;
return;
}
if (loader.errors.isNotEmpty) {
loader.errors.forEach(io.stderr.writeln);
io.exitCode = 1;
}
// Check the parsed build configs for validity.
final BuilderConfig? targetConfig = configs[configName];
if (targetConfig == null) {
io.stderr.writeln('Build config "$configName" not found.');
io.exitCode = 1;
return;
}
final List<String> buildConfigErrors = targetConfig.check(configName);
if (buildConfigErrors.isNotEmpty) {
io.stderr.writeln('Errors in "$configName":');
for (final String error in buildConfigErrors) {
io.stderr.writeln(' $error');
}
io.exitCode = 1;
return;
}
Build? targetBuild;
for (int i = 0; i < targetConfig.builds.length; i++) {
final Build build = targetConfig.builds[i];
if (build.name == buildName) {
targetBuild = build;
}
}
if (targetBuild == null) {
io.stderr.writeln(
'Target build not found. No build called $buildName in $configName',
);
io.exitCode = 1;
return;
}
// If RBE config files aren't in the tree, then disable RBE.
final String rbeConfigPath = p.join(
engine.srcDir.path,
'flutter',
'build',
'rbe',
);
final List<String> extraGnArgs = <String>[
if (!io.Directory(rbeConfigPath).existsSync()) '--no-rbe',
];
final BuildRunner buildRunner = BuildRunner(
platform: const LocalPlatform(),
processRunner: ProcessRunner(),
abi: ffi.Abi.current(),
engineSrcDir: engine.srcDir,
build: targetBuild,
extraGnArgs: extraGnArgs,
runGenerators: false,
runTests: false,
);
void handler(RunnerEvent event) {
switch (event) {
case RunnerStart():
io.stdout.writeln('$event: ${event.command.join(' ')}');
case RunnerProgress(done: true):
io.stdout.writeln(event);
case RunnerProgress(done: false):
{
final int width = io.stdout.terminalColumns;
final String percent = '${event.percent.toStringAsFixed(1)}%';
final String fraction = '(${event.completed}/${event.total})';
final String prefix = '[${event.name}] $percent $fraction ';
final int remainingSpace = width - prefix.length;
final String what;
if (remainingSpace >= event.what.length) {
what = event.what;
} else {
what = event.what.substring(event.what.length - remainingSpace + 1);
}
final String spaces = ' ' * width;
io.stdout.write('$spaces\r'); // Erase the old line.
io.stdout.write('$prefix$what\r'); // Print the new line.
}
default:
io.stdout.writeln(event);
}
}
final bool buildResult = await buildRunner.run(handler);
io.exitCode = buildResult ? 0 : 1;
}