[flutter_tools] propagate build errors from the backend (#72196)

This commit is contained in:
J-P Nurmi 2021-01-14 22:39:05 +01:00 committed by GitHub
parent ac2f62a9c1
commit e1ff62a78c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 2 deletions

View file

@ -29,6 +29,7 @@ Future<void> main(List<String> arguments) async {
final bool trackWidgetCreation = Platform.environment['TRACK_WIDGET_CREATION'] == 'true';
final bool treeShakeIcons = Platform.environment['TREE_SHAKE_ICONS'] == 'true';
final bool verbose = Platform.environment['VERBOSE_SCRIPT_LOGGING'] == 'true';
final bool prefixedErrors = Platform.environment['PREFIXED_ERROR_LOGGING'] == 'true';
Directory.current = projectDirectory;
@ -61,6 +62,8 @@ or
<String>[
if (verbose)
'--verbose',
if (prefixedErrors)
'--prefixed-errors',
if (flutterEngine != null) '--local-engine-src-path=$flutterEngine',
if (localEngine != null) '--local-engine=$localEngine',
'assemble',

View file

@ -61,6 +61,7 @@ import 'src/web/web_runner.dart';
Future<void> main(List<String> args) async {
final bool veryVerbose = args.contains('-vv');
final bool verbose = args.contains('-v') || args.contains('--verbose') || veryVerbose;
final bool prefixedErrors = args.contains('--prefixed-errors');
// Support the -? Powershell help idiom.
final int powershellHelpIndex = args.indexOf('-?');
if (powershellHelpIndex != -1) {
@ -169,6 +170,7 @@ Future<void> main(List<String> args) async {
daemon: daemon,
machine: runMachine,
verbose: verbose && !muteCommandLogging,
prefixedErrors: prefixedErrors,
windows: globals.platform.isWindows,
);
}
@ -197,6 +199,7 @@ class LoggerFactory {
/// Create the appropriate logger for the current platform and configuration.
Logger createLogger({
@required bool verbose,
@required bool prefixedErrors,
@required bool machine,
@required bool daemon,
@required bool windows,
@ -220,6 +223,9 @@ class LoggerFactory {
if (verbose) {
logger = VerboseLogger(logger, stopwatchFactory: _stopwatchFactory);
}
if (prefixedErrors) {
logger = PrefixedErrorLogger(logger);
}
if (daemon) {
return NotifyingLogger(verbose: verbose, parent: logger);
}

View file

@ -676,6 +676,34 @@ class VerboseLogger extends DelegatingLogger {
void sendEvent(String name, [Map<String, dynamic> args]) { }
}
class PrefixedErrorLogger extends DelegatingLogger {
PrefixedErrorLogger(Logger parent) : super(parent);
@override
void printError(
String message, {
StackTrace stackTrace,
bool emphasis,
TerminalColor color,
int indent,
int hangingIndent,
bool wrap,
}) {
if (message?.trim()?.isNotEmpty == true) {
message = 'ERROR: $message';
}
super.printError(
message,
stackTrace: stackTrace,
emphasis: emphasis,
color: color,
indent: indent,
hangingIndent: hangingIndent,
wrap: wrap,
);
}
}
enum _LogType { error, status, trace }
typedef SlowWarningCallback = String Function();

View file

@ -22,7 +22,8 @@ import '../project.dart';
// - <file path>:<line>:<column>: (fatal) error: <error...>
// - <file path>:<line>:<column>: warning: <warning...>
// - clang: error: <link error...>
final RegExp errorMatcher = RegExp(r'(?:.*:\d+:\d+|clang):\s?(fatal\s)?(?:error|warning):\s.*', caseSensitive: false);
// - Error: <tool error...>
final RegExp errorMatcher = RegExp(r'(?:(?:.*:\d+:\d+|clang):\s)?(fatal\s)?(?:error|warning):\s.*', caseSensitive: false);
/// Builds the Linux project through the Makefile.
Future<void> buildLinux(
@ -152,7 +153,9 @@ Future<void> _runBuild(Directory buildDir) async {
],
environment: <String, String>{
if (globals.logger.isVerbose)
'VERBOSE_SCRIPT_LOGGING': 'true'
'VERBOSE_SCRIPT_LOGGING': 'true',
if (!globals.logger.isVerbose)
'PREFIXED_ERROR_LOGGING': 'true',
},
trace: true,
stdoutErrorMatcher: errorMatcher,

View file

@ -44,6 +44,10 @@ class FlutterCommandRunner extends CommandRunner<void> {
negatable: false,
help: 'Noisy logging, including all shell commands executed.\n'
'If used with --help, shows hidden options.');
argParser.addFlag('prefixed-errors',
negatable: false,
hide: true,
defaultsTo: false);
argParser.addFlag('quiet',
negatable: false,
hide: !verboseHelp,

View file

@ -231,6 +231,7 @@ lib/main.dart:4:3: Error: Method not found: 'foo'.
main.cc:(.text+0x13): undefined reference to `Foo::bar()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
''';
processManager = FakeProcessManager.list(<FakeCommand>[
@ -252,6 +253,7 @@ lib/main.dart:4:3: Error: Method not found: 'foo'.
/foo/linux/main.cc:12:7: error: 'bar' is a private member of 'Foo'
/foo/linux/my_application.h:4:10: fatal error: 'gtk/gtk.h' file not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
''');
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,

View file

@ -36,36 +36,49 @@ void main() {
expect(loggerFactory.createLogger(
verbose: false,
prefixedErrors: false,
machine: false,
daemon: false,
windows: false,
), isA<StdoutLogger>());
expect(loggerFactory.createLogger(
verbose: false,
prefixedErrors: false,
machine: false,
daemon: false,
windows: true,
), isA<WindowsStdoutLogger>());
expect(loggerFactory.createLogger(
verbose: true,
prefixedErrors: false,
machine: false,
daemon: false,
windows: true,
), isA<VerboseLogger>());
expect(loggerFactory.createLogger(
verbose: true,
prefixedErrors: false,
machine: false,
daemon: false,
windows: false,
), isA<VerboseLogger>());
expect(loggerFactory.createLogger(
verbose: false,
prefixedErrors: true,
machine: false,
daemon: false,
windows: false,
), isA<PrefixedErrorLogger>());
expect(loggerFactory.createLogger(
verbose: false,
prefixedErrors: false,
machine: false,
daemon: true,
windows: false,
), isA<NotifyingLogger>());
expect(loggerFactory.createLogger(
verbose: false,
prefixedErrors: false,
machine: true,
daemon: false,
windows: false,