Skip to content

Commit f47eac9

Browse files
authored
changed subprocesses to async from sync (flutter#89668)
* changed subprocess to async from sync
1 parent cd4b47a commit f47eac9

File tree

11 files changed

+335
-302
lines changed

11 files changed

+335
-302
lines changed

dev/conductor/dart_test.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# codesign_integration_test takes longer than the default timeout which is 30s
2+
# since it has to clone both the engine and framework repos, and that test is running
3+
# asynchronously. The async function is being awaited more than 30s which counts as inactivity
4+
# The default timeout needs to be extended to accomodate codesign_integration_test
5+
6+
timeout: 5m

dev/conductor/lib/candidates.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class CandidatesCommand extends Command<void> {
3838
String get description => 'List release candidates.';
3939

4040
@override
41-
void run() {
41+
Future<void> run() async {
4242
final ArgResults results = argResults!;
43-
git.run(
43+
await git.run(
4444
<String>['fetch', results[kRemote] as String],
4545
'Fetch from remote ${results[kRemote]}',
4646
workingDirectory: flutterRoot.path,
@@ -52,10 +52,10 @@ class CandidatesCommand extends Command<void> {
5252
upstreamPath: flutterRoot.path,
5353
);
5454

55-
final Version currentVersion = framework.flutterVersion();
55+
final Version currentVersion = await framework.flutterVersion();
5656
stdio.printStatus('currentVersion = $currentVersion');
5757

58-
final List<String> branches = git.getOutput(
58+
final List<String> branches = (await git.getOutput(
5959
<String>[
6060
'branch',
6161
'--no-color',
@@ -65,7 +65,7 @@ class CandidatesCommand extends Command<void> {
6565
],
6666
'List all remote branches',
6767
workingDirectory: flutterRoot.path,
68-
).split('\n');
68+
)).split('\n');
6969

7070
// Pattern for extracting only the branch name via sub-group 1
7171
final RegExp remotePattern = RegExp('${results[kRemote]}\\/(.*)');

dev/conductor/lib/codesign.dart

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class CodesignCommand extends Command<void> {
3838
platform = checkouts.platform,
3939
stdio = checkouts.stdio,
4040
processManager = checkouts.processManager {
41-
if (framework != null) {
42-
_framework = framework;
43-
}
41+
if (framework != null) {
42+
_framework = framework;
43+
}
4444
argParser.addFlag(
4545
kVerify,
4646
help:
@@ -89,7 +89,7 @@ class CodesignCommand extends Command<void> {
8989
'For codesigning and verifying the signatures of engine binaries.';
9090

9191
@override
92-
void run() {
92+
Future<void> run() async {
9393
if (!platform.isMacOS) {
9494
throw ConductorException(
9595
'Error! Expected operating system "macos", actual operating system is: '
@@ -112,29 +112,30 @@ class CodesignCommand extends Command<void> {
112112
'the desired revision and run that version of the conductor.\n');
113113
revision = argResults![kRevision] as String;
114114
} else {
115-
revision = (processManager.runSync(
115+
revision = ((await processManager.run(
116116
<String>['git', 'rev-parse', 'HEAD'],
117-
workingDirectory: framework.checkoutDirectory.path,
118-
).stdout as String).trim();
117+
workingDirectory: (await framework.checkoutDirectory).path,
118+
)).stdout as String).trim();
119119
assert(revision.isNotEmpty);
120120
}
121121

122-
framework.checkout(revision);
122+
await framework.checkout(revision);
123123

124124
// Ensure artifacts present
125-
framework.runFlutter(<String>['precache', '--android', '--ios', '--macos']);
125+
await framework.runFlutter(<String>['precache', '--android', '--ios', '--macos']);
126126

127-
verifyExist();
127+
await verifyExist();
128128
if (argResults![kSignatures] as bool) {
129-
verifySignatures();
129+
await verifySignatures();
130130
}
131131
}
132132

133133
/// Binaries that are expected to be codesigned and have entitlements.
134134
///
135135
/// This list should be kept in sync with the actual contents of Flutter's
136136
/// cache.
137-
List<String> get binariesWithEntitlements {
137+
Future<List<String>> get binariesWithEntitlements async {
138+
final String frameworkCacheDirectory = await framework.cacheDirectory;
138139
return <String>[
139140
'artifacts/engine/android-arm-profile/darwin-x64/gen_snapshot',
140141
'artifacts/engine/android-arm-release/darwin-x64/gen_snapshot',
@@ -165,15 +166,16 @@ class CodesignCommand extends Command<void> {
165166
'dart-sdk/bin/utils/gen_snapshot',
166167
]
167168
.map((String relativePath) =>
168-
fileSystem.path.join(framework.cacheDirectory, relativePath))
169+
fileSystem.path.join(frameworkCacheDirectory, relativePath))
169170
.toList();
170171
}
171172

172173
/// Binaries that are only expected to be codesigned.
173174
///
174175
/// This list should be kept in sync with the actual contents of Flutter's
175176
/// cache.
176-
List<String> get binariesWithoutEntitlements {
177+
Future<List<String>> get binariesWithoutEntitlements async {
178+
final String frameworkCacheDirectory = await framework.cacheDirectory;
177179
return <String>[
178180
'artifacts/engine/darwin-x64-profile/FlutterMacOS.framework/Versions/A/FlutterMacOS',
179181
'artifacts/engine/darwin-x64-release/FlutterMacOS.framework/Versions/A/FlutterMacOS',
@@ -188,7 +190,7 @@ class CodesignCommand extends Command<void> {
188190
'artifacts/ios-deploy/ios-deploy',
189191
]
190192
.map((String relativePath) =>
191-
fileSystem.path.join(framework.cacheDirectory, relativePath))
193+
fileSystem.path.join(frameworkCacheDirectory, relativePath))
192194
.toList();
193195
}
194196

@@ -200,12 +202,13 @@ class CodesignCommand extends Command<void> {
200202
/// [binariesWithEntitlements] or [binariesWithoutEntitlements] lists should
201203
/// be updated accordingly.
202204
@visibleForTesting
203-
void verifyExist() {
205+
Future<void> verifyExist() async {
204206
final Set<String> foundFiles = <String>{};
205-
for (final String binaryPath in findBinaryPaths(framework.cacheDirectory)) {
206-
if (binariesWithEntitlements.contains(binaryPath)) {
207+
for (final String binaryPath
208+
in await findBinaryPaths(await framework.cacheDirectory)) {
209+
if ((await binariesWithEntitlements).contains(binaryPath)) {
207210
foundFiles.add(binaryPath);
208-
} else if (binariesWithoutEntitlements.contains(binaryPath)) {
211+
} else if ((await binariesWithoutEntitlements).contains(binaryPath)) {
209212
foundFiles.add(binaryPath);
210213
} else {
211214
throw ConductorException(
@@ -214,7 +217,7 @@ class CodesignCommand extends Command<void> {
214217
}
215218

216219
final List<String> allExpectedFiles =
217-
binariesWithEntitlements + binariesWithoutEntitlements;
220+
(await binariesWithEntitlements) + (await binariesWithoutEntitlements);
218221
if (foundFiles.length < allExpectedFiles.length) {
219222
final List<String> unfoundFiles = allExpectedFiles
220223
.where(
@@ -237,19 +240,19 @@ class CodesignCommand extends Command<void> {
237240

238241
/// Verify code signatures and entitlements of all binaries in the cache.
239242
@visibleForTesting
240-
void verifySignatures() {
243+
Future<void> verifySignatures() async {
241244
final List<String> unsignedBinaries = <String>[];
242245
final List<String> wrongEntitlementBinaries = <String>[];
243246
final List<String> unexpectedBinaries = <String>[];
244-
245-
for (final String binaryPath in findBinaryPaths(framework.cacheDirectory)) {
247+
for (final String binaryPath
248+
in await findBinaryPaths(await framework.cacheDirectory)) {
246249
bool verifySignature = false;
247250
bool verifyEntitlements = false;
248-
if (binariesWithEntitlements.contains(binaryPath)) {
251+
if ((await binariesWithEntitlements).contains(binaryPath)) {
249252
verifySignature = true;
250253
verifyEntitlements = true;
251254
}
252-
if (binariesWithoutEntitlements.contains(binaryPath)) {
255+
if ((await binariesWithoutEntitlements).contains(binaryPath)) {
253256
verifySignature = true;
254257
}
255258
if (!verifySignature && !verifyEntitlements) {
@@ -258,7 +261,7 @@ class CodesignCommand extends Command<void> {
258261
continue;
259262
}
260263
stdio.printTrace('Verifying the code signature of $binaryPath');
261-
final io.ProcessResult codeSignResult = processManager.runSync(
264+
final io.ProcessResult codeSignResult = await processManager.run(
262265
<String>[
263266
'codesign',
264267
'-vvv',
@@ -275,7 +278,7 @@ class CodesignCommand extends Command<void> {
275278
}
276279
if (verifyEntitlements) {
277280
stdio.printTrace('Verifying entitlements of $binaryPath');
278-
if (!hasExpectedEntitlements(binaryPath)) {
281+
if (!(await hasExpectedEntitlements(binaryPath))) {
279282
wrongEntitlementBinaries.add(binaryPath);
280283
}
281284
}
@@ -330,11 +333,12 @@ class CodesignCommand extends Command<void> {
330333
List<String>? _allBinaryPaths;
331334

332335
/// Find every binary file in the given [rootDirectory].
333-
List<String> findBinaryPaths(String rootDirectory) {
336+
Future<List<String>> findBinaryPaths(String rootDirectory) async {
334337
if (_allBinaryPaths != null) {
335338
return _allBinaryPaths!;
336339
}
337-
final io.ProcessResult result = processManager.runSync(
340+
final List<String> allBinaryPaths = <String>[];
341+
final io.ProcessResult result = await processManager.run(
338342
<String>[
339343
'find',
340344
rootDirectory,
@@ -346,13 +350,19 @@ class CodesignCommand extends Command<void> {
346350
.split('\n')
347351
.where((String s) => s.isNotEmpty)
348352
.toList();
349-
_allBinaryPaths = allFiles.where(isBinary).toList();
353+
354+
await Future.forEach(allFiles, (String filePath) async {
355+
if (await isBinary(filePath)) {
356+
allBinaryPaths.add(filePath);
357+
}
358+
});
359+
_allBinaryPaths = allBinaryPaths;
350360
return _allBinaryPaths!;
351361
}
352362

353363
/// Check mime-type of file at [filePath] to determine if it is binary.
354-
bool isBinary(String filePath) {
355-
final io.ProcessResult result = processManager.runSync(
364+
Future<bool> isBinary(String filePath) async {
365+
final io.ProcessResult result = await processManager.run(
356366
<String>[
357367
'file',
358368
'--mime-type',
@@ -364,8 +374,8 @@ class CodesignCommand extends Command<void> {
364374
}
365375

366376
/// Check if the binary has the expected entitlements.
367-
bool hasExpectedEntitlements(String binaryPath) {
368-
final io.ProcessResult entitlementResult = processManager.runSync(
377+
Future<bool> hasExpectedEntitlements(String binaryPath) async {
378+
final io.ProcessResult entitlementResult = await processManager.run(
369379
<String>[
370380
'codesign',
371381
'--display',
@@ -386,7 +396,7 @@ class CodesignCommand extends Command<void> {
386396
final String output = entitlementResult.stdout as String;
387397
for (final String entitlement in expectedEntitlements) {
388398
final bool entitlementExpected =
389-
binariesWithEntitlements.contains(binaryPath);
399+
(await binariesWithEntitlements).contains(binaryPath);
390400
if (output.contains(entitlement) != entitlementExpected) {
391401
stdio.printError(
392402
'File "$binaryPath" ${entitlementExpected ? 'does not have expected' : 'has unexpected'} '

dev/conductor/lib/git.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,34 @@ class Git {
1414

1515
final ProcessManager processManager;
1616

17-
String getOutput(
17+
Future<String> getOutput(
1818
List<String> args,
1919
String explanation, {
2020
required String workingDirectory,
2121
bool allowFailures = false,
22-
}) {
23-
final ProcessResult result = _run(args, workingDirectory);
22+
}) async {
23+
final ProcessResult result = await _run(args, workingDirectory);
2424
if (result.exitCode == 0) {
2525
return stdoutToString(result.stdout);
2626
}
2727
_reportFailureAndExit(args, workingDirectory, result, explanation);
2828
}
2929

30-
int run(
30+
Future<int> run(
3131
List<String> args,
3232
String explanation, {
3333
bool allowNonZeroExitCode = false,
3434
required String workingDirectory,
35-
}) {
36-
final ProcessResult result = _run(args, workingDirectory);
35+
}) async {
36+
final ProcessResult result = await _run(args, workingDirectory);
3737
if (result.exitCode != 0 && !allowNonZeroExitCode) {
3838
_reportFailureAndExit(args, workingDirectory, result, explanation);
3939
}
4040
return result.exitCode;
4141
}
4242

43-
ProcessResult _run(List<String> args, String workingDirectory) {
44-
return processManager.runSync(
43+
Future<ProcessResult> _run(List<String> args, String workingDirectory) async {
44+
return processManager.run(
4545
<String>['git', ...args],
4646
workingDirectory: workingDirectory,
4747
environment: <String, String>{'GIT_TRACE': '1'},

0 commit comments

Comments
 (0)