diff options
author | 2021-11-17 17:07:44 -0800 | |
---|---|---|
committer | 2021-11-18 15:15:45 -0800 | |
commit | 82b6e8483c08def5e0858baf8e412ac49eecf9ac (patch) | |
tree | 267fe97de3c778209c72647e757af3409a639865 | |
parent | f18bedf1c3d063974d7a91d8ece3b7debedca84f (diff) |
A script to update the file contents with the command output.
Used to avoid rerunning Ninja files regeneration if m2rbc conversion
generated the same makefile.
Test: treehugger
Change-Id: I1b0a619f961e6d2c7bf99a48053ecb58147c6db0
-rwxr-xr-x | scripts/update_out | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/scripts/update_out b/scripts/update_out new file mode 100755 index 000000000..d3950cf60 --- /dev/null +++ b/scripts/update_out @@ -0,0 +1,21 @@ +#! /bin/bash +# Run given command application and update the contents of a given file. +# Will not change the file if its contents has not changed. +[[ $# -gt 1 ]] || { echo "Usage: ${0##*/} FILE COMMAND" >&2; exit 1; } +set -u +declare -r outfile="$1" +shift +if [[ ! -f $outfile ]]; then + $@ >$outfile + exit +fi + +declare -r newout=${outfile}.new +$@ >$newout +rc=$? +if cmp -s $newout $outfile; then + rm $newout +else + mv -f $newout $outfile +fi +exit $rc |