summaryrefslogtreecommitdiff
path: root/tools/notsd-fixup
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-10-25 01:10:06 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-10-26 21:22:16 -0400
commit52443abf0074a859472a373113a183e0ba518f26 (patch)
tree76d3715b6afe2f308c6cc8c6fe2170cebf13af9e /tools/notsd-fixup
parent9825b6a50a433f15cc0b5baaea2f63eac47fe54e (diff)
tools/notsd-fixup--includes: Allow passing multiple arguments.
This substantially speeds things up because it doesn't have to set up and tear down the Python runtime for every single C file now.
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
)