mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 01:59:31 +00:00
Meta: Provide a way to only update a file if the output changes
This is only useful for build commands that update their destination in all cases and thus sometimes confuse cmake into rebuilding everything needlessly.
This commit is contained in:
parent
98e18d7339
commit
aaa13e5739
Notes:
sideshowbarker
2024-07-19 04:20:12 +09:00
Author: https://github.com/BenWiederhake
Commit: aaa13e5739
Pull-request: https://github.com/SerenityOS/serenity/pull/2970
Reviewed-by: https://github.com/awesomekling
1 changed files with 28 additions and 0 deletions
28
Meta/write-only-on-difference.sh
Executable file
28
Meta/write-only-on-difference.sh
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ "$#" -lt "2" ]; then
|
||||||
|
echo "USAGE: $0 <file> <cmd...>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
DST_FILE="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
# Just in case:
|
||||||
|
mkdir -p -- "$(dirname -- "${DST_FILE}")"
|
||||||
|
|
||||||
|
cleanup()
|
||||||
|
{
|
||||||
|
rm -f -- "${DST_FILE}.tmp"
|
||||||
|
}
|
||||||
|
trap cleanup 0 1 2 3 6
|
||||||
|
|
||||||
|
"$@" > "${DST_FILE}.tmp"
|
||||||
|
# If we get here, the command was successful, and we can overwrite the destination.
|
||||||
|
|
||||||
|
if ! cmp --quiet -- "${DST_FILE}.tmp" "${DST_FILE}"; then
|
||||||
|
# File changed, need to overwrite:
|
||||||
|
mv -f -- "${DST_FILE}.tmp" "${DST_FILE}"
|
||||||
|
fi
|
Loading…
Add table
Add a link
Reference in a new issue