blob: e39b66182116e97d9870d5b0b8a10c9a4faaa312 [file] [log] [blame]
Andres Amaya Garcia4c1e2ec2018-01-10 11:03:45 +00001#! /usr/bin/env sh
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +00002
Andres Amaya Garcia4c1e2ec2018-01-10 11:03:45 +00003# Copyright (c) 2018, ARM Limited, All Rights Reserved
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02004# SPDX-License-Identifier: Apache-2.0
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# This file is part of Mbed TLS (https://tls.mbed.org)
Andres Amaya Garcia4c1e2ec2018-01-10 11:03:45 +000019#
20# Purpose
21#
22# Check if generated files are up-to-date.
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000023
24set -eu
25
26if [ -d library -a -d include -a -d tests ]; then :; else
27 echo "Must be run from mbed TLS root" >&2
28 exit 1
29fi
30
31check()
32{
Andres Amaya Garcia4c1e2ec2018-01-10 11:03:45 +000033 SCRIPT=$1
34 TO_CHECK=$2
35 PATTERN=""
Andres AGc4ec7162018-04-11 21:13:20 -050036 FILES=""
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000037
Andres Amaya Garcia4c1e2ec2018-01-10 11:03:45 +000038 if [ -d $TO_CHECK ]; then
39 for FILE in $TO_CHECK/*; do
40 FILES="$FILE $FILES"
41 done
42 else
43 FILES=$TO_CHECK
44 fi
45
46 for FILE in $FILES; do
47 cp $FILE $FILE.bak
48 done
49
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000050 $SCRIPT
Andres Amaya Garcia4c1e2ec2018-01-10 11:03:45 +000051
52 # Compare the script output to the old files and remove backups
53 for FILE in $FILES; do
54 if ! diff $FILE $FILE.bak >/dev/null 2>&1; then
55 echo "'$FILE' was either modified or deleted by '$SCRIPT'"
56 exit 1
57 fi
58 mv $FILE.bak $FILE
59
60 if [ -d $TO_CHECK ]; then
61 # Create a grep regular expression that we can check against the
62 # directory contents to test whether new files have been created
63 if [ -z $PATTERN ]; then
64 PATTERN="$(basename $FILE)"
65 else
66 PATTERN="$PATTERN\|$(basename $FILE)"
67 fi
68 fi
69 done
70
71 if [ -d $TO_CHECK ]; then
72 # Check if there are any new files
73 if ls -1 $TO_CHECK | grep -v "$PATTERN" >/dev/null 2>&1; then
74 echo "Files were created by '$SCRIPT'"
75 exit 1
76 fi
77 fi
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000078}
79
Andres Amaya Garcia4c1e2ec2018-01-10 11:03:45 +000080check scripts/generate_errors.pl library/error.c
Jaeden Amero7cb47de2019-02-28 11:37:23 +000081check scripts/generate_query_config.pl programs/test/query_config.c
Andres Amaya Garcia4c1e2ec2018-01-10 11:03:45 +000082check scripts/generate_features.pl library/version_features.c
83check scripts/generate_visualc_files.pl visualc/VS2010