theos / swift-support

Swift support tools for Theos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift jobserver output doesn't show up when redirecting stdout

kabiroberai opened this issue · comments

When running make clean all, Swift compilation output shows up just fine, but it never shows up when running make clean all | cat for some reason.

In particular, the issue seems to be that Make doesn't correctly redirect the stdout of background processes (eg swift-jobserver &) when the foreground stdout is redirected. This is unexpected because a background process' stdout should be the same as the parent's.

A hacky solution is to change the print here to FileHandle.standardError.write:

print(string, terminator: "")

This makes the output appear on screen, but of course it means it won't be piped to cat. Additionally changing the invocation of make to make clean all 2>&1 | cat does allow cat to receive the output, however it causes the rest of stderr to also be redirected.

Possibly related to the fcntl(): Bad file descriptor error that Make produces when piping its output on BSD-derived systems (including macOS); see https://savannah.gnu.org/bugs/?59585.

Turns out the issue is with print. Using FileHandle.standardOutput.write works fine too.