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 {
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',
......
......@@ -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);
}
......
......@@ -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();
......
......@@ -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,
......
......@@ -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,
......
......@@ -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,
......
......@@ -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,
......
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