Unverified Commit e1ff62a7 authored by J-P Nurmi's avatar J-P Nurmi Committed by GitHub

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

parent ac2f62a9
...@@ -29,6 +29,7 @@ Future<void> main(List<String> arguments) async { ...@@ -29,6 +29,7 @@ Future<void> main(List<String> arguments) async {
final bool trackWidgetCreation = Platform.environment['TRACK_WIDGET_CREATION'] == 'true'; final bool trackWidgetCreation = Platform.environment['TRACK_WIDGET_CREATION'] == 'true';
final bool treeShakeIcons = Platform.environment['TREE_SHAKE_ICONS'] == 'true'; final bool treeShakeIcons = Platform.environment['TREE_SHAKE_ICONS'] == 'true';
final bool verbose = Platform.environment['VERBOSE_SCRIPT_LOGGING'] == 'true'; final bool verbose = Platform.environment['VERBOSE_SCRIPT_LOGGING'] == 'true';
final bool prefixedErrors = Platform.environment['PREFIXED_ERROR_LOGGING'] == 'true';
Directory.current = projectDirectory; Directory.current = projectDirectory;
...@@ -61,6 +62,8 @@ or ...@@ -61,6 +62,8 @@ or
<String>[ <String>[
if (verbose) if (verbose)
'--verbose', '--verbose',
if (prefixedErrors)
'--prefixed-errors',
if (flutterEngine != null) '--local-engine-src-path=$flutterEngine', if (flutterEngine != null) '--local-engine-src-path=$flutterEngine',
if (localEngine != null) '--local-engine=$localEngine', if (localEngine != null) '--local-engine=$localEngine',
'assemble', 'assemble',
......
...@@ -61,6 +61,7 @@ import 'src/web/web_runner.dart'; ...@@ -61,6 +61,7 @@ import 'src/web/web_runner.dart';
Future<void> main(List<String> args) async { Future<void> main(List<String> args) async {
final bool veryVerbose = args.contains('-vv'); final bool veryVerbose = args.contains('-vv');
final bool verbose = args.contains('-v') || args.contains('--verbose') || veryVerbose; final bool verbose = args.contains('-v') || args.contains('--verbose') || veryVerbose;
final bool prefixedErrors = args.contains('--prefixed-errors');
// Support the -? Powershell help idiom. // Support the -? Powershell help idiom.
final int powershellHelpIndex = args.indexOf('-?'); final int powershellHelpIndex = args.indexOf('-?');
if (powershellHelpIndex != -1) { if (powershellHelpIndex != -1) {
...@@ -169,6 +170,7 @@ Future<void> main(List<String> args) async { ...@@ -169,6 +170,7 @@ Future<void> main(List<String> args) async {
daemon: daemon, daemon: daemon,
machine: runMachine, machine: runMachine,
verbose: verbose && !muteCommandLogging, verbose: verbose && !muteCommandLogging,
prefixedErrors: prefixedErrors,
windows: globals.platform.isWindows, windows: globals.platform.isWindows,
); );
} }
...@@ -197,6 +199,7 @@ class LoggerFactory { ...@@ -197,6 +199,7 @@ class LoggerFactory {
/// Create the appropriate logger for the current platform and configuration. /// Create the appropriate logger for the current platform and configuration.
Logger createLogger({ Logger createLogger({
@required bool verbose, @required bool verbose,
@required bool prefixedErrors,
@required bool machine, @required bool machine,
@required bool daemon, @required bool daemon,
@required bool windows, @required bool windows,
...@@ -220,6 +223,9 @@ class LoggerFactory { ...@@ -220,6 +223,9 @@ class LoggerFactory {
if (verbose) { if (verbose) {
logger = VerboseLogger(logger, stopwatchFactory: _stopwatchFactory); logger = VerboseLogger(logger, stopwatchFactory: _stopwatchFactory);
} }
if (prefixedErrors) {
logger = PrefixedErrorLogger(logger);
}
if (daemon) { if (daemon) {
return NotifyingLogger(verbose: verbose, parent: logger); return NotifyingLogger(verbose: verbose, parent: logger);
} }
......
...@@ -676,6 +676,34 @@ class VerboseLogger extends DelegatingLogger { ...@@ -676,6 +676,34 @@ class VerboseLogger extends DelegatingLogger {
void sendEvent(String name, [Map<String, dynamic> args]) { } 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 } enum _LogType { error, status, trace }
typedef SlowWarningCallback = String Function(); typedef SlowWarningCallback = String Function();
......
...@@ -22,7 +22,8 @@ import '../project.dart'; ...@@ -22,7 +22,8 @@ import '../project.dart';
// - <file path>:<line>:<column>: (fatal) error: <error...> // - <file path>:<line>:<column>: (fatal) error: <error...>
// - <file path>:<line>:<column>: warning: <warning...> // - <file path>:<line>:<column>: warning: <warning...>
// - clang: error: <link error...> // - 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. /// Builds the Linux project through the Makefile.
Future<void> buildLinux( Future<void> buildLinux(
...@@ -152,7 +153,9 @@ Future<void> _runBuild(Directory buildDir) async { ...@@ -152,7 +153,9 @@ Future<void> _runBuild(Directory buildDir) async {
], ],
environment: <String, String>{ environment: <String, String>{
if (globals.logger.isVerbose) if (globals.logger.isVerbose)
'VERBOSE_SCRIPT_LOGGING': 'true' 'VERBOSE_SCRIPT_LOGGING': 'true',
if (!globals.logger.isVerbose)
'PREFIXED_ERROR_LOGGING': 'true',
}, },
trace: true, trace: true,
stdoutErrorMatcher: errorMatcher, stdoutErrorMatcher: errorMatcher,
......
...@@ -44,6 +44,10 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -44,6 +44,10 @@ class FlutterCommandRunner extends CommandRunner<void> {
negatable: false, negatable: false,
help: 'Noisy logging, including all shell commands executed.\n' help: 'Noisy logging, including all shell commands executed.\n'
'If used with --help, shows hidden options.'); 'If used with --help, shows hidden options.');
argParser.addFlag('prefixed-errors',
negatable: false,
hide: true,
defaultsTo: false);
argParser.addFlag('quiet', argParser.addFlag('quiet',
negatable: false, negatable: false,
hide: !verboseHelp, hide: !verboseHelp,
......
...@@ -231,6 +231,7 @@ lib/main.dart:4:3: Error: Method not found: 'foo'. ...@@ -231,6 +231,7 @@ lib/main.dart:4:3: Error: Method not found: 'foo'.
main.cc:(.text+0x13): undefined reference to `Foo::bar()' main.cc:(.text+0x13): undefined reference to `Foo::bar()'
clang: error: linker command failed with exit code 1 (use -v to see invocation) clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed. ninja: build stopped: subcommand failed.
ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
'''; ''';
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
...@@ -252,6 +253,7 @@ lib/main.dart:4:3: Error: Method not found: 'foo'. ...@@ -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/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 /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) 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>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
......
...@@ -36,36 +36,49 @@ void main() { ...@@ -36,36 +36,49 @@ void main() {
expect(loggerFactory.createLogger( expect(loggerFactory.createLogger(
verbose: false, verbose: false,
prefixedErrors: false,
machine: false, machine: false,
daemon: false, daemon: false,
windows: false, windows: false,
), isA<StdoutLogger>()); ), isA<StdoutLogger>());
expect(loggerFactory.createLogger( expect(loggerFactory.createLogger(
verbose: false, verbose: false,
prefixedErrors: false,
machine: false, machine: false,
daemon: false, daemon: false,
windows: true, windows: true,
), isA<WindowsStdoutLogger>()); ), isA<WindowsStdoutLogger>());
expect(loggerFactory.createLogger( expect(loggerFactory.createLogger(
verbose: true, verbose: true,
prefixedErrors: false,
machine: false, machine: false,
daemon: false, daemon: false,
windows: true, windows: true,
), isA<VerboseLogger>()); ), isA<VerboseLogger>());
expect(loggerFactory.createLogger( expect(loggerFactory.createLogger(
verbose: true, verbose: true,
prefixedErrors: false,
machine: false, machine: false,
daemon: false, daemon: false,
windows: false, windows: false,
), isA<VerboseLogger>()); ), isA<VerboseLogger>());
expect(loggerFactory.createLogger( expect(loggerFactory.createLogger(
verbose: false, verbose: false,
prefixedErrors: true,
machine: false,
daemon: false,
windows: false,
), isA<PrefixedErrorLogger>());
expect(loggerFactory.createLogger(
verbose: false,
prefixedErrors: false,
machine: false, machine: false,
daemon: true, daemon: true,
windows: false, windows: false,
), isA<NotifyingLogger>()); ), isA<NotifyingLogger>());
expect(loggerFactory.createLogger( expect(loggerFactory.createLogger(
verbose: false, verbose: false,
prefixedErrors: false,
machine: true, machine: true,
daemon: false, daemon: false,
windows: false, windows: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment