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 | 09b4f19 | 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 | 7dae108 | 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 | |
| 26 | if [ -d library -a -d include -a -d tests ]; then :; else |
| 27 | echo "Must be run from mbed TLS root" >&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | check() |
| 32 | { |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 33 | SCRIPT=$1 |
| 34 | TO_CHECK=$2 |
| 35 | PATTERN="" |
Andres AG | b7b420b | 2018-04-11 21:13:20 -0500 | [diff] [blame] | 36 | FILES="" |
Manuel Pégourié-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 37 | |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 38 | 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é-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 50 | $SCRIPT |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 51 | |
| 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é-Gonnard | b3b8e43 | 2015-02-13 14:52:19 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Andres Amaya Garcia | 7dae108 | 2018-01-10 11:03:45 +0000 | [diff] [blame] | 80 | check scripts/generate_errors.pl library/error.c |
| 81 | check scripts/generate_features.pl library/version_features.c |
| 82 | check scripts/generate_visualc_files.pl visualc/VS2010 |