blob: ac3e31c4b5e893e4ede900ea3ea04b55f0617fe7 [file] [log] [blame]
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +00001#! /usr/bin/env sh
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +00002
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +00003# Copyright (c) 2018, ARM Limited, All Rights Reserved
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02004# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5#
6# This file is provided under the Apache License 2.0, or the
7# GNU General Public License v2.0 or later.
8#
9# **********
10# Apache License 2.0:
Bence Szépkúti09b4f192020-05-26 01:54:15 +020011#
12# Licensed under the Apache License, Version 2.0 (the "License"); you may
13# not use this file except in compliance with the License.
14# You may obtain a copy of the License at
15#
16# http://www.apache.org/licenses/LICENSE-2.0
17#
18# Unless required by applicable law or agreed to in writing, software
19# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21# See the License for the specific language governing permissions and
22# limitations under the License.
23#
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020024# **********
25#
26# **********
27# GNU General Public License v2.0 or later:
28#
29# This program is free software; you can redistribute it and/or modify
30# it under the terms of the GNU General Public License as published by
31# the Free Software Foundation; either version 2 of the License, or
32# (at your option) any later version.
33#
34# This program is distributed in the hope that it will be useful,
35# but WITHOUT ANY WARRANTY; without even the implied warranty of
36# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37# GNU General Public License for more details.
38#
39# You should have received a copy of the GNU General Public License along
40# with this program; if not, write to the Free Software Foundation, Inc.,
41# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
42#
43# **********
44#
Bence Szépkúti09b4f192020-05-26 01:54:15 +020045# This file is part of Mbed TLS (https://tls.mbed.org)
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +000046#
47# Purpose
48#
49# Check if generated files are up-to-date.
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000050
51set -eu
52
53if [ -d library -a -d include -a -d tests ]; then :; else
54 echo "Must be run from mbed TLS root" >&2
55 exit 1
56fi
57
58check()
59{
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +000060 SCRIPT=$1
61 TO_CHECK=$2
62 PATTERN=""
Andres AGb7b420b2018-04-11 21:13:20 -050063 FILES=""
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000064
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +000065 if [ -d $TO_CHECK ]; then
66 for FILE in $TO_CHECK/*; do
67 FILES="$FILE $FILES"
68 done
69 else
70 FILES=$TO_CHECK
71 fi
72
73 for FILE in $FILES; do
74 cp $FILE $FILE.bak
75 done
76
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000077 $SCRIPT
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +000078
79 # Compare the script output to the old files and remove backups
80 for FILE in $FILES; do
81 if ! diff $FILE $FILE.bak >/dev/null 2>&1; then
82 echo "'$FILE' was either modified or deleted by '$SCRIPT'"
83 exit 1
84 fi
85 mv $FILE.bak $FILE
86
87 if [ -d $TO_CHECK ]; then
88 # Create a grep regular expression that we can check against the
89 # directory contents to test whether new files have been created
90 if [ -z $PATTERN ]; then
91 PATTERN="$(basename $FILE)"
92 else
93 PATTERN="$PATTERN\|$(basename $FILE)"
94 fi
95 fi
96 done
97
98 if [ -d $TO_CHECK ]; then
99 # Check if there are any new files
100 if ls -1 $TO_CHECK | grep -v "$PATTERN" >/dev/null 2>&1; then
101 echo "Files were created by '$SCRIPT'"
102 exit 1
103 fi
104 fi
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000105}
106
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +0000107check scripts/generate_errors.pl library/error.c
108check scripts/generate_features.pl library/version_features.c
109check scripts/generate_visualc_files.pl visualc/VS2010