mk-bundle-hints.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) Viktor Szakats
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. detect_in_reused_sources=1
  26. if [ "$detect_in_reused_sources" = '1' ]; then
  27. # Make symlinks for all re-used sources
  28. grep -E '^(lib|unit)[0-9]+_SOURCES = ' libtest/Makefile.inc unit/Makefile.inc \
  29. | sed -E 's@^([a-z]+)/[a-zA-Z.]+:(lib|unit)([0-9]+)_SOURCES = (lib|unit)([0-9]+).+@\1 \2 \3 \5@g' | \
  30. while read -r l; do
  31. if [[ "${l}" =~ ([a-z]+)\ ([a-z]+)\ ([0-9]+)\ ([0-9]+) ]]; then
  32. trg="${BASH_REMATCH[3]}"
  33. src="${BASH_REMATCH[4]}"
  34. if [ "${trg}" != "${src}" ]; then
  35. dir="${BASH_REMATCH[1]}"
  36. pfx="${BASH_REMATCH[2]}"
  37. ln -s "${pfx}${src}.c" "${dir}/${pfx}${trg}.c"
  38. fi
  39. fi
  40. done
  41. fi
  42. # Look for symbols possibly re-used in multiple sources.
  43. #
  44. # Falsely picks ups symbols in re-used sources, but guarded for a single use.
  45. # Misses shadowed variables.
  46. # shellcheck disable=SC2046
  47. grep -E '^ *(static|struct) +' $(find libtest unit -maxdepth 1 -name 'lib*.c' -o -name 'unit*.c' -o -name 'mk-*.pl') \
  48. | grep -E '^(libtest|unit)/' \
  49. | grep -E '\.(c|pl):(static|struct)( +[a-zA-Z_* ]+)? +[a-zA-Z_][a-zA-Z0-9_]+ *' | sort -u \
  50. | grep -o -E '[a-zA-Z_][a-zA-Z0-9_]+ *[=;[({]' | tr -d '=;[({ ' \
  51. | grep -v -E '^(NULL$|sizeof$|CURLE_)' \
  52. | sort | uniq -c | sort -k 2 | grep -v -E '^ +1 ' \
  53. | awk '{print " \"" $2 "\","}'
  54. echo '---'
  55. # Extract list of macros that may be re-used by multiple tests.
  56. #
  57. # Picks up false-positive when the macro is defined to the same value everywhere.
  58. # shellcheck disable=SC2046
  59. grep -E '^ *# *define +' $(find libtest unit -maxdepth 1 -name 'lib*.c' -o -name 'unit*.c' -o -name 'mk-*.pl') \
  60. | grep -E '^(libtest|unit)/' \
  61. | grep -o -E '.+\.(c|pl): *# *define +[A-Z_][A-Z0-9_]+' | sort -u \
  62. | grep -o -E '[A-Z_][A-Z0-9_]+' \
  63. | sort | uniq -c | sort -k 2 | grep -v -E '^ +1 ' \
  64. | awk '{print " \"" $2 "\","}'
  65. if [ "$detect_in_reused_sources" = '1' ]; then
  66. # Delete symlinks for all re-used sources
  67. find libtest unit -type l -delete
  68. fi