Skip to content

Commit

Permalink
scripts: only overwrite source file if differs
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartolini committed Sep 8, 2024
1 parent e4f36da commit 078a0b8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions scripts/uncrustify/uncrustify-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,27 @@ fi
if [ -n "$2" ]; then
# Do uncrustify.
echo "$2"
${UNCRUSTIFY} -q -c "$1" -f "$2" > "$2".new
TEMPFILE_UNCRUSTIFY=$(mktemp)
${UNCRUSTIFY} -q -c "$1" -f "$2" > "$TEMPFILE_UNCRUSTIFY"

if [ $? -ne 0 ]; then
echo "Failed to format '$2'"
exit 1
else
fix_indentation_char < "$2".new \
TEMPFILE_AWK=$(mktemp)
fix_indentation_char < "$TEMPFILE_UNCRUSTIFY" \
| add_newline_before_namespace_closing_bracket \
| fix_semicolon_indentation \
> "$2"
fi
> "$TEMPFILE_AWK"

rm "$TEMPFILE_UNCRUSTIFY"

rm "$2".new
# Only overwrite if there are differences.
diff "$2" "$TEMPFILE_AWK" 2>/dev/null
if [ $? -ne 0 ]; then
mv "$TEMPFILE_AWK" "$2"
else
rm "$TEMPFILE_AWK"
fi
fi
fi

0 comments on commit 078a0b8

Please sign in to comment.