Skip to content

Commit 46f3f30

Browse files
authored
Upgrade builder scripts to Dart 3.10.1 (#187)
1 parent 92a6b78 commit 46f3f30

24 files changed

+1289
-800
lines changed

.github/workflows/builder.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
sdk:
29-
- 3.1.0
29+
- 3.10.1
3030
os:
3131
- ubuntu-latest
3232
steps:

builder/bin/find_base_commit.dart

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@ import 'package:glob/glob.dart';
1515

1616
void main(List<String> args) async {
1717
final parser = ArgParser();
18-
parser.addMultiOption('builder',
19-
abbr: 'b',
20-
help: 'Select the builders matching the glob [option is repeatable]',
21-
splitCommas: false);
22-
parser.addOption('branch',
23-
abbr: 'B',
24-
help: 'Select the builders building this branch',
25-
defaultsTo: 'main');
26-
parser.addOption('count',
27-
abbr: 'c', help: 'List this many commits', defaultsTo: '1');
18+
parser.addMultiOption(
19+
'builder',
20+
abbr: 'b',
21+
help: 'Select the builders matching the glob [option is repeatable]',
22+
splitCommas: false,
23+
);
24+
parser.addOption(
25+
'branch',
26+
abbr: 'B',
27+
help: 'Select the builders building this branch',
28+
defaultsTo: 'main',
29+
);
30+
parser.addOption(
31+
'count',
32+
abbr: 'c',
33+
help: 'List this many commits',
34+
defaultsTo: '1',
35+
);
2836
parser.addFlag('help', help: 'Show the program usage.', negatable: false);
2937

3038
final options = parser.parse(args);
@@ -41,21 +49,24 @@ ${parser.usage}''');
4149

4250
int count = int.parse(options['count']);
4351
final globs = List<Glob>.from(
44-
options['builder'].map((String pattern) => Glob(pattern)));
52+
options['builder'].map((String pattern) => Glob(pattern)),
53+
);
4554

4655
// Download the most recent builds from buildbucket.
4756
const maxBuilds = 1000;
48-
final url = Uri.parse('https://cr-buildbucket.appspot.com'
49-
'/prpc/buildbucket.v2.Builds/SearchBuilds');
57+
final url = Uri.parse(
58+
'https://cr-buildbucket.appspot.com'
59+
'/prpc/buildbucket.v2.Builds/SearchBuilds',
60+
);
5061
const maxRetries = 3;
5162
const timeout = Duration(seconds: 30);
5263
final query = jsonEncode({
5364
'predicate': {
5465
'builder': {'project': 'dart', 'bucket': 'ci.sandbox'},
55-
'status': 'ENDED_MASK'
66+
'status': 'ENDED_MASK',
5667
},
5768
'pageSize': maxBuilds,
58-
'fields': 'builds.*.builder.builder,builds.*.input'
69+
'fields': 'builds.*.builder.builder,builds.*.input',
5970
});
6071
late Map<String, dynamic> searchResult;
6172
for (int i = 1; i <= maxRetries; i++) {
@@ -67,16 +78,21 @@ ${parser.usage}''');
6778
..write(query);
6879
final response = await request.close().timeout(timeout);
6980
if (response.statusCode != 200) {
70-
print('Failed to search for builds: '
71-
'${response.statusCode}:${response.reasonPhrase}');
81+
print(
82+
'Failed to search for builds: '
83+
'${response.statusCode}:${response.reasonPhrase}',
84+
);
7285
exit(1);
7386
}
7487
const prefix = ")]}'";
7588
searchResult = await (response
7689
.cast<List<int>>()
7790
.transform(Utf8Decoder())
78-
.map((event) =>
79-
event.startsWith(prefix) ? event.substring(prefix.length) : event)
91+
.map(
92+
(event) => event.startsWith(prefix)
93+
? event.substring(prefix.length)
94+
: event,
95+
)
8096
.transform(JsonDecoder())
8197
.cast<Map<String, dynamic>>()
8298
.first
@@ -86,7 +102,8 @@ ${parser.usage}''');
86102
} on TimeoutException catch (e) {
87103
final inSeconds = e.duration?.inSeconds;
88104
stderr.writeln(
89-
'Attempt $i of $maxRetries timed out after $inSeconds seconds');
105+
'Attempt $i of $maxRetries timed out after $inSeconds seconds',
106+
);
90107
if (i == maxRetries) {
91108
stderr.writeln('error: Failed to download $url');
92109
exit(1);
@@ -131,8 +148,10 @@ ${parser.usage}''');
131148
continue;
132149
}
133150
final commit = input['id'] as String;
134-
final buildersForCommit =
135-
buildersForCommits.putIfAbsent(commit, () => <String>{});
151+
final buildersForCommit = buildersForCommits.putIfAbsent(
152+
commit,
153+
() => <String>{},
154+
);
136155
buildersForCommit.add(builder);
137156
}
138157

