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="" |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 23 | |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame^] | 24 | if [ -d $TO_CHECK ]; then |
| 25 | for FILE in $TO_CHECK/*; do |
| 26 | FILES="$FILE $FILES" |
| 27 | done |
| 28 | else |
| 29 | FILES=$TO_CHECK |
| 30 | fi |
| 31 | |
| 32 | for FILE in $FILES; do |
| 33 | cp $FILE $FILE.bak |
| 34 | done |
| 35 | |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 36 | $SCRIPT |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame^] | 37 | |
| 38 | # Compare the script output to the old files and remove backups |
| 39 | for FILE in $FILES; do |
| 40 | if ! diff $FILE $FILE.bak >/dev/null 2>&1; then |
| 41 | echo "'$FILE' was either modified or deleted by '$SCRIPT'" |
| 42 | exit 1 |
| 43 | fi |
| 44 | mv $FILE.bak $FILE |
| 45 | |
| 46 | if [ -d $TO_CHECK ]; then |
| 47 | # Create a grep regular expression that we can check against the |
| 48 | # directory contents to test whether new files have been created |
| 49 | if [ -z $PATTERN ]; then |
| 50 | PATTERN="$(basename $FILE)" |
| 51 | else |
| 52 | PATTERN="$PATTERN\|$(basename $FILE)" |
| 53 | fi |
| 54 | fi |
| 55 | done |
| 56 | |
| 57 | if [ -d $TO_CHECK ]; then |
| 58 | # Check if there are any new files |
| 59 | if ls -1 $TO_CHECK | grep -v "$PATTERN" >/dev/null 2>&1; then |
| 60 | echo "Files were created by '$SCRIPT'" |
| 61 | exit 1 |
| 62 | fi |
| 63 | fi |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame^] | 66 | check scripts/generate_errors.pl library/error.c |
| 67 | check scripts/generate_features.pl library/version_features.c |
| 68 | check scripts/generate_visualc_files.pl visualc/VS2010 |