82b6e8483c
Used to avoid rerunning Ninja files regeneration if m2rbc conversion generated the same makefile. Test: treehugger Change-Id: I1b0a619f961e6d2c7bf99a48053ecb58147c6db0
21 lines
444 B
Bash
Executable file
21 lines
444 B
Bash
Executable file
#! /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
|