@@ -148,9 +167,10 @@ ${parser.usage}''');
148167
}
149168

150169
// List commits run on the most builders.
151-
for (final commit in buildersForCommits.keys
152-
.where((commit) => buildersForCommits[commit]!.length == maxBots)
153-
.take(count)) {
170+
for (final commit
171+
in buildersForCommits.keys
172+
.where((commit) => buildersForCommits[commit]!.length == maxBots)
173+
.take(count)) {
154174
print(commit);
155175
}
156176
}

builder/bin/upload_results_to_database.dart

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ import 'package:http/http.dart' as http;
1515
late BuildInfo buildInfo;
1616

1717
Future<List<Map<String, dynamic>>> readChangedResults(File resultsFile) async {
18-
final lines = (await resultsFile.readAsLines())
19-
.map((line) => jsonDecode(line)! as Map<String, dynamic>);
18+
final lines = (await resultsFile.readAsLines()).map(
19+
(line) => jsonDecode(line)! as Map<String, dynamic>,
20+
);
2021
if (lines.isEmpty) {
2122
print('Empty input results.json file');
2223
exit(1);
2324
}
24-
buildInfo = BuildInfo.fromResult(
25-
lines.first, {for (final line in lines) line[fConfiguration]});
25+
buildInfo = BuildInfo.fromResult(lines.first, {
26+
for (final line in lines) line[fConfiguration],
27+
});
2628
return lines.where(isChangedResult).toList();
2729
}
2830

29-
File fileOption(options, String name) {
31+
File fileOption(ArgResults options, String name) {
3032
final path = options[name];
3133
if (path == null) {
3234
print("Required option '$name'!");
@@ -40,37 +42,50 @@ File fileOption(options, String name) {
4042
return file;
4143
}
4244

43-
Future<BuildStatus> processResults(options, client, firestore) async {
45+
Future<BuildStatus> processResults(
46+
ArgResults options,
47+
http.Client client,
48+
FirestoreService firestore,
49+
) async {
4450
final inputFile = fileOption(options, 'results');
4551
final results = await readChangedResults(inputFile);
4652
final String? buildbucketID = options['buildbucket_id'];
4753
final String? baseRevision = options['base_revision'];
4854
final commitCache = CommitsCache(firestore, client);
4955
if (buildInfo is TryBuildInfo) {
50-
return Tryjob(buildInfo as TryBuildInfo, buildbucketID!, baseRevision!,
51-
commitCache, firestore, client)
52-
.process(results);
56+
return Tryjob(
57+
buildInfo as TryBuildInfo,
58+
buildbucketID!,
59+
baseRevision!,
60+
commitCache,
61+
firestore,
62+
client,
63+
).process(results);
5364
} else {
5465
return Build(buildInfo, commitCache, firestore).process(results);
5566
}
5667
}
5768

5869
void main(List<String> arguments) async {
59-
final options = (ArgParser()
60-
..addOption('project',
61-
abbr: 'p',
62-
defaultsTo: 'dart-ci-staging',
63-
allowed: ['dart-ci-staging', 'dart-ci'])
64-
..addOption('results', abbr: 'r')
65-
..addOption('buildbucket_id', abbr: 'i')
66-
..addOption('base_revision', abbr: 'b')
67-
..addOption('status_file'))
68-
.parse(arguments);
70+
final options =
71+
(ArgParser()
72+
..addOption(
73+
'project',
74+
abbr: 'p',
75+
defaultsTo: 'dart-ci-staging',
76+
allowed: ['dart-ci-staging', 'dart-ci'],
77+
)
78+
..addOption('results', abbr: 'r')
79+
..addOption('buildbucket_id', abbr: 'i')
80+
..addOption('base_revision', abbr: 'b')
81+
..addOption('status_file'))
82+
.parse(arguments);
6983

7084
final baseClient = http.Client();
7185
final client = await clientViaApplicationDefaultCredentials(
72-
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
73-
baseClient: baseClient);
86+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
87+
baseClient: baseClient,
88+
);
7489
final api = FirestoreApi(client);
7590
final firestore = FirestoreService(api, client, project: options['project']);
7691

0 commit comments

Comments
 (0)