Andres Amaya Garcia | 7dae108 | 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 | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 3 | # Copyright (c) 2018, ARM Limited, All Rights Reserved |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 4 | # 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úti | 09b4f19 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 11 | # |
| 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úti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 24 | # ********** |
| 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úti | 09b4f19 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 45 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 46 | # |
| 47 | # Purpose |
| 48 | # |
| 49 | # Check if generated files are up-to-date. |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 50 | |
| 51 | set -eu |
| 52 | |
Manuel Pégourié-Gonnard | 961fb13 | 2020-07-16 10:40:13 +0200 | [diff] [blame^] | 53 | if [ $# -ne 0 ] && [ "$1" = "--help" ]; then |
| 54 | cat <<EOF |
| 55 | $0 [-u] |
| 56 | This script checks that all generated file are up-to-date. If some aren't, by |
| 57 | default the scripts reports it and exits in error; with the -u option, it just |
| 58 | updates them instead. |
| 59 | |
| 60 | -u Update the files rather than return an error for out-of-date files. |
| 61 | EOF |
| 62 | exit |
| 63 | fi |
| 64 | |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 65 | if [ -d library -a -d include -a -d tests ]; then :; else |
| 66 | echo "Must be run from mbed TLS root" >&2 |
| 67 | exit 1 |
| 68 | fi |
| 69 | |
Manuel Pégourié-Gonnard | 961fb13 | 2020-07-16 10:40:13 +0200 | [diff] [blame^] | 70 | UPDATE= |
| 71 | if [ $# -ne 0 ] && [ "$1" = "-u" ]; then |
| 72 | shift |
| 73 | UPDATE='y' |
| 74 | fi |
| 75 | |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 76 | check() |
| 77 | { |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 78 | SCRIPT=$1 |
| 79 | TO_CHECK=$2 |
| 80 | PATTERN="" |
Andres AG | b7b420b | 2018-04-11 21:13:20 -0500 | [diff] [blame] | 81 | FILES="" |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 82 | |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 83 | 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é-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 95 | $SCRIPT |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 96 | |
| 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é-Gonnard | 961fb13 | 2020-07-16 10:40:13 +0200 | [diff] [blame^] | 101 | if [ -z "$UPDATE" ]; then |
| 102 | exit 1 |
| 103 | fi |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 104 | fi |
Manuel Pégourié-Gonnard | 961fb13 | 2020-07-16 10:40:13 +0200 | [diff] [blame^] | 105 | if [ -z "$UPDATE" ]; then |
| 106 | mv $FILE.bak $FILE |
| 107 | else |
| 108 | rm $FILE.bak |
| 109 | fi |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 110 | |
| 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é-Gonnard | 961fb13 | 2020-07-16 10:40:13 +0200 | [diff] [blame^] | 126 | if [ -z "$UPDATE" ]; then |
| 127 | exit 1 |
| 128 | fi |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 129 | fi |
| 130 | fi |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 133 | check scripts/generate_errors.pl library/error.c |
| 134 | check scripts/generate_features.pl library/version_features.c |
| 135 | check scripts/generate_visualc_files.pl visualc/VS2010 |