Skip to content

Commit 54c886b

Browse files
improve trace logging in packages autoroller (#154441)
Add debugging to diagnose: flutter/flutter#154151
1 parent 881f869 commit 54c886b

4 files changed

Lines changed: 52 additions & 34 deletions

File tree

dev/conductor/core/lib/src/git.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Git {
3333
_reportFailureAndExit(args, workingDirectory, result, explanation);
3434
}
3535

36-
Future<int> run(
36+
Future<ProcessResult> run(
3737
List<String> args,
3838
String explanation, {
3939
bool allowNonZeroExitCode = false,
@@ -48,7 +48,7 @@ class Git {
4848
if (result.exitCode != 0 && !allowNonZeroExitCode) {
4949
_reportFailureAndExit(args, workingDirectory, result, explanation);
5050
}
51-
return result.exitCode;
51+
return result;
5252
}
5353

5454
Future<ProcessResult> _run(List<String> args, String workingDirectory) async {

dev/conductor/core/lib/src/packages_autoroller.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ This PR was generated by the automated
140140
}
141141

142142
Future<void> _regenerateGradleLockfiles(Directory repoRoot) async {
143-
await framework.runDart(<String>[
143+
await framework.streamDart(<String>[
144144
'${repoRoot.path}/dev/tools/bin/generate_gradle_lockfiles.dart',
145145
'--no-gradle-generation',
146146
'--no-exclusion',
@@ -149,8 +149,10 @@ This PR was generated by the automated
149149
// If the git checkout is clean, we did not update any lockfiles and we do
150150
// not need an additional commit.
151151
case NoDiff():
152+
stdio.printTrace('No diff after calling generate_gradle_lockfiles.dart');
152153
return;
153154
case OnlyLockfileChanges():
155+
stdio.printTrace('Committing Gradle lockfile changes...');
154156
await framework.commit(
155157
'Re-generate Gradle lockfiles',
156158
addFirst: true,

dev/conductor/core/lib/src/repository.dart

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ abstract class Repository {
380380

381381
/// Determines if one ref is an ancestor for another.
382382
Future<bool> isAncestor(String possibleAncestor, String possibleDescendant) async {
383-
final int exitcode = await git.run(
383+
final io.ProcessResult result = await git.run(
384384
<String>[
385385
'merge-base',
386386
'--is-ancestor',
@@ -391,18 +391,18 @@ abstract class Repository {
391391
allowNonZeroExitCode: true,
392392
workingDirectory: (await checkoutDirectory).path,
393393
);
394-
return exitcode == 0;
394+
return result.exitCode == 0;
395395
}
396396

397397
/// Determines if a given commit has a tag.
398398
Future<bool> isCommitTagged(String commit) async {
399-
final int exitcode = await git.run(
399+
final io.ProcessResult result = await git.run(
400400
<String>['describe', '--exact-match', '--tags', commit],
401401
'verify $commit is already tagged',
402402
allowNonZeroExitCode: true,
403403
workingDirectory: (await checkoutDirectory).path,
404404
);
405-
return exitcode == 0;
405+
return result.exitCode == 0;
406406
}
407407

408408
/// Resets repository HEAD to [ref].
@@ -480,16 +480,27 @@ abstract class Repository {
480480
}
481481
authorArg = '--author="$author"';
482482
}
483-
await git.run(
484-
<String>[
485-
'commit',
486-
'--message',
487-
message,
488-
if (authorArg != null) authorArg,
489-
],
483+
final List<String> commitCmd = <String>[
484+
'commit',
485+
'--message',
486+
message,
487+
if (authorArg != null) authorArg,
488+
];
489+
stdio.printTrace('Executing git $commitCmd...');
490+
final io.ProcessResult commitResult = await git.run(
491+
commitCmd,
490492
'commit changes',
491493
workingDirectory: (await checkoutDirectory).path,
492494
);
495+
final String stdout = commitResult.stdout as String;
496+
if (stdout.isNotEmpty) {
497+
stdio.printTrace(stdout);
498+
}
499+
final String stderr = commitResult.stderr as String;
500+
if (stderr.isNotEmpty) {
501+
stdio.printTrace(stderr);
502+
}
503+
493504
return reverseParse('HEAD');
494505
}
495506

@@ -608,13 +619,6 @@ class FrameworkRepository extends Repository {
608619
]);
609620
}
610621

611-
Future<io.ProcessResult> runDart(List<String> args) async {
612-
return processManager.run(<String>[
613-
fileSystem.path.join((await checkoutDirectory).path, 'bin', 'dart'),
614-
...args,
615-
]);
616-
}
617-
618622
Future<io.ProcessResult> runFlutter(List<String> args) async {
619623
await _ensureToolReady();
620624
return processManager.run(<String>[
@@ -623,16 +627,27 @@ class FrameworkRepository extends Repository {
623627
]);
624628
}
625629

630+
Future<void> streamDart(List<String> args) async => _streamProcess(<String>[
631+
fileSystem.path.join((await checkoutDirectory).path, 'bin', 'dart'),
632+
...args,
633+
]);
634+
626635
Future<io.Process> streamFlutter(
627636
List<String> args, {
628637
void Function(String)? stdoutCallback,
629638
void Function(String)? stderrCallback,
639+
}) async => _streamProcess(<String>[
640+
fileSystem.path.join((await checkoutDirectory).path, 'bin', 'flutter'),
641+
...args,
642+
]);
643+
644+
Future<io.Process> _streamProcess(
645+
List<String> cmd, {
646+
void Function(String)? stdoutCallback,
647+
void Function(String)? stderrCallback,
630648
}) async {
631-
await _ensureToolReady();
632-
final io.Process process = await processManager.start(<String>[
633-
fileSystem.path.join((await checkoutDirectory).path, 'bin', 'flutter'),
634-
...args,
635-
]);
649+
stdio.printTrace('Executing $cmd...');
650+
final io.Process process = await processManager.start(cmd);
636651
process
637652
.stdout
638653
.transform(utf8.decoder)
@@ -643,6 +658,15 @@ class FrameworkRepository extends Repository {
643658
.transform(utf8.decoder)
644659
.transform(const LineSplitter())
645660
.listen(stderrCallback ?? stdio.printError);
661+
final int exitCode = await process.exitCode;
662+
if (exitCode != 0) {
663+
throw io.ProcessException(
664+
cmd.first,
665+
cmd.sublist(1),
666+
'Process failed',
667+
exitCode,
668+
);
669+
}
646670
return process;
647671
}
648672

dev/conductor/core/test/packages_autoroller_test.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ void main() {
293293
'-b',
294294
'packages-autoroller-branch-1',
295295
]),
296-
const FakeCommand(command: <String>[
297-
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
298-
'help',
299-
]),
300296
const FakeCommand(command: <String>[
301297
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
302298
'--verbose',
@@ -389,10 +385,6 @@ void main() {
389385
'-b',
390386
'packages-autoroller-branch-1',
391387
]),
392-
const FakeCommand(command: <String>[
393-
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
394-
'help',
395-
]),
396388
const FakeCommand(command: <String>[
397389
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/flutter',
398390
'--verbose',

0 commit comments

Comments
 (0)