Update mbedTLS sources
[platform/upstream/iotivity.git] / extlibs / mbedtls / mbedtls / tests / scripts / check-generated-files.sh
1 #! /usr/bin/env sh
2
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.
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 {
20     SCRIPT=$1
21     TO_CHECK=$2
22     PATTERN=""
23     FILES=""
24
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
37     $SCRIPT
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
65 }
66
67 check scripts/generate_errors.pl library/error.c
68 check scripts/generate_query_config.pl programs/ssl/query_config.c
69 check scripts/generate_features.pl library/version_features.c
70 check scripts/generate_visualc_files.pl visualc/VS2010