From e1ff62a78c526601d10b68444bf924703e732e18 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 14 Jan 2021 22:39:05 +0100 Subject: [PATCH] [flutter_tools] propagate build errors from the backend (#72196) --- packages/flutter_tools/bin/tool_backend.dart | 3 ++ packages/flutter_tools/lib/executable.dart | 6 ++++ .../flutter_tools/lib/src/base/logger.dart | 28 +++++++++++++++++++ .../lib/src/linux/build_linux.dart | 7 +++-- .../src/runner/flutter_command_runner.dart | 4 +++ .../hermetic/build_linux_test.dart | 2 ++ .../test/general.shard/base/logger_test.dart | 13 +++++++++ 7 files changed, 61 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/bin/tool_backend.dart b/packages/flutter_tools/bin/tool_backend.dart index 678d10a005..b4b67681bf 100644 --- a/packages/flutter_tools/bin/tool_backend.dart +++ b/packages/flutter_tools/bin/tool_backend.dart @@ -29,6 +29,7 @@ Future main(List 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 [ if (verbose) '--verbose', + if (prefixedErrors) + '--prefixed-errors', if (flutterEngine != null) '--local-engine-src-path=$flutterEngine', if (localEngine != null) '--local-engine=$localEngine', 'assemble', diff --git a/packages/flutter_tools/lib/executable.dart b/packages/flutter_tools/lib/executable.dart index 660c494662..626f6def99 100644 --- a/packages/flutter_tools/lib/executable.dart +++ b/packages/flutter_tools/lib/executable.dart @@ -61,6 +61,7 @@ import 'src/web/web_runner.dart'; Future main(List 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 main(List 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); } diff --git a/packages/flutter_tools/lib/src/base/logger.dart b/packages/flutter_tools/lib/src/base/logger.dart index 741bba1f18..038ec4cdcc 100644 --- a/packages/flutter_tools/lib/src/base/logger.dart +++ b/packages/flutter_tools/lib/src/base/logger.dart @@ -676,6 +676,34 @@ class VerboseLogger extends DelegatingLogger { void sendEvent(String name, [Map 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(); diff --git a/packages/flutter_tools/lib/src/linux/build_linux.dart b/packages/flutter_tools/lib/src/linux/build_linux.dart index 3a20b674c7..daf4756ee2 100644 --- a/packages/flutter_tools/lib/src/linux/build_linux.dart +++ b/packages/flutter_tools/lib/src/linux/build_linux.dart @@ -22,7 +22,8 @@ import '../project.dart'; // - ::: (fatal) error: // - ::: warning: // - clang: error: -final RegExp errorMatcher = RegExp(r'(?:.*:\d+:\d+|clang):\s?(fatal\s)?(?:error|warning):\s.*', caseSensitive: false); +// - 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 buildLinux( @@ -152,7 +153,9 @@ Future _runBuild(Directory buildDir) async { ], environment: { if (globals.logger.isVerbose) - 'VERBOSE_SCRIPT_LOGGING': 'true' + 'VERBOSE_SCRIPT_LOGGING': 'true', + if (!globals.logger.isVerbose) + 'PREFIXED_ERROR_LOGGING': 'true', }, trace: true, stdoutErrorMatcher: errorMatcher, diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart index 0fe8117853..3dc7929dd1 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart @@ -44,6 +44,10 @@ class FlutterCommandRunner extends CommandRunner { 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, diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart index 1229ae7f08..cf22b60d10 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart @@ -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([ @@ -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: { FileSystem: () => fileSystem, diff --git a/packages/flutter_tools/test/general.shard/base/logger_test.dart b/packages/flutter_tools/test/general.shard/base/logger_test.dart index 37a0c7c81f..752361d637 100644 --- a/packages/flutter_tools/test/general.shard/base/logger_test.dart +++ b/packages/flutter_tools/test/general.shard/base/logger_test.dart @@ -36,36 +36,49 @@ void main() { expect(loggerFactory.createLogger( verbose: false, + prefixedErrors: false, machine: false, daemon: false, windows: false, ), isA()); expect(loggerFactory.createLogger( verbose: false, + prefixedErrors: false, machine: false, daemon: false, windows: true, ), isA()); expect(loggerFactory.createLogger( verbose: true, + prefixedErrors: false, machine: false, daemon: false, windows: true, ), isA()); expect(loggerFactory.createLogger( verbose: true, + prefixedErrors: false, machine: false, daemon: false, windows: false, ), isA()); expect(loggerFactory.createLogger( verbose: false, + prefixedErrors: true, + machine: false, + daemon: false, + windows: false, + ), isA()); + expect(loggerFactory.createLogger( + verbose: false, + prefixedErrors: false, machine: false, daemon: true, windows: false, ), isA()); expect(loggerFactory.createLogger( verbose: false, + prefixedErrors: false, machine: true, daemon: false, windows: false,