check-generated-files.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #! /usr/bin/env sh
  2. # Copyright The Mbed TLS Contributors
  3. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  4. #
  5. # This file is provided under the Apache License 2.0, or the
  6. # GNU General Public License v2.0 or later.
  7. #
  8. # **********
  9. # Apache License 2.0:
  10. #
  11. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  12. # not use this file except in compliance with the License.
  13. # You may obtain a copy of the License at
  14. #
  15. # http://www.apache.org/licenses/LICENSE-2.0
  16. #
  17. # Unless required by applicable law or agreed to in writing, software
  18. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  19. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. # See the License for the specific language governing permissions and
  21. # limitations under the License.
  22. #
  23. # **********
  24. #
  25. # **********
  26. # GNU General Public License v2.0 or later:
  27. #
  28. # This program is free software; you can redistribute it and/or modify
  29. # it under the terms of the GNU General Public License as published by
  30. # the Free Software Foundation; either version 2 of the License, or
  31. # (at your option) any later version.
  32. #
  33. # This program is distributed in the hope that it will be useful,
  34. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. # GNU General Public License for more details.
  37. #
  38. # You should have received a copy of the GNU General Public License along
  39. # with this program; if not, write to the Free Software Foundation, Inc.,
  40. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  41. #
  42. # **********
  43. #
  44. # Purpose
  45. #
  46. # Check if generated files are up-to-date.
  47. set -eu
  48. if [ $# -ne 0 ] && [ "$1" = "--help" ]; then
  49. cat <<EOF
  50. $0 [-u]
  51. This script checks that all generated file are up-to-date. If some aren't, by
  52. default the scripts reports it and exits in error; with the -u option, it just
  53. updates them instead.
  54. -u Update the files rather than return an error for out-of-date files.
  55. EOF
  56. exit
  57. fi
  58. if [ -d library -a -d include -a -d tests ]; then :; else
  59. echo "Must be run from mbed TLS root" >&2
  60. exit 1
  61. fi
  62. UPDATE=
  63. if [ $# -ne 0 ] && [ "$1" = "-u" ]; then
  64. shift
  65. UPDATE='y'
  66. fi
  67. check()
  68. {
  69. SCRIPT=$1
  70. TO_CHECK=$2
  71. PATTERN=""
  72. FILES=""
  73. if [ -d $TO_CHECK ]; then
  74. for FILE in $TO_CHECK/*; do
  75. FILES="$FILE $FILES"
  76. done
  77. else
  78. FILES=$TO_CHECK
  79. fi
  80. for FILE in $FILES; do
  81. cp $FILE $FILE.bak
  82. done
  83. $SCRIPT
  84. # Compare the script output to the old files and remove backups
  85. for FILE in $FILES; do
  86. if ! diff $FILE $FILE.bak >/dev/null 2>&1; then
  87. echo "'$FILE' was either modified or deleted by '$SCRIPT'"
  88. if [ -z "$UPDATE" ]; then
  89. exit 1
  90. fi
  91. fi
  92. if [ -z "$UPDATE" ]; then
  93. mv $FILE.bak $FILE
  94. else
  95. rm $FILE.bak
  96. fi
  97. if [ -d $TO_CHECK ]; then
  98. # Create a grep regular expression that we can check against the
  99. # directory contents to test whether new files have been created
  100. if [ -z $PATTERN ]; then
  101. PATTERN="$(basename $FILE)"
  102. else
  103. PATTERN="$PATTERN\|$(basename $FILE)"
  104. fi
  105. fi
  106. done
  107. if [ -d $TO_CHECK ]; then
  108. # Check if there are any new files
  109. if ls -1 $TO_CHECK | grep -v "$PATTERN" >/dev/null 2>&1; then
  110. echo "Files were created by '$SCRIPT'"
  111. if [ -z "$UPDATE" ]; then
  112. exit 1
  113. fi
  114. fi
  115. fi
  116. }
  117. check scripts/generate_errors.pl library/error.c
  118. check scripts/generate_query_config.pl programs/ssl/query_config.c
  119. check scripts/generate_features.pl library/version_features.c
  120. check scripts/generate_visualc_files.pl visualc/VS2010