check-order.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash -e
  2. #
  3. # Copyright (c) 2018 Apple Inc. All rights reserved.
  4. #
  5. # @APPLE_APACHE_LICENSE_HEADER_START@
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. # @APPLE_APACHE_LICENSE_HEADER_END@
  20. #
  21. test "$ACTION" = install || exit 0
  22. list_objc_syms ()
  23. {
  24. nm -arch $1 -nU ${DSTROOT}/usr/lib/system/libdispatch.dylib | grep _OBJC | cut -d' ' -f3
  25. }
  26. list_mutable_data_syms ()
  27. {
  28. nm -arch $1 -m ${DSTROOT}/usr/lib/system/libdispatch.dylib |grep __DATA|egrep -v '(__const|__crash_info)'|sed 's/^.* //'
  29. }
  30. list_objc_order ()
  31. {
  32. grep '^_OBJC' "${SCRIPT_INPUT_FILE_0}"
  33. }
  34. list_dirty_order ()
  35. {
  36. grep '^[^#]' "${SCRIPT_INPUT_FILE_1}"
  37. }
  38. list_clean_order ()
  39. {
  40. grep '^[^#]' "${SCRIPT_INPUT_FILE_2}"
  41. }
  42. fail=
  43. case "$PLATFORM_NAME" in
  44. *simulator) exit 0;;
  45. *) ;;
  46. esac
  47. if comm -12 <(list_dirty_order | sort) <(list_clean_order | sort) | grep .; then
  48. echo 1>&2 "error: *** SYMBOLS CAN'T BE BOTH CLEAN AND DIRTY ***"
  49. comm 1>&2 -12 <(list_dirty_order | sort) <(list_clean_order | sort)
  50. fail=t
  51. fi
  52. for arch in $ARCHS; do
  53. if test "$PLATFORM_NAME" = macosx -a "$arch" = i386; then
  54. continue
  55. fi
  56. if list_mutable_data_syms $arch | sort | uniq -c | grep -qvw 1; then
  57. echo 1>&2 "error: *** DUPLICATED SYMBOL NAMES FOR SLICE $arch ***"
  58. list_mutable_data_syms $arch | sort | uniq -c | grep -qw 1 1>&2
  59. fail=t
  60. fi
  61. if comm -23 <(list_mutable_data_syms $arch | sort) <((list_dirty_order; list_clean_order) | sort) | grep -q .; then
  62. echo 1>&2 "error: *** SYMBOLS NOT MARKED CLEAN OR DIRTY FOR SLICE $arch ***"
  63. comm 1>&2 -23 <(list_mutable_data_syms $arch | sort) <((list_dirty_order; list_clean_order) | sort)
  64. fail=t
  65. fi
  66. if comm -13 <(list_mutable_data_syms $arch | sort) <((list_dirty_order; list_clean_order) | sort) | grep -q .; then
  67. echo 1>&2 "warning: *** Found unknown symbols in dirty/clean files for slice $arch ***"
  68. comm 1>&2 -13 <(list_mutable_data_syms $arch | sort) <((list_dirty_order; list_clean_order) | sort)
  69. fi
  70. if ! cmp -s <(list_objc_syms $arch) <(list_objc_order); then
  71. echo 1>&2 "error: *** SYMBOL ORDER IS NOT WHAT IS EXPECTED FOR SLICE $arch ***"
  72. diff 1>&2 -U100 <(list_objc_syms $arch) <(list_objc_order) || fail=t
  73. fi
  74. done
  75. test -z "$fail"