@@ -434,15 +434,32 @@ class SampleChecker {
434
434
// The cached JSON Flutter version information from 'flutter --version --machine'.
435
435
String ? _flutterVersion;
436
436
437
- Future <ProcessResult > _runSnippetsScript (List <String > args) async {
437
+ Future <Process > _runSnippetsScript (List <String > args) async {
438
438
final String workingDirectory = path.join (_flutterRoot, 'dev' , 'docs' );
439
439
if (_flutterVersion == null ) {
440
440
// Capture the flutter version information once so that the snippets tool doesn't
441
441
// have to run it for every snippet.
442
+ if (verbose) {
443
+ print (< String > [_flutter, '--version' , '--machine' ].join (' ' ));
444
+ }
442
445
final ProcessResult versionResult = Process .runSync (_flutter, < String > ['--version' , '--machine' ]);
446
+ if (verbose) {
447
+ stdout.write (versionResult.stdout);
448
+ stderr.write (versionResult.stderr);
449
+ }
443
450
_flutterVersion = versionResult.stdout as String ? ?? '' ;
444
451
}
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 (
446
463
Platform .resolvedExecutable,
447
464
< String > [
448
465
'pub' ,
@@ -467,7 +484,14 @@ class SampleChecker {
467
484
final String sampleId = _createNameFromSource ('sample' , sample.start.filename, sample.start.line);
468
485
final String inputName = '$sampleId .input' ;
469
486
// 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
+ }
471
495
inputFile.writeAsStringSync (sample.input.join ('\n ' ));
472
496
final File outputFile = File (path.join (_tempDirectory.path, '$sampleId .dart' ));
473
497
final List <String > args = < String > [
@@ -478,15 +502,22 @@ class SampleChecker {
478
502
'--no-format-output' ,
479
503
...sample.args,
480
504
];
481
- if (verbose)
505
+ if (verbose) {
482
506
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 ) {
487
518
throw SampleCheckerException (
488
519
'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 }). ' ,
490
521
file: sample.start.filename,
491
522
line: sample.start.line,
492
523
);
0 commit comments