blob: 7ad707e151dae0d804048808abbcb24adf7f24fd [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
Manuel Pégourié-Gonnard961fb132020-07-16 10:40:13 +020053if [ $# -ne 0 ] && [ "$1" = "--help" ]; then
54 cat <<EOF
55$0 [-u]
56This script checks that all generated file are up-to-date. If some aren't, by
57default the scripts reports it and exits in error; with the -u option, it just
58updates them instead.
59
60 -u Update the files rather than return an error for out-of-date files.
61EOF
62 exit
63fi
64
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000065if [ -d library -a -d include -a -d tests ]; then :; else
66 echo "Must be run from mbed TLS root" >&2
67 exit 1
68fi
69
Manuel Pégourié-Gonnard961fb132020-07-16 10:40:13 +020070UPDATE=
71if [ $# -ne 0 ] && [ "$1" = "-u" ]; then
72 shift
73 UPDATE='y'
74fi
75
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000076check()
77{
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +000078 SCRIPT=$1
79 TO_CHECK=$2
80 PATTERN=""
Andres AGb7b420b2018-04-11 21:13:20 -050081 FILES=""
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000082
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +000083 if [ -d $TO_CHECK ]; then
84 for FILE in $TO_CHECK/*; do
85 FILES="$FILE $FILES"
86 done
87 else
88 FILES=$TO_CHECK
89 fi
90
91 for FILE in $FILES; do
92 cp $FILE $FILE.bak
93 done
94
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +000095 $SCRIPT
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +000096
97 # Compare the script output to the old files and remove backups
98 for FILE in $FILES; do
99 if ! diff $FILE $FILE.bak >/dev/null 2>&1; then
100 echo "'$FILE' was either modified or deleted by '$SCRIPT'"
Manuel Pégourié-Gonnard961fb132020-07-16 10:40:13 +0200101 if [ -z "$UPDATE" ]; then
102 exit 1
103 fi
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +0000104 fi
Manuel Pégourié-Gonnard961fb132020-07-16 10:40:13 +0200105 if [ -z "$UPDATE" ]; then
106 mv $FILE.bak $FILE
107 else
108 rm $FILE.bak
109 fi
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +0000110
111 if [ -d $TO_CHECK ]; then
112 # Create a grep regular expression that we can check against the
113 # directory contents to test whether new files have been created
114 if [ -z $PATTERN ]; then
115 PATTERN="$(basename $FILE)"
116 else
117 PATTERN="$PATTERN\|$(basename $FILE)"
118 fi
119 fi
120 done
121
122 if [ -d $TO_CHECK ]; then
123 # Check if there are any new files
124 if ls -1 $TO_CHECK | grep -v "$PATTERN" >/dev/null 2>&1; then
125 echo "Files were created by '$SCRIPT'"
Manuel Pégourié-Gonnard961fb132020-07-16 10:40:13 +0200126 if [ -z "$UPDATE" ]; then
127 exit 1
128 fi
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +0000129 fi
130 fi
Manuel Pégourié-Gonnardb3b8e432015-02-13 14:52:19 +0000131}
132
Andres Amaya Garcia7dae1082018-01-10 11:03:45 +0000133check scripts/generate_errors.pl library/error.c
134check scripts/generate_features.pl library/version_features.c
135check scripts/generate_visualc_files.pl visualc/VS2010