From 96a2b322fe384fa624cadd468e7d44396e49c2af Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 25 Oct 2016 02:03:25 -0400 Subject: tools/notsd-fixup: Split the makefile pass into a separate executable. This avoids using bash read(1) to loop over the files, as we've already gotten decent speedups from avoiding bash read(1). This means we've got at least two more fork/exec's because of xargs, but it's probably worth it. But that's kind of premature-optimization; the time improvement here is probably just random noise. But, I think this makes the code more maintainable/manageable too, so I'm committing it. --- tools/notsd-fixup | 44 +++++++++++++------------------------------- tools/notsd-fixup--makefiles | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 31 deletions(-) create mode 100755 tools/notsd-fixup--makefiles (limited to 'tools') diff --git a/tools/notsd-fixup b/tools/notsd-fixup index 79b30b7c55..71b3bf4dfa 100755 --- a/tools/notsd-fixup +++ b/tools/notsd-fixup @@ -1,43 +1,25 @@ #!/usr/bin/env bash # Copyright (C) 2015-2016 Luke Shumaker -# We wrap the programs called by xargs 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 `find -exec` because `-exec` won't do much of -# anything useful with the exit status. +main() { + set -e + set -o pipefail + export LC_COLLATE=C + + # We wrap the programs called by xargs 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 `find -exec` because `-exec` won't do much of + # anything useful with the exit status. -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)|" \ - -e '/^nested\.subdirs/d' \ - -e '/^include \$\(topsrcdir\)\/build-aux\/Makefile\.tail\.mk$/d' - echo - find "$(dirname "$filename")" -mindepth 2 -maxdepth 2 -name Makefile -print0 | - xargs -r0 dirname -z -- | - xargs -r0 basename -a -z | - xargs -r0 printf 'nested.subdirs += %s\n' | sort - echo - echo 'include $(topsrcdir)/build-aux/Makefile.tail.mk' - } | cat -s | build-aux/write-ifchanged "$filename" - done -) + # Makefiles + find "$@" -type f -name Makefile -print0 | + xargs -r0 sh -c "$0--makefiles \"\$@\" || exit 255" -- -fixup_includes() ( + # C includes 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 -) - -main() { - set -e - set -o pipefail - export LC_COLLATE=C - fixup_makefiles "$@" - fixup_includes "$@" } main "$@" diff --git a/tools/notsd-fixup--makefiles b/tools/notsd-fixup--makefiles new file mode 100755 index 0000000000..bb18c3be7b --- /dev/null +++ b/tools/notsd-fixup--makefiles @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +doit() { + local filename=$1 + { + <"$filename" sed -r \ + -e "s|(/\.\.)*/config.mk|/$(realpath -ms --relative-to="$(dirname -- "$filename")" config.mk)|" \ + -e '/^nested\.subdirs/d' \ + -e '/^include \$\(topsrcdir\)\/build-aux\/Makefile\.tail\.mk$/d' + echo + find "$(dirname "$filename")" -mindepth 2 -maxdepth 2 -name Makefile -print0 | + xargs -r0 dirname -z -- | + xargs -r0 basename -a -z | + xargs -r0 printf 'nested.subdirs += %s\n' | sort + echo + echo 'include $(topsrcdir)/build-aux/Makefile.tail.mk' + } | cat -s | build-aux/write-ifchanged "$filename" +} + +main() { + set -e + set -o pipefail + local filename + for filename in "$@"; do + >&2 printf ' => fixup %q\n' "$filename" + doit "$filename" + done +} + +main "$@" -- cgit v1.2.3-54-g00ecf