blob: d12bc0468344469d5e88b305e96f859f6ba7f081 [file] [log] [blame]
Martin Rothbec11082015-11-03 21:01:53 -07001#!/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
18TOP=$(pwd)
19MAIN_LOGFILE="${TOP}/relnotes.txt"
20
21#check for tools
22( git --version && cloc --version ) > /dev/null 2>&1
23if [ $? -ne 0 ]; then
24 echo "ERROR: cloc or git is not installed. Exiting"
25 exit 1
26fi
27
28#verify that the repo is clean before losing state.
29git diff-index --quiet --cached HEAD
30if [ $? -ne 0 ] || [ "$(git diff --shortstat 2> /dev/null | tail -n1)" != "" ]; then
31 echo "ERROR: repo is not clean. Exiting."
32 exit 1
33fi
34
35#verify command line arguments
36if [ -z "$1" ] || [ -z "$2" ]; then
37echo
38echo "Usage: $0 <old_version> <new_version>"
39echo "Old version should be a tag (4.1), a branch (origin/4.1), or a commit id"
40echo "New version can be 'HEAD' a branch (origin/master) a tag (4.2), or a commit id"
41echo "Example: \"$0 origin/4.1 4.2\""
42echo
43exit 1
44else
45 OLD_COREBOOT_VERSION="$1"
46 NEW_COREBOOT_VERSION="$2"
47fi
48
49#Figure out which logfile we're writing to.
50if [ -f "$MAIN_LOGFILE" ]; then
51 LOGFILE="$(mktemp "LOGFILE.XXXX")"
52 LOGFILE="${TOP}/$LOGFILE"
53 UPDATE_MAIN_LOGFILE=1
54else
55 LOGFILE="$MAIN_LOGFILE"
56fi
57
58#print and log the versions
59log_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
68get_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.
89get_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
109get_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.
131version_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
141trap version_ctrl_c SIGINT
142
143mainboard_list_new="$(mktemp "LOGFILE.XXXX")"
144mainboard_list_old="$(mktemp "LOGFILE.XXXX")"
145
146#check out old version and get information
147printf -- "Finding old submodule versions...\n"
148git checkout "$OLD_COREBOOT_VERSION" > /dev/null 2>&1
149git submodule update --init --checkout > /dev/null 2>&1
150BLOBS_OLD_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/blobs")
151VBOOT_OLD_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/vboot")
152ARM_OLD_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/arm-trusted-firmware")
153NVIDIA_OLD_VERSION=$(get_latest_commit_id "${TOP}/util/nvidia/cbootimage")
154find '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
156printf "Calculating old SLOC\n"
157find 'src' -name 'Makefile.inc' -exec rename 's/Makefile\.inc/gnumakefile/' {} \;
158OLD_SLOC=$(cloc --progress-rate=0 --quiet --script-lang="Bourne Shell",bash --force-lang=c,inc --exclude-dir=vendorcode src)
159find 'src' -name 'gnumakefile' -exec rename 's/gnumakefile/Makefile\.inc/' {} \;
160
161#check out new version and get information
162printf -- "\nFinding new submodule versions...\n"
163git checkout "$NEW_COREBOOT_VERSION" > /dev/null 2>&1
164git submodule update --init --checkout > /dev/null 2>&1
165BLOBS_NEW_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/blobs")
166VBOOT_NEW_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/vboot")
167ARM_NEW_VERSION=$(get_latest_commit_id "${TOP}/3rdparty/arm-trusted-firmware")
168NVIDIA_NEW_VERSION=$(get_latest_commit_id "${TOP}/util/nvidia/cbootimage")
169find 'src/mainboard' -name 'Kconfig.name' | sed 's|/Kconfig.name||' | sed 's|src/mainboard/|- |' | grep '/' | sort > "$mainboard_list_new"
170printf "Calculating new SLOC\n"
171find 'src' -name 'Makefile.inc' -exec rename 's/Makefile\.inc/gnumakefile/' {} \;
172NEW_SLOC=$(cloc --progress-rate=0 --quiet --script-lang="Bourne Shell",bash --force-lang=c,inc --exclude-dir=vendorcode src)
173find 'src' -name 'gnumakefile' -exec rename 's/gnumakefile/Makefile\.inc/' {} \;
174
175new_mainboards=$(grep -Fxv -f "$mainboard_list_old" "$mainboard_list_new")
176removed_mainboards=$(grep -Fxv -f "$mainboard_list_new" "$mainboard_list_old")
177
178git checkout origin/master > /dev/null 2>&1
179git submodule update --init --checkout > /dev/null 2>&1
180rm -f "$mainboard_list_old" "$mainboard_list_new"
181trap "" SIGINT
182
183#start outputting to logfile
184echo "Generating release notes from version ${OLD_COREBOOT_VERSION} to ${NEW_COREBOOT_VERSION}"
185echo; echo "Main coreboot repo"
186echo "Main coreboot repo" >> "$LOGFILE"
187echo "------------------" >> "$LOGFILE"
188log_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
190NOW=$(date -u)
191( echo "$NOW"; echo ) >> "$LOGFILE"
192
193#first get things that are generally outside the mainboards and architectures
194get_log_dedupe "Build system" "Makefile Makefile.inc toolchain.inc src/Kconfig src/cpu/Makefile.inc"
195get_log_dedupe "Utilities" "util/"
196get_log_dedupe "Documentation" "Documentation/ README"
197get_log_dedupe "Payloads" "payloads/"
198get_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
202get_log_dedupe "Mainboards" "src/mainboard/"
203
204#Get architectures 3rd so separate the various pieces out
205get_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$')"
206get_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$')"
207get_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"
208get_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
211get_log_dedupe "ACPI" "src/acpi/"
212get_log_dedupe "Console" "src/console/ src/include/console"
213get_log_dedupe "SuperIO" "src/superio/ src/include/superio"
214get_log_dedupe "EC " "src/ec"
215get_log_dedupe "Drivers" "src/drivers/"
216get_log_dedupe "Devices" "src/device/ src/include/device"
217get_log_dedupe "Lib" "src/lib/"
218get_log_dedupe "Commonlib" "src/commonlib/"
219get_log_dedupe "Include" "src/include/"
220
221#Last, get anything that was missed above
222get_log_dedupe "MISC" "."
223
224if [ -n "$new_mainboards" ]; then
225 printf "Added %s mainboards:\n-------------------\n%s\n\n" "$(echo "$new_mainboards" | wc -l)" "$new_mainboards" >> "$LOGFILE"
226fi
227
228if [ -n "$removed_mainboards" ]; then
229 printf "Removed %s mainboards:\n---------------------\n%s\n\n" "$(echo "$removed_mainboards" | wc -l)" "$removed_mainboards" >> "$LOGFILE"
230fi
231
232# log submodules
233printf "Submodules\n----------\n" >> "$LOGFILE"
234get_log_submodule "$BLOBS_OLD_VERSION" "$BLOBS_NEW_VERSION" "3rdparty/blobs"
235get_log_submodule "$ARM_OLD_VERSION" "$ARM_NEW_VERSION" "3rdparty/arm-trusted-firmware"
236get_log_submodule "$VBOOT_OLD_VERSION" "$VBOOT_NEW_VERSION" "3rdparty/vboot"
237get_log_submodule "$NVIDIA_OLD_VERSION" "$NVIDIA_NEW_VERSION" "util/nvidia/cbootimage"
238
239printf "\ncoreboot statistics\n-------------------\n" >> "$LOGFILE"
240NEW_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)
241TOTAL_COMMITS=$(git log --pretty=oneline "${1}..${2}" | wc -l)
242printf -- "- 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
249printf -- "- New authors: %s\n" "$NEW_AUTHORS" >> "$LOGFILE"
250printf -- "- 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"
251printf -- "- 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
253printf "\nOld SLOC (%s)\n%s" "$NOW" "$OLD_SLOC" >> "$LOGFILE"
254printf "\nNew SLOC (%s)\n%s" "$NOW" "$NEW_SLOC" >> "$LOGFILE"
255
256# Add the collected data to the top of the existing logfile for parsing
257if [ -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"
264fi