sanity.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. ##===----------------------------------------------------------------------===##
  3. ##
  4. ## This source file is part of the Swift Logging API open source project
  5. ##
  6. ## Copyright (c) 2018-2019 Apple Inc. and the Swift Logging API project authors
  7. ## Licensed under Apache License v2.0
  8. ##
  9. ## See LICENSE.txt for license information
  10. ## See CONTRIBUTORS.txt for the list of Swift Logging API project authors
  11. ##
  12. ## SPDX-License-Identifier: Apache-2.0
  13. ##
  14. ##===----------------------------------------------------------------------===##
  15. ##===----------------------------------------------------------------------===##
  16. ##
  17. ## This source file is part of the SwiftNIO open source project
  18. ##
  19. ## Copyright (c) 2017-2019 Apple Inc. and the SwiftNIO project authors
  20. ## Licensed under Apache License v2.0
  21. ##
  22. ## See LICENSE.txt for license information
  23. ## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
  24. ##
  25. ## SPDX-License-Identifier: Apache-2.0
  26. ##
  27. ##===----------------------------------------------------------------------===##
  28. set -eu
  29. here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  30. function replace_acceptable_years() {
  31. # this needs to replace all acceptable forms with 'YEARS'
  32. sed -e 's/2018-2019/YEARS/' -e 's/2019/YEARS/'
  33. }
  34. printf "=> Checking linux tests... "
  35. FIRST_OUT="$(git status --porcelain)"
  36. ruby "$here/../scripts/generate_linux_tests.rb" > /dev/null
  37. SECOND_OUT="$(git status --porcelain)"
  38. if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
  39. printf "\033[0;31mmissing changes!\033[0m\n"
  40. git --no-pager diff
  41. exit 1
  42. else
  43. printf "\033[0;32mokay.\033[0m\n"
  44. fi
  45. printf "=> Checking license headers... "
  46. tmp=$(mktemp /tmp/.swift-log-sanity_XXXXXX)
  47. for language in swift-or-c bash dtrace; do
  48. declare -a matching_files
  49. declare -a exceptions
  50. expections=( )
  51. matching_files=( -name '*' )
  52. case "$language" in
  53. swift-or-c)
  54. exceptions=( -name c_nio_http_parser.c -o -name c_nio_http_parser.h -o -name cpp_magic.h -o -name Package.swift -o -name CNIOSHA1.h -o -name c_nio_sha1.c -o -name ifaddrs-android.c -o -name ifaddrs-android.h)
  55. matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' )
  56. cat > "$tmp" <<"EOF"
  57. //===----------------------------------------------------------------------===//
  58. //
  59. // This source file is part of the Swift Logging API open source project
  60. //
  61. // Copyright (c) YEARS Apple Inc. and the Swift Logging API project authors
  62. // Licensed under Apache License v2.0
  63. //
  64. // See LICENSE.txt for license information
  65. // See CONTRIBUTORS.txt for the list of Swift Logging API project authors
  66. //
  67. // SPDX-License-Identifier: Apache-2.0
  68. //
  69. //===----------------------------------------------------------------------===//
  70. EOF
  71. ;;
  72. bash)
  73. matching_files=( -name '*.sh' )
  74. cat > "$tmp" <<"EOF"
  75. #!/bin/bash
  76. ##===----------------------------------------------------------------------===##
  77. ##
  78. ## This source file is part of the Swift Logging API open source project
  79. ##
  80. ## Copyright (c) YEARS Apple Inc. and the Swift Logging API project authors
  81. ## Licensed under Apache License v2.0
  82. ##
  83. ## See LICENSE.txt for license information
  84. ## See CONTRIBUTORS.txt for the list of Swift Logging API project authors
  85. ##
  86. ## SPDX-License-Identifier: Apache-2.0
  87. ##
  88. ##===----------------------------------------------------------------------===##
  89. EOF
  90. ;;
  91. dtrace)
  92. matching_files=( -name '*.d' )
  93. cat > "$tmp" <<"EOF"
  94. #!/usr/sbin/dtrace -q -s
  95. /*===----------------------------------------------------------------------===*
  96. *
  97. * This source file is part of the Swift Logging API open source project
  98. *
  99. * Copyright (c) YEARS Apple Inc. and the Swift Logging API project authors
  100. * Licensed under Apache License v2.0
  101. *
  102. * See LICENSE.txt for license information
  103. * See CONTRIBUTORS.txt for the list of Swift Logging API project authors
  104. *
  105. * SPDX-License-Identifier: Apache-2.0
  106. *
  107. *===----------------------------------------------------------------------===*/
  108. EOF
  109. ;;
  110. *)
  111. echo >&2 "ERROR: unknown language '$language'"
  112. ;;
  113. esac
  114. expected_lines=$(cat "$tmp" | wc -l)
  115. expected_sha=$(cat "$tmp" | shasum)
  116. (
  117. cd "$here/.."
  118. find . \
  119. \( \! -path './.build/*' -a \
  120. \( "${matching_files[@]}" \) -a \
  121. \( \! \( "${exceptions[@]}" \) \) \) | while read line; do
  122. if [[ "$(cat "$line" | replace_acceptable_years | head -n $expected_lines | shasum)" != "$expected_sha" ]]; then
  123. printf "\033[0;31mmissing headers in file '$line'!\033[0m\n"
  124. diff -u <(cat "$line" | replace_acceptable_years | head -n $expected_lines) "$tmp"
  125. exit 1
  126. fi
  127. done
  128. printf "\033[0;32mokay.\033[0m\n"
  129. )
  130. done
  131. rm "$tmp"