Skip to content

Commit 2e663b2

Browse files
authored
[bots] Print more on --verbose analyze_sample_code (flutter#90880)
1 parent 99b210f commit 2e663b2

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

dev/bots/analyze_sample_code.dart

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,32 @@ class SampleChecker {
434434
// The cached JSON Flutter version information from 'flutter --version --machine'.
435435
String? _flutterVersion;
436436

437-
Future<ProcessResult> _runSnippetsScript(List<String> args) async {
437+
Future<Process> _runSnippetsScript(List<String> args) async {
438438
final String workingDirectory = path.join(_flutterRoot, 'dev', 'docs');
439439
if (_flutterVersion == null) {
440440
// Capture the flutter version information once so that the snippets tool doesn't
441441
// have to run it for every snippet.
442+
if (verbose) {
443+
print(<String>[_flutter, '--version', '--machine'].join(' '));
444+
}
442445
final ProcessResult versionResult = Process.runSync(_flutter, <String>['--version', '--machine']);
446+
if (verbose) {
447+
stdout.write(versionResult.stdout);
448+
stderr.write(versionResult.stderr);
449+
}
443450
_flutterVersion = versionResult.stdout as String? ?? '';
444451
}
445-
return Process.run(
452+
if (verbose) {
453+
print(<String>[
454+
Platform.resolvedExecutable,
455+
'pub',
456+
'global',
457+
'run',
458+
'snippets',
459+
...args,
460+
].join(' '));
461+
}
462+
return Process.start(
446463
Platform.resolvedExecutable,
447464
<String>[
448465
'pub',
@@ -467,7 +484,14 @@ class SampleChecker {
467484
final String sampleId = _createNameFromSource('sample', sample.start.filename, sample.start.line);
468485
final String inputName = '$sampleId.input';
469486
// Now we have a filename like 'lib.src.material.foo_widget.123.dart' for each snippet.
470-
final File inputFile = File(path.join(_tempDirectory.path, inputName))..createSync(recursive: true);
487+
final String inputFilePath = path.join(_tempDirectory.path, inputName);
488+
if (verbose) {
489+
stdout.writeln('Creating $inputFilePath.');
490+
}
491+
final File inputFile = File(inputFilePath)..createSync(recursive: true);
492+
if (verbose) {
493+
stdout.writeln('Writing $inputFilePath.');
494+
}
471495
inputFile.writeAsStringSync(sample.input.join('\n'));
472496
final File outputFile = File(path.join(_tempDirectory.path, '$sampleId.dart'));
473497
final List<String> args = <String>[
@@ -478,15 +502,22 @@ class SampleChecker {
478502
'--no-format-output',
479503
...sample.args,
480504
];
481-
if (verbose)
505+
if (verbose) {
482506
print('Generating sample for ${sample.start.filename}:${sample.start.line}');
483-
final ProcessResult process = await _runSnippetsScript(args);
484-
if (verbose)
485-
stderr.write('${process.stderr}');
486-
if (process.exitCode != 0) {
507+
}
508+
final Process process = await _runSnippetsScript(args);
509+
if (verbose) {
510+
process.stdout.transform(utf8.decoder).forEach(stdout.write);
511+
}
512+
process.stderr.transform(utf8.decoder).forEach(stderr.write);
513+
final int exitCode = await process.exitCode.timeout(const Duration(seconds: 30), onTimeout: () {
514+
stderr.writeln('Snippet script timed out.');
515+
return -1;
516+
});
517+
if (exitCode != 0) {
487518
throw SampleCheckerException(
488519
'Unable to create sample for ${sample.start.filename}:${sample.start.line} '
489-
'(using input from ${inputFile.path}):\n${process.stdout}\n${process.stderr}',
520+
'(using input from ${inputFile.path}).',
490521
file: sample.start.filename,
491522
line: sample.start.line,
492523
);

0 commit comments

Comments
 (0)