summaryrefslogtreecommitdiff
path: root/tools/notsd-fixup
diff options
context:
space:
mode:
Diffstat (limited to 'tools/notsd-fixup')
-rwxr-xr-xtools/notsd-fixup32
1 files changed, 8 insertions, 24 deletions
diff --git a/tools/notsd-fixup b/tools/notsd-fixup
index 1d4287b259..4bd4b3f94c 100755
--- a/tools/notsd-fixup
+++ b/tools/notsd-fixup
@@ -1,11 +1,9 @@
#!/usr/bin/env bash
# Copyright (C) 2015-2016 Luke Shumaker
-# The reason we do `find`/`while read`-loops instead of `find -exec` commands
-# is that we want errors from the inner loop to bubble up.
-
fixup_makefiles() (
find "$@" -type f -name Makefile | while read -r filename; do
+ >&2 printf ' => fixup %q\n' "$filename"
{
<"$filename" sed -r \
-e "s|(/\.\.)*/config.mk|/$(realpath -ms --relative-to="$(dirname -- "$filename")" config.mk)|" \
@@ -34,27 +32,13 @@ fixup_includes() (
done
fi
- find "$@" \( -name '*.h' -o -name '*.c' -o -name '*.gperf' \) -type f | while read -r filename; do
- false
- # We copy the write-ifchanged logic to here, because we have a
- # higher-than usual chance of the main command failing. In a
- # Makefile we would handle this by setting .DELETE_ON_ERROR:,
- # but we can't do that here, so we have to inter-mingle the
- # logics.
- local outfile="$filename"
- tmpfile="$(dirname "$outfile")/.tmp.${outfile##*/}.tmp"
- local r=0
- "$0"--includes "$filename" > "$tmpfile" || r=$?
- if [[ $r != 0 ]]; then
- rm -f "$tmpfile" || :
- (exit $r)
- fi
- if cmp -s "$tmpfile" "$outfile"; then
- rm -f "$tmpfile" || :
- else
- mv -f "$tmpfile" "$outfile"
- fi
- done
+ # We wrap the $0--includes program with `sh` because xargs only exits
+ # early if the status is 255, but we want to exit early for all
+ # non-zero statuses. We use xargs instead of -exec because -exec won't
+ # do much of anything useful with the exit status.
+ rm -rf -- "$0"--includes.cache
+ find "$@" \( -name '*.h' -o -name '*.c' -o -name '*.gperf' -o -name '*.gperf.m4' \) -type f -print0 |
+ xargs -r0 sh -c "$0--includes \"\$@\" || exit 255" --
rm -rf -- "$0"--includes.cache
)