[bots] Print more on --verbose analyze_sample_code (#90880)
This commit is contained in:
parent
99b210f560
commit
2e663b2472
@ -434,15 +434,32 @@ class SampleChecker {
|
|||||||
// The cached JSON Flutter version information from 'flutter --version --machine'.
|
// The cached JSON Flutter version information from 'flutter --version --machine'.
|
||||||
String? _flutterVersion;
|
String? _flutterVersion;
|
||||||
|
|
||||||
Future<ProcessResult> _runSnippetsScript(List<String> args) async {
|
Future<Process> _runSnippetsScript(List<String> args) async {
|
||||||
final String workingDirectory = path.join(_flutterRoot, 'dev', 'docs');
|
final String workingDirectory = path.join(_flutterRoot, 'dev', 'docs');
|
||||||
if (_flutterVersion == null) {
|
if (_flutterVersion == null) {
|
||||||
// Capture the flutter version information once so that the snippets tool doesn't
|
// Capture the flutter version information once so that the snippets tool doesn't
|
||||||
// have to run it for every snippet.
|
// have to run it for every snippet.
|
||||||
|
if (verbose) {
|
||||||
|
print(<String>[_flutter, '--version', '--machine'].join(' '));
|
||||||
|
}
|
||||||
final ProcessResult versionResult = Process.runSync(_flutter, <String>['--version', '--machine']);
|
final ProcessResult versionResult = Process.runSync(_flutter, <String>['--version', '--machine']);
|
||||||
|
if (verbose) {
|
||||||
|
stdout.write(versionResult.stdout);
|
||||||
|
stderr.write(versionResult.stderr);
|
||||||
|
}
|
||||||
_flutterVersion = versionResult.stdout as String? ?? '';
|
_flutterVersion = versionResult.stdout as String? ?? '';
|
||||||
}
|
}
|
||||||
return Process.run(
|
if (verbose) {
|
||||||
|
print(<String>[
|
||||||
|
Platform.resolvedExecutable,
|
||||||
|
'pub',
|
||||||
|
'global',
|
||||||
|
'run',
|
||||||
|
'snippets',
|
||||||
|
...args,
|
||||||
|
].join(' '));
|
||||||
|
}
|
||||||
|
return Process.start(
|
||||||
Platform.resolvedExecutable,
|
Platform.resolvedExecutable,
|
||||||
<String>[
|
<String>[
|
||||||
'pub',
|
'pub',
|
||||||
@ -467,7 +484,14 @@ class SampleChecker {
|
|||||||
final String sampleId = _createNameFromSource('sample', sample.start.filename, sample.start.line);
|
final String sampleId = _createNameFromSource('sample', sample.start.filename, sample.start.line);
|
||||||
final String inputName = '$sampleId.input';
|
final String inputName = '$sampleId.input';
|
||||||
// Now we have a filename like 'lib.src.material.foo_widget.123.dart' for each snippet.
|
// Now we have a filename like 'lib.src.material.foo_widget.123.dart' for each snippet.
|
||||||
final File inputFile = File(path.join(_tempDirectory.path, inputName))..createSync(recursive: true);
|
final String inputFilePath = path.join(_tempDirectory.path, inputName);
|
||||||
|
if (verbose) {
|
||||||
|
stdout.writeln('Creating $inputFilePath.');
|
||||||
|
}
|
||||||
|
final File inputFile = File(inputFilePath)..createSync(recursive: true);
|
||||||
|
if (verbose) {
|
||||||
|
stdout.writeln('Writing $inputFilePath.');
|
||||||
|
}
|
||||||
inputFile.writeAsStringSync(sample.input.join('\n'));
|
inputFile.writeAsStringSync(sample.input.join('\n'));
|
||||||
final File outputFile = File(path.join(_tempDirectory.path, '$sampleId.dart'));
|
final File outputFile = File(path.join(_tempDirectory.path, '$sampleId.dart'));
|
||||||
final List<String> args = <String>[
|
final List<String> args = <String>[
|
||||||
@ -478,15 +502,22 @@ class SampleChecker {
|
|||||||
'--no-format-output',
|
'--no-format-output',
|
||||||
...sample.args,
|
...sample.args,
|
||||||
];
|
];
|
||||||
if (verbose)
|
if (verbose) {
|
||||||
print('Generating sample for ${sample.start.filename}:${sample.start.line}');
|
print('Generating sample for ${sample.start.filename}:${sample.start.line}');
|
||||||
final ProcessResult process = await _runSnippetsScript(args);
|
}
|
||||||
if (verbose)
|
final Process process = await _runSnippetsScript(args);
|
||||||
stderr.write('${process.stderr}');
|
if (verbose) {
|
||||||
if (process.exitCode != 0) {
|
process.stdout.transform(utf8.decoder).forEach(stdout.write);
|
||||||
|
}
|
||||||
|
process.stderr.transform(utf8.decoder).forEach(stderr.write);
|
||||||
|
final int exitCode = await process.exitCode.timeout(const Duration(seconds: 30), onTimeout: () {
|
||||||
|
stderr.writeln('Snippet script timed out.');
|
||||||
|
return -1;
|
||||||
|
});
|
||||||
|
if (exitCode != 0) {
|
||||||
throw SampleCheckerException(
|
throw SampleCheckerException(
|
||||||
'Unable to create sample for ${sample.start.filename}:${sample.start.line} '
|
'Unable to create sample for ${sample.start.filename}:${sample.start.line} '
|
||||||
'(using input from ${inputFile.path}):\n${process.stdout}\n${process.stderr}',
|
'(using input from ${inputFile.path}).',
|
||||||
file: sample.start.filename,
|
file: sample.start.filename,
|
||||||
line: sample.start.line,
|
line: sample.start.line,
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user