github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/debian/helpers/uscan-summary.sh (about)

     1  #!/bin/bash
     2  
     3  # Read the logs from uscan + get-orig-source, and display
     4  # the list of Files-Excluded patterns that were not matched
     5  # in any of the MUT components.
     6  #
     7  # Typical use-case: after bumping the package to a new version,
     8  # run it to see which Files-Excluded patterns are now useless.
     9  # You might want to remove those from the Files-Excluded list,
    10  # and possibly remove their equivalent packages from the
    11  # Build-Depends field.
    12  #
    13  # Usage:
    14  #
    15  #     uscan --verbose --download-current-version 2>&1 | tee uscan-logs
    16  #     ./debian/helpers/uscan-summary.sh < uscan-logs
    17  #
    18  # Copyright: Arnaud Rebillout <elboulangero@gmail.com>
    19  # License: GPL-3+
    20  
    21  set -e
    22  set -u
    23  
    24  export LC_ALL=C
    25  
    26  ## key: component
    27  ## value: newline-separated list of unmatched patterns
    28  declare -A COMPONENTS
    29  
    30  assert_empty() {
    31      [ -z "$1" ] || exit 1
    32  }
    33  
    34  assert_nonempty() {
    35      [ -n "$1" ] || exit 1
    36  }
    37  
    38  comp=
    39  
    40  ## read uscan logs, get unmatched patterns for each component
    41  while IFS= read -r line
    42  do
    43      case "$line" in
    44          ('uscan info: Process watch file'*)
    45              assert_empty "$comp"
    46              comp=engine
    47              continue
    48              ;;
    49          ('get-orig-source info: Process'*)
    50              assert_nonempty "$comp"
    51              comp=
    52              continue
    53              ;;
    54          ('    component = '*)
    55              assert_empty "$comp"
    56              comp=$(echo "$line" | sed 's/.* = //')
    57              continue
    58              ;;
    59          (*'No files matched excluded pattern'*)
    60              pattern=$(echo "$line" | sed 's/.* excluded pattern .*: //')
    61              [ -n "${COMPONENTS[$comp]:-}" ] && COMPONENTS[$comp]+=$'\n'
    62              COMPONENTS[$comp]+="$pattern"
    63              continue
    64              ;;
    65      esac
    66  done < /dev/stdin
    67  
    68  #for comp in "${!COMPONENTS[@]}"; do
    69  #    echo "==== ${comp^^} ===="
    70  #    echo "${COMPONENTS[$comp]}"
    71  #    echo ""
    72  #done
    73  
    74  ## get unmatched patterns altogether, while removing the
    75  ## patterns with '~', as we expect those to be unmatched.
    76  ALL_UNMATCHED_PATTERNS=$(printf '%s\n' ${COMPONENTS[@]} | grep -v '^~' | sort -u)
    77  
    78  ## useless patterns are those unmatched for all components
    79  USELESS_PATTERNS=
    80  for p in $ALL_UNMATCHED_PATTERNS; do
    81      useless=1
    82      for c in "${!COMPONENTS[@]}"; do
    83          if echo "${COMPONENTS[$c]}" | grep -qFx "$p"; then
    84              continue
    85          else
    86              useless=0
    87              break
    88          fi
    89      done
    90      if [ $useless -eq 1 ]; then
    91          [ -n "${USELESS_PATTERNS}" ] && USELESS_PATTERNS+=$'\n'
    92          USELESS_PATTERNS+="$p"
    93      fi
    94  done
    95  
    96  if [ -z "$USELESS_PATTERNS" ]; then
    97      echo "No useless patterns found in Files-Excluded. All good here."
    98  else
    99      echo "The following patterns were not found in any of the MUT components."
   100      echo "They can probably be removed from Files-Excluded in d/copyright."
   101      echo
   102      echo "$USELESS_PATTERNS"
   103  fi
   104  
   105  # vim: et sts=4 sw=4