Skip to content

Commit ab7ef1d

Browse files
authored
Tweaks to build_daemon for webdev. (#4034)
1 parent 94d20ff commit ab7ef1d

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

build_runner/bin/build_runner.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,20 @@ Future<void> main(List<String> args) async {
8080
exitCode = await commandRunner.runCommand(parsedArgs) ?? 1;
8181
} else {
8282
var experiments = parsedArgs.command!['enable-experiment'] as List<String>?;
83-
if ({'build', 'serve', 'watch', 'test'}.contains(commandName)) {
84-
buildLog.configuration = buildLog.configuration.rebuild((b) {
85-
b.mode = BuildLogMode.build;
86-
});
83+
// Set the buildLog mode before the command starts so the first few log
84+
// messages are displayed correctly.
85+
switch (commandName) {
86+
case 'build':
87+
case 'serve':
88+
case 'watch':
89+
case 'test':
90+
buildLog.configuration = buildLog.configuration.rebuild((b) {
91+
b.mode = BuildLogMode.build;
92+
});
93+
case 'daemon':
94+
buildLog.configuration = buildLog.configuration.rebuild((b) {
95+
b.mode = BuildLogMode.daemon;
96+
});
8797
}
8898
while ((exitCode = await generateAndRun(args, experiments: experiments)) ==
8999
ExitCode.tempFail.code) {}

build_runner/lib/src/entrypoint/daemon.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class DaemonCommand extends WatchCommand {
9999
// These are serialized between special `<log-record>` and `</log-record>`
100100
// tags to make parsing them on stdout easier. They can have multiline
101101
// strings so we can't just serialize the json on a single line.
102+
//
103+
// `BuildRunnerDaemonBuilder` sets its own `onLog` replacing this one.
102104
buildLog.configuration = buildLog.configuration.rebuild((b) {
103105
b.onLog =
104106
(record) => stdout.writeln('''
@@ -111,9 +113,6 @@ $logEndMarker''');
111113
builderApplications,
112114
options,
113115
);
114-
buildLog.configuration = buildLog.configuration.rebuild((b) {
115-
b.onLog = null;
116-
});
117116

118117
// Forward server logs to daemon command STDIO.
119118
var logSub = builder.logs.listen((log) {

build_runner_core/lib/src/environment/create_merged_dir.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ Future<bool> createMergedOutputDirectories(
6868
outputSymlinksOnly || outputLocation.useSymlinks,
6969
outputLocation.hoist,
7070
)) {
71-
buildLog.error(
72-
'Unable to create merged directory for ${outputLocation.path}.',
73-
);
7471
return false;
7572
}
7673
}
@@ -333,9 +330,8 @@ Future<bool> _cleanUpOutputDir(
333330
);
334331
} on NonInteractiveBuildException catch (_) {
335332
buildLog.error(
336-
'Unable to create merged directory at $outputPath.\n'
337-
'Choose a different directory or delete the contents of that '
338-
'directory.',
333+
'Unable to create merged directory $outputPath. Choose a different '
334+
'directory or delete the contents of that directory.',
339335
);
340336
return false;
341337
}

build_runner_core/lib/src/logging/log_display.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,14 @@ class LogDisplay {
101101
_logger.log(severity.toLogLevel, message);
102102

103103
// Display.
104-
if (buildLog.configuration.mode == BuildLogMode.daemon &&
105-
severity == Severity.error) {
106-
stderr.writeln(_render(severity, message));
104+
if (buildLog.configuration.mode == BuildLogMode.daemon) {
105+
// For `build_daemon` just display the messages, severity is determined
106+
// by stderr vs stdout.
107+
if (severity == Severity.error) {
108+
stderr.writeln(message);
109+
} else {
110+
stdout.writeln(message);
111+
}
107112
} else {
108113
stdout.writeln(_render(severity, message));
109114
}

0 commit comments

Comments
 (0)