Merge "A script to update the file contents with the command output." am: 71fe2cc783
am: ef9ba0896b
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1895960 Change-Id: I5214c0c6e357886edf29e23c129b5e2b0d5aac4b
This commit is contained in:
21
scripts/update_out
Executable file
21
scripts/update_out
Executable file
@@ -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
|
Reference in New Issue
Block a user