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 | # Copyright (c) 2018, ARM Limited, All Rights Reserved |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 4 | # 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 Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 19 | # |
| 20 | # Purpose |
| 21 | # |
| 22 | # Check if generated files are up-to-date. |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 23 | |
| 24 | set -eu |
| 25 | |
Manuel Pégourié-Gonnard | 2774fc4 | 2020-07-16 10:40:13 +0200 | [diff] [blame] | 26 | if [ $# -ne 0 ] && [ "$1" = "--help" ]; then |
| 27 | cat <<EOF |
| 28 | $0 [-u] |
| 29 | This script checks that all generated file are up-to-date. If some aren't, by |
| 30 | default the scripts reports it and exits in error; with the -u option, it just |
| 31 | updates them instead. |
| 32 | |
| 33 | -u Update the files rather than return an error for out-of-date files. |
| 34 | EOF |
| 35 | exit |
| 36 | fi |
| 37 | |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 38 | if [ -d library -a -d include -a -d tests ]; then :; else |
| 39 | echo "Must be run from mbed TLS root" >&2 |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
Manuel Pégourié-Gonnard | 2774fc4 | 2020-07-16 10:40:13 +0200 | [diff] [blame] | 43 | UPDATE= |
| 44 | if [ $# -ne 0 ] && [ "$1" = "-u" ]; then |
| 45 | shift |
| 46 | UPDATE='y' |
| 47 | fi |
| 48 | |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 49 | check() |
| 50 | { |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 51 | SCRIPT=$1 |
| 52 | TO_CHECK=$2 |
| 53 | PATTERN="" |
Andres AG | c4ec716 | 2018-04-11 21:13:20 -0500 | [diff] [blame] | 54 | FILES="" |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 55 | |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 56 | if [ -d $TO_CHECK ]; then |
| 57 | for FILE in $TO_CHECK/*; do |
| 58 | FILES="$FILE $FILES" |
| 59 | done |
| 60 | else |
| 61 | FILES=$TO_CHECK |
| 62 | fi |
| 63 | |
| 64 | for FILE in $FILES; do |
| 65 | cp $FILE $FILE.bak |
| 66 | done |
| 67 | |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 68 | $SCRIPT |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 69 | |
| 70 | # Compare the script output to the old files and remove backups |
| 71 | for FILE in $FILES; do |
| 72 | if ! diff $FILE $FILE.bak >/dev/null 2>&1; then |
| 73 | echo "'$FILE' was either modified or deleted by '$SCRIPT'" |
Manuel Pégourié-Gonnard | 2774fc4 | 2020-07-16 10:40:13 +0200 | [diff] [blame] | 74 | if [ -z "$UPDATE" ]; then |
| 75 | exit 1 |
| 76 | fi |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 77 | fi |
Manuel Pégourié-Gonnard | 2774fc4 | 2020-07-16 10:40:13 +0200 | [diff] [blame] | 78 | if [ -z "$UPDATE" ]; then |
| 79 | mv $FILE.bak $FILE |
| 80 | else |
| 81 | rm $FILE.bak |
| 82 | fi |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 83 | |
| 84 | if [ -d $TO_CHECK ]; then |
| 85 | # Create a grep regular expression that we can check against the |
| 86 | # directory contents to test whether new files have been created |
| 87 | if [ -z $PATTERN ]; then |
| 88 | PATTERN="$(basename $FILE)" |
| 89 | else |
| 90 | PATTERN="$PATTERN\|$(basename $FILE)" |
| 91 | fi |
| 92 | fi |
| 93 | done |
| 94 | |
| 95 | if [ -d $TO_CHECK ]; then |
| 96 | # Check if there are any new files |
| 97 | if ls -1 $TO_CHECK | grep -v "$PATTERN" >/dev/null 2>&1; then |
| 98 | echo "Files were created by '$SCRIPT'" |
Manuel Pégourié-Gonnard | 2774fc4 | 2020-07-16 10:40:13 +0200 | [diff] [blame] | 99 | if [ -z "$UPDATE" ]; then |
| 100 | exit 1 |
| 101 | fi |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 102 | fi |
| 103 | fi |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 106 | check scripts/generate_errors.pl library/error.c |
Jaeden Amero | 7cb47de | 2019-02-28 11:37:23 +0000 | [diff] [blame] | 107 | check scripts/generate_query_config.pl programs/test/query_config.c |
Andres Amaya Garcia | 4c1e2ec | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 108 | check scripts/generate_features.pl library/version_features.c |
| 109 | check scripts/generate_visualc_files.pl visualc/VS2010 |