Skip to content

Commit edc9a40

Browse files
gnpricechrisbobbe
authored andcommitted
check: Fix closed-pipe git error that could defeat build_runner suite
Sometimes `tools/check build_runner` would exit with just an error message about "signal 13": Running build_runner... xargs: git: terminated with signal 13; aborting Running drift... Signal 13 is SIGPIPE: it means that `git` command under `xargs` was trying to write to a pipe, presumably its own standard output, and the other end of the pipe had been closed, presumably by the next command having already exited. The reason the other end had been closed is that `grep -q` has an optimization where it exits as soon as it knows its answer. Handy in general, but some programs (like `git grep -l`, apparently) are fragile like this to having their output pipe closed. So, undo that behavior here. The overall effect of this bug was that the tools/check script would report success in this case, but the build_runner suite wouldn't have run, even if there were relevant input files modified. This didn't affect runs using `--all-files`, including in CI. See chat thread: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/build_runner.20unexpected.20output/near/1929739 Reported-by: Chris Bobbe <[email protected]> Fixes: #905
1 parent 48d138f commit edc9a40

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tools/check

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ if_verbose() {
124124
fi
125125
}
126126

127+
# usage: grep_quiet_hungry GREP_ARGUMENTS...
128+
#
129+
# Just like `grep --quiet` aka `grep -q`, except this consumes the
130+
# whole input. Useful when consuming a pipeline from a command that
131+
# isn't robust to having its stdout pipe broken.
132+
grep_quiet_hungry() {
133+
grep --quiet "$@" && cat >/dev/null
134+
}
135+
127136
# usage: files_check [GIT_PATHSPECS...]
128137
#
129138
# True just if $opt_files includes any files matching GIT_PATHSPECS.
@@ -222,7 +231,7 @@ should_run_build_runner() {
222231
# (And at this point we must have a meaningful $files_base_commit.)
223232
if git_changed_files "${files_base_commit}" \
224233
| xargs -r git grep -l '^part .*g\.dart.;$' \
225-
| grep -q .; then
234+
| grep_quiet_hungry .; then
226235
return 0
227236
fi
228237

0 commit comments

Comments
 (0)