Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions build_runner_core/lib/src/generate/build_definition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,6 @@ class _Loader {
RunnerAssetWriter writer,
) async {
if (conflictingAssets.isEmpty) return;

buildLog.info(
'Deleting ${conflictingAssets.length} declared outputs '
'which already existed on disk.',
);
await Future.wait(conflictingAssets.map((id) => writer.delete(id)));
}
}
Expand Down
7 changes: 5 additions & 2 deletions build_runner_core/lib/src/logging/ansi_buffer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AnsiBuffer {
static const String nbsp = '\u00A0';
static const reset = '\x1B[0m';
static const bold = '\x1B[1m';
static const boldRed = '\x1B[1;31m';
static const _nbspCodeUnit = 0xA0;
static const _spaceCodeUnit = 32;

Expand Down Expand Up @@ -127,7 +128,7 @@ class AnsiBuffer {

/// Removes all ANSI constants from [string], for testing.
static String removeAnsi(String string) =>
string.replaceAll(reset, '').replaceAll(bold, '');
string.replaceAll(reset, '').replaceAll(bold, '').replaceAll(boldRed, '');
}

/// A line for writing to an [AnsiBuffer].
Expand Down Expand Up @@ -167,7 +168,9 @@ class AnsiBufferLine {
}

bool _isAnsi(String item) =>
item == AnsiBuffer.reset || item == AnsiBuffer.bold;
item == AnsiBuffer.reset ||
item == AnsiBuffer.bold ||
item == AnsiBuffer.boldRed;

bool get _showingAnsi =>
buildLog.configuration.forceAnsiConsoleForTesting ??
Expand Down
20 changes: 16 additions & 4 deletions build_runner_core/lib/src/logging/build_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ class BuildLog {
_display.block(render());
_display.flush();
} else {
_display.message(Severity.info, _status.join(''));
_display.message(
Severity.info,
// Removes ANSI codes if necessary.
AnsiBufferLine(_status).toString(),
);
}
}

