-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Avoid calling GCC for tests when C code is unchanged
- Loading branch information
Showing
2 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
# USAGE: | ||
# ... | write-if-change $FILENAME | ||
# | ||
# Write standard input to a file unless the input is same as current contents. | ||
# That is, timestamp changes only if its contents change. | ||
|
||
set -eu | ||
|
||
FILENAME="$1" | ||
|
||
if test -r "$FILENAME" && test ! -f "$FILENAME" | ||
then | ||
echo "ERROR: $FILENAME is not a regular file." | ||
exit 1 | ||
fi | ||
|
||
if test ! -f "$FILENAME" | ||
then | ||
cat >$FILENAME | ||
exit 0 | ||
fi | ||
|
||
OLD_CONTENTS="$(cat $FILENAME)" | ||
NEW_CONTENTS="$(cat)" | ||
|
||
if test "$OLD_CONTENTS" != "$NEW_CONTENTS" | ||
then | ||
echo "$NEW_CONTENTS" >$FILENAME | ||
fi |