You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.6 KiB

  1. #!/bin/bash
  2. # Copyright 2021 Nick Brassel (@tzarc)
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. set -eEuo pipefail
  5. job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
  6. source_ref="0.11.0"
  7. dest_ref="develop"
  8. ignore_ref="master"
  9. unset skip_zero
  10. export SIZE_REGRESSION_EXECUTING=1
  11. function usage() {
  12. echo "Usage: $(basename "$0") [-h] [-j <jobs>] [-s <source>] [-d <dest>] [-n] planck/rev6:default"
  13. echo " -h : Shows this usage page."
  14. echo " -j <threads> : Change the number of threads to execute with. Defaults to \`$job_count\`."
  15. echo " -s <source> : Use source commit, branch, tag, or sha1 to start the search. Defaults to \`$source_ref\`."
  16. echo " -d <dest> : Use destination commit, branch, tag, or sha1 to end the search. Defaults to \`$dest_ref\`."
  17. echo " -i <ignore> : The branch to ignore refs from. Defaults to \`$ignore_ref\`."
  18. echo " -n : Skips printing changes if the delta is zero."
  19. exit 1
  20. }
  21. if [[ ${#} -eq 0 ]]; then
  22. usage
  23. exit 0
  24. fi
  25. unset cleanup_completed
  26. _internal_cleanup() {
  27. if [[ -z "${cleanup_completed:-}" ]] ; then
  28. echo
  29. echo
  30. echo 'Your git repository is in an indeterminate state!' >&2
  31. echo 'Make sure you swap to your intended branch.' >&2
  32. echo
  33. unset SIZE_REGRESSION_EXECUTING
  34. fi
  35. cleanup_completed=1
  36. }
  37. trap _internal_cleanup EXIT HUP INT
  38. while getopts "hj:s:d:i:n" opt "$@" ; do
  39. case "$opt" in
  40. h) usage; exit 0;;
  41. j) job_count="${OPTARG:-}";;
  42. s) source_ref="${OPTARG:-}";;
  43. d) dest_ref="${OPTARG:-}";;
  44. i) ignore_ref="${OPTARG:-}";;
  45. n) skip_zero=1;;
  46. \?) usage >&2; exit 1;;
  47. esac
  48. done
  49. # Work out the target board
  50. shift $((OPTIND-1))
  51. keyboard_target=$1
  52. # Helper for resetting submodule existence
  53. fixup_submodules() {
  54. [ -e lib/ugfx ] && rm -rf lib/ugfx
  55. [ -e lib/pico-sdk ] && rm -rf lib/pico-sdk
  56. [ -e lib/chibios-contrib/ext/mcux-sdk ] && rm -rf lib/chibios-contrib/ext/mcux-sdk
  57. [ -e lib/lvgl ] && rm -rf lib/lvgl
  58. make git-submodule
  59. }
  60. last_size=0
  61. last_line=""
  62. function build_executor() {
  63. git rev-list --oneline --no-merges ${source_ref}...${dest_ref} ^${ignore_ref} | while IFS= read -r line ; do
  64. revision=$(echo $line | cut -d' ' -f1)
  65. make distclean >/dev/null 2>&1
  66. git checkout -f $revision >/dev/null 2>&1 || { echo "Failed to check out revision ${revision}" >&2 ; exit 1 ; }
  67. fixup_submodules >/dev/null 2>&1
  68. make -j${job_count} $keyboard_target >/dev/null 2>&1 || true
  69. file_size=$(arm-none-eabi-size .build/*.elf 2>/dev/null | awk '/elf/ {print $1}' 2>/dev/null || true)
  70. if [[ "$last_size" == 0 ]] ; then last_size=$file_size ; fi
  71. if [[ -z "$file_size" ]] ; then file_size=0 ; fi
  72. if [[ -n "$last_line" ]] ; then
  73. size_delta=$(( $last_size - $file_size ))
  74. if { [[ -n "${skip_zero:-}" ]] && [[ $size_delta -ne 0 ]] ; } || [[ -z "${skip_zero:-}" ]] || [[ $file_size -eq 0 ]] ; then
  75. printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line"
  76. fi
  77. fi
  78. last_size=$file_size
  79. last_line=$line
  80. done
  81. if [ -n "$last_line" ] ; then
  82. size_delta=0
  83. printf "Size: %8d, delta: %+6d -- %s\n" "$last_size" "$size_delta" "$last_line"
  84. fi
  85. }
  86. # The actual execution of all the builds needs to be the last command in the entire script
  87. # - During builds, this script file will disappear, so we need the entire script to be
  88. # loaded into the script interpreter at the time of execution. Do not refactor.
  89. build_executor