From b5c4382bef8c688d0cf63f554a7d886faddc77cb Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 5 Apr 2022 14:08:09 +0200 Subject: [PATCH] check-generated-files.sh -u: don't update file timestamps When running check-generated-files in update mode, all generated files were regenerated. As a consequence, ``` tests/scripts/check-generated-files.sh -u && make ``` always caused most of the code to be rebuilt. Now, if a file hasn't changed, preserve its original modification time (and other metadata), so the command above doesn't rebuild anything that has actually not changed. Signed-off-by: Gilles Peskine --- tests/scripts/check-generated-files.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 5e35be8f9..75730ba25 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -65,24 +65,25 @@ check() fi for FILE in "$@"; do - cp "$FILE" "$FILE.bak" + cp -p "$FILE" "$FILE.bak" done "$SCRIPT" # Compare the script output to the old files and remove backups for FILE in "$@"; do - if ! diff "$FILE" "$FILE.bak" >/dev/null 2>&1; then + if diff "$FILE" "$FILE.bak" >/dev/null 2>&1; then + # Move the original file back so that $FILE's timestamp doesn't + # change (avoids spurious rebuilds with make). + mv "$FILE.bak" "$FILE" + else echo "'$FILE' was either modified or deleted by '$SCRIPT'" if [ -z "$UPDATE" ]; then exit 1 + else + rm "$FILE.bak" fi fi - if [ -z "$UPDATE" ]; then - mv "$FILE.bak" "$FILE" - else - rm "$FILE.bak" - fi done if [ -n "$directory" ]; then