Expand Down Expand Up @@ -498,14 +502,22 @@ class BuildLog {
if (displayedProgressEntries.isNotEmpty) {
result.writeLine([]);
}

final renderedMessages = _messages.render();
if (renderedMessages.warningLines.isNotEmpty) {
for (final line in renderedMessages.warningLines) {
result.write(line);
}
result.writeEmptyLine();
}

if (_status.isNotEmpty) {
result.writeLine(_status);
}

final renderedMessages = _messages.render();
if (renderedMessages.isNotEmpty) {
if (renderedMessages.errorLines.isNotEmpty) {
result.writeEmptyLine();
for (final line in renderedMessages) {
for (final line in renderedMessages.errorLines) {
result.write(line);
}
}
Expand Down
52 changes: 40 additions & 12 deletions build_runner_core/lib/src/logging/build_log_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class BuildLogMessages {
bool hasMessages({required String? phaseName}) =>
_phaseNamesWithMessages.contains(phaseName);

List<AnsiBufferLine> render() {
final result = <AnsiBufferLine>[];
RenderResult render() {
final result = RenderResult();

final buildRunnerCategories = <MapEntry<_MessageCategory, List<Message>>>[];
for (final entry in _messageByCategory.entries) {
Expand All @@ -72,40 +72,50 @@ class BuildLogMessages {
return result;
}

List<AnsiBufferLine> _renderCategory(
RenderResult _renderCategory(
MapEntry<_MessageCategory, List<Message>> entry,
) {
final result = <AnsiBufferLine>[];
final category = entry.key;
final context = category.context;

final messages = _messageByCategory[category]!;
final failed = messages.any(
(message) => message.severity == Severity.error,
);

final result = <AnsiBufferLine>[];
result.add(
AnsiBufferLine([
'log output for ',
AnsiBuffer.bold,
category.phaseName ?? 'build_runner',
AnsiBuffer.reset,
if (context != null) ...[
' on ',
AnsiBuffer.bold,
failed ? AnsiBuffer.boldRed : AnsiBuffer.bold,
context,
AnsiBuffer.reset,
' ',
],
AnsiBuffer.bold,
category.phaseName ?? 'build_runner',
AnsiBuffer.reset,
]),
);

for (final message in _messageByCategory[category]!) {
for (final message in messages) {
var first = true;
for (final line in message.text.split('\n')) {
result.add(
AnsiBufferLine([
if (message.severity == Severity.error) AnsiBuffer.boldRed,
first ? message.severity.prefix : ' ',
if (message.severity == Severity.error) AnsiBuffer.reset,
line,
], hangingIndent: 2),
);
first = false;
}
}
return result;

return failed
? RenderResult.failed(result)
: RenderResult.succeeded(result);
}
}

Expand Down Expand Up @@ -177,3 +187,21 @@ enum Severity {
Severity.error => 'E ',
};
}

class RenderResult {
final List<AnsiBufferLine> warningLines;
final List<AnsiBufferLine> errorLines;

RenderResult() : warningLines = [], errorLines = [];
RenderResult.failed(List<AnsiBufferLine> lines)
: errorLines = lines,
warningLines = [];
RenderResult.succeeded(List<AnsiBufferLine> lines)
: warningLines = lines,
errorLines = [];

void addAll(RenderResult other) {
warningLines.addAll(other.warningLines);
errorLines.addAll(other.errorLines);
}
}
33 changes: 18 additions & 15 deletions build_runner_core/test/logging/build_log_console_mode_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ columns because it will not fit.'''),
padLinesRight('''
Some setup.

log output for build_runner
build_runner
Some info.
W A warning.
W Another warning.
Expand Down Expand Up @@ -238,15 +238,16 @@ Building, full build.'''),
0s builder1 on 10 inputs; pkg|lib/l0.dart
0s builder2 on 15 inputs

Building, full build.

log output for builder1 on lib/l0.dart
lib/l0.dart builder1
Some info.
Some more info.
log output for builder2 on lib/l1.dart

Building, full build.

lib/l1.dart builder2
W A warning.
E An error.
log output for builder2 on lib/l3.dart
lib/l3.dart builder2
E An error.'''),
);

Expand Down Expand Up @@ -275,17 +276,18 @@ E An error.'''),
0s builder2 on 15 inputs
0s builder1 (lazy): 1 no-op

Building, full build.

log output for builder1 on lib/l0.dart
lib/l0.dart builder1
Some info.
Some more info.
log output for builder2 on lib/l1.dart

Building, full build.

lib/l1.dart builder2
W A warning.
E An error.
log output for builder2 on lib/l3.dart
lib/l3.dart builder2
E An error.
log output for builder1 (lazy) on lib/l3.dart
lib/l3.dart builder1 (lazy)
E An error.'''),
);
});
Expand Down Expand Up @@ -343,11 +345,12 @@ E An error.'''),
0s builder1 on 1 input: 1 output
0s builder2 on 1 input: 1 output

lib/l0.dart builder1
Some info.

Built with build_runner in 0s with warnings; wrote 2 outputs.

log output for builder1 on lib/l0.dart
Some info.
log output for builder2 on lib/l0.dart
lib/l0.dart builder2
W A warning.
E An error.'''),
);
Expand Down
17 changes: 10 additions & 7 deletions build_runner_core/test/logging/build_log_messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,22 @@ void main() {
context: 'file1',
severity: Severity.info,
);
expect(messages.render().map((l) => l.toString()).toList(), [
'log output for phase1 on file1',
'E message1',
'W message3',
'log output for phase2 on file1',
final rendered = messages.render();
expect(rendered.warningLines.map((l) => l.toString()).toList(), [
'file1 phase2',
' message2',
' message6',
'log output for phase1 on file2',
'file2 phase1',
' message4',
'log output for build_runner',
'build_runner',
'W message0',
' message5',
]);
expect(rendered.errorLines.map((l) => l.toString()).toList(), [
'file1 phase1',
'E message1',
'W message3',
]);
});
});
}
Loading