scripts/mk-release.sh
author Daniel Zimmermann <netzimme@gmail.com>
Thu Jan 02 10:35:44 2014 +0100 (2014-01-02)
changeset 3266 84fcb0cae9a4
parent 2859 0afb64320510
permissions -rwxr-xr-x
libc/newlib: fix typo in "bump version to 2.1.0"

Fix a typo in the commit http://crosstool-ng.org/hg/crosstool-ng/rev/b966620c7b1e

Signed-off-by: "Daniel Zimmermann" netzimme@gmail.com
Message-Id: <f2dbd80da6affb11089a.1388669655@haus-VirtualBox>
Patchwork-Id: 306129
     1 #!/bin/bash
     2 #set -x
     3 
     4 export LC_ALL=C
     5 
     6 my_name="$( basename "${0}" )"
     7 
     8 usage() {
     9     cat <<-_EOF_
    10 		Usage:
    11 		    ${my_name} <repos_dir> <M.m.p>
    12 	_EOF_
    13 }
    14 
    15 repos="${1}"
    16 version="${2}"
    17 
    18 [ -n "${repos}"   ] || { usage; exit 1; }
    19 [ -d "${repos}"   ] || { printf "${my_name}: ${repos}: no such file or directory\n"; exit 1; }
    20 [ -n "${version}" ] || { usage; exit 1; }
    21 
    22 _hg() {
    23     HGPLAIN=1 hg --config progress.disabled=true "$@"
    24 }
    25 
    26 gen_bound_revs() {
    27     r1=$( _hg log   \
    28           |awk 'BEGIN {
    29                   found=0;
    30                 }
    31                 $1=="'"${label}"':" {
    32                   split($2,a,":"); rev=a[1];
    33                 }
    34                 $0~/^summary:[[:space:]]*[[:digit:]]+\.[[:digit:]]+: '"${msg}"'/ \
    35                 && found==0 {
    36                   printf( "%d\n", rev ); found=1;
    37                 }'
    38         )
    39 
    40     r2=$( _hg log -b "${branch}" \
    41           |awk '$1=="changeset:" {
    42                   split($2,a,":");
    43                   printf( "%d\n", a[1] );
    44                   nextfile;
    45                 }'
    46         )
    47 
    48     r1_log=$((r1+log_offset))
    49     if [ ${#r1_log} -gt ${#r2} ]; then
    50         rev_w=${#r1_log}
    51     else
    52         rev_w=${#r2}
    53     fi
    54 }
    55 
    56 print_intro_mail() {
    57     cat <<-_EOF_
    58 		Hello all!
    59 		
    60 		I'm pleased to announce the release of crosstool-NG ${version}!
    61 		
    62 		As usual, there has been quite a number of improvements, new features,
    63 		and bug fixes all around. The most notable changes are listed below:
    64 		
    65 		YEM:
    66 		YEM: PUT YOUR MESSAGE HERE
    67 		YEM:
    68 		
    69 		This marks the beginning of the ${ver_M}.${ver_m} maintenance branch, and the end of
    70 		the previous maintenance branch. As always, comments and suggestions
    71 		are most welcome!
    72 		
    73 		The release can be found at the following URLs:
    74 		Changelog: http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-${version}.changelog
    75 		Tarball:   http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-${version}.tar.bz2
    76 		Patches:   http://crosstool-ng.org/download/crosstool-ng/01-fixes/${version}/
    77 		
    78 		As a reminder, the home for crosstool-NG is:
    79 		http://crosstool-ng.org/
    80 		
    81 		Crosstool-NG also has a Freshmeat page:
    82 		http://freshmeat.net/projects/crosstool-ng
    83 	_EOF_
    84 }
    85 
    86 print_intro_changelog_full_release() {
    87     cat <<-_EOF_
    88 		crosstool-NG ${version} -- ${date}
    89 		
    90 		This is a feature-release. Significant changes are:
    91 		
    92 		YEM:
    93 		YEM: PUT YOUR MESSAGE HERE
    94 		YEM:
    95 	_EOF_
    96 }
    97 
    98 print_intro_changelog_bug_fix() {
    99     cat <<-_EOF_
   100 		crosstool-NG ${version} -- ${date}
   101 		
   102 		This is a bug-fix-only release.
   103 	_EOF_
   104 }
   105 
   106 print_author_stats() {
   107     printf "\nMany thanks to the people who contributed to this release:\n\n"
   108     prev_author=""
   109     template='{author|person}\n'
   110     _hg log -b "${branch}" -r "${r1_log}:${r2}"                 \
   111            --template "${template}"                             \
   112     |sed -r -e 's/"//g;'                                        \
   113     |awk -F '' '{
   114                   nb[$0]++;
   115                 }
   116                 END {
   117                   for( author in nb ) {
   118                     printf( "   %4d  %s\n", nb[author], author );
   119                   }
   120                 }'                                              \
   121     |sort -s -k1nr -k2
   122 }
   123 
   124 print_author_shortlog() {
   125     printf "\nHere is the per-author shortlog:\n"
   126     prev_author=""
   127     template='{author|person}|{rev}|{branches}|{desc|firstline}\n'
   128     _hg log -b "${branch}" -r "${r1_log}:${r2}"             \
   129            --template "${template}"                         \
   130     |awk -F '' '{
   131                   n=split( $0,a,"|" );
   132                   printf( "%s", gensub("\"","","g",a[1]) );
   133                   printf( "|%0*d", '${rev_w}', a[2] );
   134                   for(i=3;i<=n;i++) {
   135                     printf( "|%s", a[i] );
   136                   }
   137                   printf( "\n" );
   138                 }'                                          \
   139     |sort                                                   \
   140     |while read line; do
   141         author="$( echo "${line}" |cut -d \| -f 1 )"
   142         rev="$( echo "${line}" |cut -d \| -f 2 )"
   143         br="$( echo "${line}" |cut -d \| -f 3 )"
   144         desc="$( echo "${line}" |cut -d \| -f 4- )"
   145 
   146         case "${br}" in
   147             ${branch})  ;;
   148             [0-9]*.*)    continue;;
   149             *) ;;
   150         esac
   151 
   152         case "${desc}" in
   153             Merge.)                 continue;;
   154             *": close "*" branch"*) continue;;
   155 #           *\(merged\))            continue;;
   156         esac
   157 
   158         author="$( echo "${author}" |sed -r -e 's/"//g;' )"
   159 
   160         if [ ! "${prev_author}" = "${author}" ]; then
   161             printf "\n"
   162             printf "    ${author}:\n"
   163             prev_author="${author}"
   164         fi
   165         rev="$( echo "${rev}" |sed -r -e 's/^0*//;' )"
   166 
   167         printf "%s\n" "${desc}"     \
   168         |fmt -w 65                  \
   169         |(first=1; while read l; do
   170             if [ -n "${first}" ]; then
   171                 printf "        [%*d] %s\n" ${rev_w} ${rev} "${l}"
   172                 first=
   173             else
   174                 printf "         %*.*s  %s\n" ${rev_w} ${rev_w} '' "${l}"
   175             fi
   176         done)
   177     done
   178 }
   179 
   180 print_diffstat() {
   181     printf "\nThe diffstat follows:\n\n"
   182     _hg diff -r "${r1}:${r2}" --color=never \
   183     |diffstat -r 2 -p 1 -w 10               \
   184     |tail -n 1                              \
   185     |sed -r -e 's/^ */    /;'
   186 
   187     _hg diff -r "${r1}:${r2}" --color=never \
   188     |diffstat -f 1 -r 2 -p 1 -w 10          \
   189     |head -n -1                             \
   190     |while read file line; do
   191         if [ ${#file} -gt 57 ]; then
   192             file="$( echo "${file}" |sed -r -e 's/^(.{,24}).*(.{28})$/\1.....\2/;' )"
   193         fi
   194         printf "    %-57s %s\n" "${file}" "${line}"
   195     done
   196 }
   197 
   198 print_short_diffstat() {
   199     printf "\nThe short diffstat follows:\n\n"
   200 
   201     eval total=$(( $(
   202         _hg diff -r "${r1}:${r2}" --color=never "${i}"                              \
   203         |diffstat -r 2 -p 1 -w 10                                                   \
   204         |tail -n 1                                                                  \
   205         |sed -r -e 's/^[[:space:]]*[[:digit:]]+ files? changed(,[[:space:]]+|$)//;' \
   206                 -e 's/([[:digit:]]+)[^-\+]+\((-|\+)\)/\1/g;'                        \
   207                 -e 's/,//g; s/ /+/; s/^$/0/;'
   208     ) ))
   209     printf "    %-24.24s %5d(+/-)\n" "Total" ${total}
   210     others=${total}
   211 
   212     { for i in              \
   213         kconfig/            \
   214         patches/            \
   215         config/*/           \
   216         scripts/build/*/    \
   217         samples/            \
   218         ; do
   219         eval val=$(( $(
   220             _hg diff -r "${r1}:${r2}" --color=never "${i}"                              \
   221             |diffstat -r 2 -p 1 -w 10                                                   \
   222             |tail -n 1                                                                  \
   223             |sed -r -e 's/^[[:space:]]*[[:digit:]]+ files? changed(,[[:space:]]+|$)//;' \
   224                     -e 's/([[:digit:]]+)[^-\+]+\((-|\+)\)/\1/g;'                        \
   225                     -e 's/,//g; s/ /+/; s/^$/0/;'
   226         ) ))
   227         if [ ${val} -gt $((total/100)) ]; then
   228             printf "%d %s\n" $(((1000*val)/total)) "${i}"
   229             others=$((others-val))
   230         fi
   231     done; printf "%d Others\n" $(((1000*others)/total)); }  \
   232     |sort -nr                                               \
   233     |{ while read v i; do
   234         if [ "${i}" = "Others" ]; then
   235             others=${v}
   236         else
   237             printf "    %-24.24s %3d.%d%%\n" "${i}" $((v/10)) $((v%10))
   238         fi
   239        done; printf "    %-24.24s %3d.%d%%\n" "Others" $((others/10)) $((others%10)); }
   240 }
   241 
   242 ver_M="$( printf "${version}" |cut -d . -f 1 )"
   243 ver_m="$( printf "${version}" |cut -d . -f 2 )"
   244 ver_p="$( printf "${version}" |cut -d . -f 3 )"
   245 
   246 sob_line="$( printf "Signed-off-by: "; _hg debugconfig ui.username )"
   247 prefix="$(pwd)/crosstool-ng-${version}"
   248 pushd "${repos}" >/dev/null 2>&1
   249 
   250 printf "Checking for existing tag: "
   251 if _hg tags |grep -E '^'"crosstool-ng-${version}"'\>' >/dev/null; then
   252     printf "already tagged\n"
   253     exit 1
   254 fi
   255 printf "no\n"
   256 
   257 if [ ${ver_p} -eq 0 ]; then
   258     print_mail="yes"
   259     print_intro_changelog="print_intro_changelog_full_release"
   260     label="parent"
   261     msg="create maintenance branch, (update|bump) version to [[:digit:]]+"'\'".[[:digit:]]+"'\'".0"'$'
   262     branch="default"
   263     log_offset=0
   264 else
   265     print_mail="no"
   266     print_intro_changelog="print_intro_changelog_bug_fix"
   267     label="changeset"
   268     msg="(update|bump) version to ${ver_M}"'\'".${ver_m}"'\'".$((ver_p-1))"'\+hg$'
   269     branch="${ver_M}.${ver_m}"
   270     log_offset=1
   271 fi
   272 
   273 printf "Computing boundary revisions:"
   274 gen_bound_revs
   275 printf " %d:%d\n" ${r1} ${r2}
   276 
   277 printf "Tagging release:"
   278 _hg up "${branch}" >/dev/null
   279 if [ ${ver_p} -eq 0 ]; then
   280     printf " update version"
   281     _hg branch "${ver_M}.${ver_m}" >/dev/null
   282     echo "${version}" >".version"
   283     _msg="$( printf "%s.%s: create maintenance branch, update version to %s\n\n%s" \
   284                     "${ver_M}" "${ver_m}" "${version}" "${sob_line}"
   285            )"
   286     _hg ci -m "${_msg}"
   287 else
   288     printf " update version"
   289     echo "${version}" >".version"
   290     _msg="$( printf "%s.%s: update version to %s\n\n%s" \
   291                     "${ver_M}" "${ver_m}" "${version}" "${sob_line}"
   292            )"
   293     _hg ci -m "${_msg}"
   294 fi
   295 
   296 printf ", tag"
   297 _msg="$( printf "Tagging release %s\n\n%s" "${version}" "${sob_line}" )"
   298 _hg tag -m "${_msg}" crosstool-ng-${version}
   299 
   300 printf ", update version"
   301 echo "${version}+hg" >".version"
   302 _msg="$( printf "%s.%s: update version to %s+hg\n\n%s" \
   303                 "${ver_M}" "${ver_m}" "${version}" "${sob_line}"
   304        )"
   305 _hg ci -m "${_msg}"
   306 
   307 printf ", date"
   308 date="$( _hg log -r crosstool-ng-${version} --template '{date|isodate}\n'    \
   309          |sed -r -e 's/-|://g; s/ /./; s/ //;'                              \
   310        )"
   311 printf ", done.\n"
   312 
   313 if [ ${ver_p} -eq 0 ]; then
   314     printf "Generating release mail:"
   315     printf " intro"
   316     print_intro_mail        > "${prefix}.mail"
   317     printf ", stats"
   318     print_author_stats      >>"${prefix}.mail"
   319     printf ", shortlog"
   320     print_author_shortlog   >>"${prefix}.mail"
   321     printf ", diffstat"
   322     print_short_diffstat    >>"${prefix}.mail"
   323     printf ", done.\n"
   324 fi
   325 
   326 printf "Generating release changelog:"
   327 printf " intro"
   328 ${print_intro_changelog}    > "${prefix}.changelog"
   329 printf ", stats"
   330 print_author_stats          >>"${prefix}.changelog"
   331 printf ", shortlog"
   332 print_author_shortlog       >>"${prefix}.changelog"
   333 printf ", diffstat"
   334 print_diffstat              >>"${prefix}.changelog"
   335 printf ", done.\n"
   336 
   337 popd >/dev/null 2>&1
   338 
   339 printf "Creating tarball:"
   340 prefix="crosstool-ng-${version}"
   341 printf " extract"
   342 date="$( _hg log -R "${repos}" -r "${prefix}" --template '{date|rfc822date}\n' )"
   343 tmpdir="$( mktemp -d --tmpdir XXXXXX )"
   344 _hg archive --cwd "${repos}" -r "${prefix}" -X '.hg*' --type files "${tmpdir}/${prefix}"
   345 printf ", bootstrap"
   346 pushd "${tmpdir}/${prefix}" >/dev/null 2>&1
   347 ./bootstrap >/dev/null
   348 rm -rf autom4te.cache
   349 popd >/dev/null 2>&1
   350 printf ", tarball"
   351 tar cjf "$(pwd)/${prefix}.tar.bz2" -C "${tmpdir}" "${prefix}"
   352 rm -rf "${tmpdir}"
   353 printf ", sum"
   354 for s in md5 sha1 sha512; do
   355     ${s}sum "${prefix}.tar.bz2" >"${prefix}.tar.bz2.${s}"
   356 done
   357 printf ", touch"
   358 touch -d "${date}" "${prefix}"*
   359 printf ", done.\n"
   360 
   361 if [ ${ver_p} -eq 0 ]; then
   362     printf "\nAn editor will be launched for you to edit the mail.\n"
   363     read -p "Press enter when ready..." foo
   364     cp "${prefix}.mail"{,.orig}
   365     vi "${prefix}.mail"
   366     diff -du -U 1 "${prefix}.mail"{.orig,} |patch -p0 "${prefix}.changelog" >/dev/null
   367     rm -f "${prefix}".{mail,changelog}.orig
   368 fi
   369 
   370 printf "\nAn editor will be launched for you to review the changelog.\n"
   371 read -p "Press enter when ready..." foo
   372 vi "${prefix}.changelog"
   373 
   374 printf "\nNow, you can push the changes with:   hg push -R '${repos}'\n"