Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 1 | #! /usr/bin/env sh |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 2 | |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 3 | # This file is part of mbed TLS (https://tls.mbed.org) |
| 4 | # |
| 5 | # Copyright (c) 2018, ARM Limited, All Rights Reserved |
| 6 | # |
| 7 | # Purpose |
| 8 | # |
| 9 | # Check if generated files are up-to-date. |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 10 | |
| 11 | set -eu |
| 12 | |
| 13 | if [ -d library -a -d include -a -d tests ]; then :; else |
| 14 | echo "Must be run from mbed TLS root" >&2 |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | check() |
| 19 | { |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 20 | SCRIPT=$1 |
| 21 | TO_CHECK=$2 |
| 22 | PATTERN="" |
Andres AG | c4ec716 | 2018-04-11 21:13:20 -0500 | [diff] [blame] | 23 | FILES="" |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 24 | |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 25 | if [ -d $TO_CHECK ]; then |
| 26 | for FILE in $TO_CHECK/*; do |
| 27 | FILES="$FILE $FILES" |
| 28 | done |
| 29 | else |
| 30 | FILES=$TO_CHECK |
| 31 | fi |
| 32 | |
| 33 | for FILE in $FILES; do |
| 34 | cp $FILE $FILE.bak |
| 35 | done |
| 36 | |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 37 | $SCRIPT |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 38 | |
| 39 | # Compare the script output to the old files and remove backups |
| 40 | for FILE in $FILES; do |
| 41 | if ! diff $FILE $FILE.bak >/dev/null 2>&1; then |
| 42 | echo "'$FILE' was either modified or deleted by '$SCRIPT'" |
| 43 | exit 1 |
| 44 | fi |
| 45 | mv $FILE.bak $FILE |
| 46 | |
| 47 | if [ -d $TO_CHECK ]; then |
| 48 | # Create a grep regular expression that we can check against the |
| 49 | # directory contents to test whether new files have been created |
| 50 | if [ -z $PATTERN ]; then |
| 51 | PATTERN="$(basename $FILE)" |
| 52 | else |
| 53 | PATTERN="$PATTERN\|$(basename $FILE)" |
| 54 | fi |
| 55 | fi |
| 56 | done |
| 57 | |
| 58 | if [ -d $TO_CHECK ]; then |
| 59 | # Check if there are any new files |
| 60 | if ls -1 $TO_CHECK | grep -v "$PATTERN" >/dev/null 2>&1; then |
| 61 | echo "Files were created by '$SCRIPT'" |
| 62 | exit 1 |
| 63 | fi |
| 64 | fi |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 67 | check scripts/generate_errors.pl library/error.c |
Jaeden Amero | 7cb47de | 2019-02-28 11:37:23 +0000 | [diff] [blame] | 68 | check scripts/generate_query_config.pl programs/test/query_config.c |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 69 | check scripts/generate_features.pl library/version_features.c |
| 70 | check scripts/generate_visualc_files.pl visualc/VS2010 |