Martin Roth | bec1108 | 2015-11-03 21:01:53 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # This file is part of the coreboot project. |
| 4 | # |
| 5 | # Copyright 2015 Google Inc. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; version 2 of the License. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | |
| 16 | #set -x # uncomment for debug |
| 17 | |
| 18 | TOP=$(pwd) |
| 19 | MAIN_LOGFILE="${TOP}/relnotes.txt" |
| 20 | |
| 21 | #check for tools |
| 22 | ( git --version && cloc --version ) > /dev/null 2>&1 |
| 23 | if [ $? -ne 0 ]; then |
| 24 | echo "ERROR: cloc or git is not installed. Exiting" |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | #verify that the repo is clean before losing state. |
| 29 | git diff-index --quiet --cached HEAD |
| 30 | if [ $? -ne 0 ] || [ "$(git diff --shortstat 2> /dev/null | tail -n1)" != "" ]; then |
| 31 | echo "ERROR: repo is not clean. Exiting." |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | #verify command line arguments |
| 36 | if [ -z "$1" ] || [ -z "$2" ]; then |
| 37 | echo |
| 38 | echo "Usage: $0 <old_version> <new_version>" |
| 39 | echo "Old version should be a tag (4.1), a branch (origin/4.1), or a commit id" |
| 40 | echo "New version can be 'HEAD' a branch (origin/master) a tag (4.2), or a commit id" |
| 41 | echo "Example: \"$0 origin/4.1 4.2\"" |
| 42 | echo |
| 43 | exit 1 |
| 44 | else |
| 45 | OLD_COREBOOT_VERSION="$1" |
| 46 | NEW_COREBOOT_VERSION="$2" |
| 47 | fi |
| 48 | |
| 49 | #Figure out which logfile we're writing to. |
| 50 | if [ -f "$MAIN_LOGFILE" ]; then |
| 51 | LOGFILE="$(mktemp "LOGFILE.XXXX")" |
| 52 | LOGFILE="${TOP}/$LOGFILE" |
| 53 | UPDATE_MAIN_LOGFILE=1 |
| 54 | else |
| 55 | LOGFILE="$MAIN_LOGFILE" |
| 56 | fi |
| 57 | |
| 58 | #print and log the versions |
| 59 | log_versions() { |
| 60 | echo "Log of commit $1 to commit $2" |
| 61 | echo "Log of commit $1 to commit $2" >> "$LOGFILE" |
| 62 | echo "Total commits: $(git log "${1}..${2}" | grep -c '^commit ' )" |
| 63 | echo "Total commits: $(git log "${1}..${2}" | grep -c '^commit ' )" >> "$LOGFILE" |
| 64 | echo |
| 65 | } |
| 66 | |
| 67 | #get the first commit id in the current tree |
| 68 | get_latest_commit_id() { |
| 69 | pushd "$1" > /dev/null |
| 70 | git log | grep '^commit ' | head -1 | sed 's/commit //' |
| 71 | popd > /dev/null |
| 72 | } |
| 73 | |
| 74 | #main get log function |
| 75 | _get_log() { |
| 76 | local oldver="$1" |
| 77 | local newver="$2" |
| 78 | local title="$3" |
| 79 | local paths="$4" |
| 80 | |
| 81 | #Leave ${paths} unquoted |
| 82 | git log --abbrev-commit --pretty=oneline "${oldver}..${newver}" -- ${paths} | \ |
| 83 | sort -t ' ' -k 2 | \ |
| 84 | uniq |
| 85 | } |
| 86 | |
| 87 | #output to a new log, then compare to the first logfile, and only output |
| 88 | #non duplicated lines to the final file. |
| 89 | get_log_dedupe() { |
| 90 | local title="$1" |
| 91 | local paths="$2" |
| 92 | dedupe_tmpfile="$(mktemp "LOGFILE.XXXX")" |
| 93 | |
| 94 | local log=$(_get_log "$OLD_COREBOOT_VERSION" "$NEW_COREBOOT_VERSION" "$title" "$paths") |
| 95 | |
| 96 | echo "$log" > "$dedupe_tmpfile" |
| 97 | |
| 98 | log=$(grep -Fxv -f "$LOGFILE" "$dedupe_tmpfile") |
| 99 | local commits=$(echo "$log" | wc -l) |
| 100 | |
| 101 | if [ -n "$log" ]; then |
| 102 | printf "%s\n%s\n\n" "$title ($commits commits)" "$log" >> "$LOGFILE" |
| 103 | fi |
| 104 | |
| 105 | rm "$dedupe_tmpfile" |
| 106 | } |
| 107 | |
| 108 | # get logs for the submodules |
| 109 | get_log_submodule() { |
| 110 | local old_version="$1" |
| 111 | local new_version="$2" |
| 112 | local submodule_dir="$3" |
| 113 | |
| 114 | printf "Submodule %s\n" "$submodule_dir" |
| 115 | printf "commit %s to commit %s\n\n" "$old_version" "$new_version" |
| 116 | |
| 117 | pushd "${TOP}/$submodule_dir" > /dev/null |
| 118 | local log=$(_get_log "$old_version" "$new_version" "$submodule_dir" ".") |
| 119 | local commits=$(echo "$log" | wc -l) |
| 120 | |
| 121 | if [ -n "$log" ]; then |
| 122 | printf "%s\n%s\n\n" "$submodule_dir ($commits commits)" "$log" >> "$LOGFILE" |
| 123 | fi |
| 124 | |
| 125 | popd > /dev/null |
| 126 | } |
| 127 | |
| 128 | #make sure things get cleaned up if ctl-c is pressed while the old version |
| 129 | #is checked out and files are renamed. This can be a real mess to clean |
| 130 | #up manually. |
| 131 | version_ctrl_c() { |
| 132 | printf "\n** Trapped CTRL-C\n Cleaning up and exiting." |
| 133 | find 'src' -name 'gnumakefile' -exec rename 's/gnumakefile/Makefile\.inc/' {} \; |
| 134 | git checkout origin/master > /dev/null 2>&1 |
| 135 | git submodule update --init --checkout > /dev/null 2>&1 |
| 136 | rm -f "$mainboard_list_old" "$mainboard_list_new" |
| 137 | rm "$LOGFILE" |
| 138 | exit 1; |
| 139 | } |
| 140 | |
| 141 | trap version_ctrl_c SIGINT |
| 142 | |
| 143 | mainboard_list_new="$(mktemp "LOGFILE.XXXX")" |
| 144 | mainboard_list_old="$(mktemp "LOGFILE.XXXX")" |
| 145 | |
| 146 | #check out old version and get information |
| 147 | printf -- "Finding old submodule versions...\n" |
| 148 | git checkout "$OLD_COREBOOT_VERSION" > /dev/null 2>&1 |
| 149 | git submodule update --init --checkout > /dev/null 2>&1 |
| 150 | BLOBS_OLD_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/blobs") |
| 151 | VBOOT_OLD_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/vboot") |
| 152 | ARM_OLD_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/arm-trusted-firmware") |
| 153 | NVIDIA_OLD_VERSION=$(get_latest_commit_id "${TOP}/util/nvidia/cbootimage") |
| 154 | find 'src/mainboard' -name 'Kconfig.name' | sed 's|/Kconfig.name||' | sed 's|src/mainboard/|- |' | grep '/' | sort > "$mainboard_list_old" |
| 155 | #because cloc works on extensions, and .inc identifies as pascal, rename Makefile.inc, then remap the other .inc files to c |
| 156 | printf "Calculating old SLOC\n" |
| 157 | find 'src' -name 'Makefile.inc' -exec rename 's/Makefile\.inc/gnumakefile/' {} \; |
| 158 | OLD_SLOC=$(cloc --progress-rate=0 --quiet --script-lang="Bourne Shell",bash --force-lang=c,inc --exclude-dir=vendorcode src) |
| 159 | find 'src' -name 'gnumakefile' -exec rename 's/gnumakefile/Makefile\.inc/' {} \; |
| 160 | |
| 161 | #check out new version and get information |
| 162 | printf -- "\nFinding new submodule versions...\n" |
| 163 | git checkout "$NEW_COREBOOT_VERSION" > /dev/null 2>&1 |
| 164 | git submodule update --init --checkout > /dev/null 2>&1 |
| 165 | BLOBS_NEW_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/blobs") |
| 166 | VBOOT_NEW_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/vboot") |
| 167 | ARM_NEW_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/arm-trusted-firmware") |
| 168 | NVIDIA_NEW_VERSION=$(get_latest_commit_id "${TOP}/util/nvidia/cbootimage") |
| 169 | find 'src/mainboard' -name 'Kconfig.name' | sed 's|/Kconfig.name||' | sed 's|src/mainboard/|- |' | grep '/' | sort > "$mainboard_list_new" |
| 170 | printf "Calculating new SLOC\n" |
| 171 | find 'src' -name 'Makefile.inc' -exec rename 's/Makefile\.inc/gnumakefile/' {} \; |
| 172 | NEW_SLOC=$(cloc --progress-rate=0 --quiet --script-lang="Bourne Shell",bash --force-lang=c,inc --exclude-dir=vendorcode src) |
| 173 | find 'src' -name 'gnumakefile' -exec rename 's/gnumakefile/Makefile\.inc/' {} \; |
| 174 | |
| 175 | new_mainboards=$(grep -Fxv -f "$mainboard_list_old" "$mainboard_list_new") |
| 176 | removed_mainboards=$(grep -Fxv -f "$mainboard_list_new" "$mainboard_list_old") |
| 177 | |
| 178 | git checkout origin/master > /dev/null 2>&1 |
| 179 | git submodule update --init --checkout > /dev/null 2>&1 |
| 180 | rm -f "$mainboard_list_old" "$mainboard_list_new" |
| 181 | trap "" SIGINT |
| 182 | |
| 183 | #start outputting to logfile |
| 184 | echo "Generating release notes from version ${OLD_COREBOOT_VERSION} to ${NEW_COREBOOT_VERSION}" |
| 185 | echo; echo "Main coreboot repo" |
| 186 | echo "Main coreboot repo" >> "$LOGFILE" |
| 187 | echo "------------------" >> "$LOGFILE" |
| 188 | log_versions "$(git log --pretty=%H "${OLD_COREBOOT_VERSION}..${NEW_COREBOOT_VERSION}" | tail -1)" "$(git log --pretty=%H "${OLD_COREBOOT_VERSION}..${NEW_COREBOOT_VERSION}" | head -1 )" |
| 189 | |
| 190 | NOW=$(date -u) |
| 191 | ( echo "$NOW"; echo ) >> "$LOGFILE" |
| 192 | |
| 193 | #first get things that are generally outside the mainboards and architectures |
| 194 | get_log_dedupe "Build system" "Makefile Makefile.inc toolchain.inc src/Kconfig src/cpu/Makefile.inc" |
| 195 | get_log_dedupe "Utilities" "util/" |
| 196 | get_log_dedupe "Documentation" "Documentation/ README" |
| 197 | get_log_dedupe "Payloads" "payloads/" |
| 198 | get_log_dedupe "Vendorcode" "src/vendorcode/" |
| 199 | |
| 200 | # get mainboards 2nd so that changes that are mainboard specific don't get |
| 201 | # grabbed by the architectures |
| 202 | get_log_dedupe "Mainboards" "src/mainboard/" |
| 203 | |
| 204 | #Get architectures 3rd so separate the various pieces out |
| 205 | get_log_dedupe "ARM" "$(for codedir in $(grep -rl "_ARM" --include=Kconfig | grep -v 'src/mainboard\|payloads/\|drivers/\|vendorcode/\|console' ) ; do dirname "$codedir"; done | grep -v '^src$')" |
| 206 | get_log_dedupe "RISC-V" "$(for codedir in $(grep -rl "_RISCV" --include=Kconfig | grep -v 'src/mainboard\|payloads/\|drivers/\|vendorcode/\|console' ) ; do dirname "$codedir"; done | grep -v '^src$')" |
| 207 | get_log_dedupe "X86" "src/arch/x86 src/cpu/x86 src/cpu/intel src/soc/intel src/cpu/amd src/northbridge/intel src/northbridge/amd src/southbridge/intel src/southbridge/amd src/drivers/intel/fsp1_0 src/drivers/intel/fsp1_1 src/include/amd src/include/intel src/include/x86 src/include/pc80" |
| 208 | get_log_dedupe "MIPS" "$(for codedir in $(grep -rl "_MIPS" --include=Kconfig | grep -v 'src/mainboard\|payloads/\|drivers/\|vendorcode/\|console' ) ; do dirname "$codedir"; done | grep -v '^src$')" |
| 209 | |
| 210 | #4th, get all the rest of the specific areas |
| 211 | get_log_dedupe "ACPI" "src/acpi/" |
| 212 | get_log_dedupe "Console" "src/console/ src/include/console" |
| 213 | get_log_dedupe "SuperIO" "src/superio/ src/include/superio" |
| 214 | get_log_dedupe "EC " "src/ec" |
| 215 | get_log_dedupe "Drivers" "src/drivers/" |
| 216 | get_log_dedupe "Devices" "src/device/ src/include/device" |
| 217 | get_log_dedupe "Lib" "src/lib/" |
| 218 | get_log_dedupe "Commonlib" "src/commonlib/" |
| 219 | get_log_dedupe "Include" "src/include/" |
| 220 | |
| 221 | #Last, get anything that was missed above |
| 222 | get_log_dedupe "MISC" "." |
| 223 | |
| 224 | if [ -n "$new_mainboards" ]; then |
| 225 | printf "Added %s mainboards:\n-------------------\n%s\n\n" "$(echo "$new_mainboards" | wc -l)" "$new_mainboards" >> "$LOGFILE" |
| 226 | fi |
| 227 | |
| 228 | if [ -n "$removed_mainboards" ]; then |
| 229 | printf "Removed %s mainboards:\n---------------------\n%s\n\n" "$(echo "$removed_mainboards" | wc -l)" "$removed_mainboards" >> "$LOGFILE" |
| 230 | fi |
| 231 | |
| 232 | # log submodules |
| 233 | printf "Submodules\n----------\n" >> "$LOGFILE" |
| 234 | get_log_submodule "$BLOBS_OLD_VERSION" "$BLOBS_NEW_VERSION" "3rdparty/blobs" |
| 235 | get_log_submodule "$ARM_OLD_VERSION" "$ARM_NEW_VERSION" "3rdparty/arm-trusted-firmware" |
| 236 | get_log_submodule "$VBOOT_OLD_VERSION" "$VBOOT_NEW_VERSION" "3rdparty/vboot" |
| 237 | get_log_submodule "$NVIDIA_OLD_VERSION" "$NVIDIA_NEW_VERSION" "util/nvidia/cbootimage" |
| 238 | |
| 239 | printf "\ncoreboot statistics\n-------------------\n" >> "$LOGFILE" |
| 240 | NEW_AUTHORS=$(git log --pretty=%an "${OLD_COREBOOT_VERSION}" | sort | uniq > before_names.txt && git log --pretty=%an | sort | uniq > after_names.txt && grep -Fxv -c -f before_names.txt after_names.txt && rm before_names.txt after_names.txt) |
| 241 | TOTAL_COMMITS=$(git log --pretty=oneline "${1}..${2}" | wc -l) |
| 242 | printf -- "- Total commits: %s\n" "$TOTAL_COMMITS" >> "$LOGFILE" |
| 243 | |
| 244 | #TODO: Fix days between releases - between two branches or tags works well, between individual patches works poorly, as we get the creation date of the patch, not the merge date. |
| 245 | #DAYS_BETWEEN_RELEASES=$(( ( $(date -ud "$(git show "$NEW_COREBOOT_VERSION" | grep -m 1 '^Date: ' | sed 's/Date:[[:space:]]*//' | sed 's/[+-].*//g')" +'%s') - $(date -ud "$(git show "$OLD_COREBOOT_VERSION" | grep -m 1 '^Date: ' | sed 's/Date:[[:space:]]*//' | sed 's/[+-].*//g')" +'%s') ) /60/60/24 )) |
| 246 | #AVERAGE_COMMITS=$((TOTAL_COMMITS / DAYS_BETWEEN_RELEASES)) |
| 247 | #printf "- Average daily commits: %s\n" "$AVERAGE_COMMITS" |
| 248 | |
| 249 | printf -- "- New authors: %s\n" "$NEW_AUTHORS" >> "$LOGFILE" |
| 250 | printf -- "- Total authors: %s\n" "$(git log "${OLD_COREBOOT_VERSION}..${NEW_COREBOOT_VERSION}" | grep -e '^Author:' | sed 's/.*Author: //' | sed 's/ <.*.>//' | sort | uniq | wc -l)" >> "$LOGFILE" |
| 251 | printf -- "- Reviewers on submitted patches: %s\n" "$(git log "${OLD_COREBOOT_VERSION}..${NEW_COREBOOT_VERSION}" | grep -e '^ *Reviewed-by: ' | sed 's/.*Reviewed-by: //' | sed 's/ <.*.>//' | sort | uniq | wc -l)" >> "$LOGFILE" |
| 252 | |
| 253 | printf "\nOld SLOC (%s)\n%s" "$NOW" "$OLD_SLOC" >> "$LOGFILE" |
| 254 | printf "\nNew SLOC (%s)\n%s" "$NOW" "$NEW_SLOC" >> "$LOGFILE" |
| 255 | |
| 256 | # Add the collected data to the top of the existing logfile for parsing |
| 257 | if [ -n "$UPDATE_MAIN_LOGFILE" ]; then |
| 258 | tmpfile="$(mktemp "LOGFILE.XXXX")" |
| 259 | grep -Fxv -f "$MAIN_LOGFILE" "$LOGFILE" > "$tmpfile" |
| 260 | printf "\n\n" >> "$tmpfile" |
| 261 | cat "$MAIN_LOGFILE" >> "$tmpfile" |
| 262 | mv "$tmpfile" "$MAIN_LOGFILE" |
| 263 | rm -f "$LOGFILE" |
| 264 | fi |