check-safety.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/sh
  2. # Copyright 2014-2019 Free Software Foundation, Inc.
  3. # This file is part of the GNU C Library.
  4. # The GNU C Library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. # The GNU C Library is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # Lesser General Public License for more details.
  12. # You should have received a copy of the GNU Lesser General Public
  13. # License along with the GNU C Library; if not, see
  14. # <http://www.gnu.org/licenses/>.
  15. # Check that the @safety notes are self-consistent, i.e., that they're
  16. # in proper order (mt then as then ac), that remarks appear within
  17. # corresponding sections (mt within mt, etc), that unsafety always has
  18. # an explicit reason and when there's a reason for unsafety it's not
  19. # safe, and that there aren't duplicates remarks.
  20. success=:
  21. # If no arguments are given, take all *.texi files in the current directory.
  22. test $# != 0 || set *.texi
  23. # FIXME: check that each @deftypefu?n is followed by a @safety note,
  24. # with nothing but @deftypefu?nx and comment lines in between. (There
  25. # might be more stuff too).
  26. # Check that all safety remarks have entries for all of MT, AS and AC,
  27. # in this order, with an optional prelim note before them.
  28. grep -n '^@safety' "$@" |
  29. grep -v ':@safety{\(@prelim{}\)\?@mt\(un\)\?safe{.*}'\
  30. '@as\(un\)\?safe{.*}@ac\(un\)\?safe{.*}}' &&
  31. success=false
  32. # Check that @mt-started notes appear within @mtsafe or @mtunsafe,
  33. # that @as-started notes appear within @assafe or @asunsafe, and that
  34. # @ac-started notes appear within @acsafe or @acunsafe. Also check
  35. # that @mt, @as and @ac are followed by an s (for safe) or u (for
  36. # unsafe), but let @mt have as, ac or asc before [su], and let @as
  37. # have a c (for cancel) before [su]. Also make sure blanks separate
  38. # each of the annotations.
  39. grep -n '^@safety' "$@" |
  40. grep -v ':@safety{\(@prelim{}\)\?'\
  41. '@mt\(un\)\?safe{\(@mt\(asc\?\|ac\)\?[su][^ ]*}\)\?'\
  42. '\( @mt\(asc\?\|ac\)\?[su][^ ]*}\)*}'\
  43. '@as\(un\)\?safe{\(@asc\?[su][^ ]*}\)\?'\
  44. '\( @asc\?[su][^ ]*}\)*}'\
  45. '@ac\(un\)\?safe{\(@ac[su][^ ]*}\)\?'\
  46. '\( @ac[su][^ ]*}\)*}}' &&
  47. success=false
  48. # Make sure safety lines marked as @mtsafe do not contain any
  49. # MT-Unsafe remark; that would be @mtu, but there could be as, ac or
  50. # asc between mt and u.
  51. grep -n '^@safety.*@mtsafe' "$@" |
  52. grep '@mt\(asc\?\|ac\)?u' "$@" &&
  53. success=false
  54. # Make sure @mtunsafe lines contain at least one @mtu remark (with
  55. # optional as, ac or asc between mt and u).
  56. grep -n '^@safety.*@mtunsafe' "$@" |
  57. grep -v '@mtunsafe{.*@mt\(asc\?\|ac\)\?u' &&
  58. success=false
  59. # Make sure safety lines marked as @assafe do not contain any AS-Unsafe
  60. # remark, which could be @asu or @mtasu note (with an optional c
  61. # between as and u in both cases).
  62. grep -n '^@safety.*@assafe' "$@" |
  63. grep '@\(mt\)\?asc\?u' &&
  64. success=false
  65. # Make sure @asunsafe lines contain at least one @asu remark (which
  66. # could be @ascu, or @mtasu or even @mtascu).
  67. grep -n '^@safety.*@asunsafe' "$@" |
  68. grep -v '@mtasc\?u.*@asunsafe\|@asunsafe{.*@asc\?u' &&
  69. success=false
  70. # Make sure safety lines marked as @acsafe do not contain any
  71. # AC-Unsafe remark, which could be @acu, @ascu or even @mtacu or
  72. # @mtascu.
  73. grep -n '^@safety.*@acsafe' "$@" |
  74. grep '@\(mt\)\?as\?cu' &&
  75. success=false
  76. # Make sure @acunsafe lines contain at least one @acu remark (possibly
  77. # implied by @ascu, @mtacu or @mtascu).
  78. grep -n '^@safety.*@acunsafe' "$@" |
  79. grep -v '@\(mtas\?\|as\)cu.*@acunsafe\|@acunsafe{.*@acu' &&
  80. success=false
  81. # Make sure there aren't duplicate remarks in the same safety note.
  82. grep -n '^@safety' "$@" |
  83. grep '[^:]\(@\(mt\|a[sc]\)[^ {]*{[^ ]*}\).*[^:]\1' &&
  84. success=false
  85. # Check that comments containing safety remarks do not contain {}s,
  86. # that all @mt remarks appear before @as remarks, that in turn appear
  87. # before @ac remarks, all properly blank-separated, and that an
  88. # optional comment about exclusions is between []s at the end of the
  89. # line.
  90. grep -n '^@c \+[^@ ]\+\( dup\)\?'\
  91. '\( @\(mt\|a[sc]\)[^ ]*\)*\( \[.*\]\)\?$' "$@" |
  92. grep -v ':@c *[^@{}]*\( @mt[^ {}]*\)*'\
  93. '\( @as[^ {}]*\)*\( @ac[^ {}]*\)*\( \[.*\]\)\?$' &&
  94. success=false
  95. # Check that comments containing safety remarks do not contain
  96. # duplicate remarks.
  97. grep -n '^@c \+[^@ ]\+\( dup\)\?'\
  98. '\( @\(mt\|a[sc]\)[^ ]*\)*\( \[.*\]\)\?$' "$@" |
  99. grep '[^:]\(@\(mt\|a[sc]\)[^ ]*\) \(.*[^:]\)\?\1\($\| \)' &&
  100. success=false
  101. $success