From 26b01c58d18bde9c7c2385f40c0d5e13d5c5650b Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 04 Jan 2021 18:22:26 -0500 Subject: cmd/build: Add more information to build log --- diff --git a/NEWS b/NEWS index a90add1..355277b 100644 --- a/NEWS +++ b/NEWS @@ -23,7 +23,8 @@ New features: field. * "prokit installer-pc" now supports foreign installations using an "-F" option. - * "prokit build" now saves logs of builds. + * "prokit build" now saves logs of builds and prints detailed + information about the build and its results. Error handling and bug fixes: diff --git a/src/cmd/build.sh b/src/cmd/build.sh index dab9964..e254abe 100644 --- a/src/cmd/build.sh +++ b/src/cmd/build.sh @@ -22,6 +22,37 @@ _cmd_build_root= _cmd_build_pkg_dir= _cmd_build_build_deps= +_cmd_build_header() +{ + local underline="${1}" + local fmt="${2}" + shift 2 + + printf "\\n${fmt}\\n" "${@}" + printf "${fmt}\\n\\n" "${@}" | sed "s|.|${underline}|g" + + return 0 +} + +_cmd_build_time() +{ + # Based on code from by Rich + # Felker, with whitespace added for readability. + printf '%d' $(($(TZ=UTC0 date "+ + ( + (%Y - 1600) * 365 + + (%Y - 1600) / 4 + - (%Y - 1600) / 100 + + (%Y - 1600) / 400 + + 1%j - 1000 + - 135140 + ) * 86400 + + (1%H - 100) * 3600 + + (1%M - 100) * 60 + + (1%S - 100)"))) + return 0 +} + _cmd_build_make_deps_pkg() { local pkg_dir= @@ -70,13 +101,38 @@ _cmd_build_fini() _cmd_build_build() { - local host_arch="${1}" - local host_plat="${2}" - shift 2 + local build_arch="${1}" + local build_plat="${2}" + local host_arch="${3}" + local host_plat="${4}" + local dist="${5}" + shift 5 + local build_date= local es= + local changes= + local opk= + local build_time= + + build_date="$(LC_ALL='C' date '+%a, %d %b %Y %H:%M:%S %z')" + build_time=$(_cmd_build_time) + + printf '%s (%s) %s\n' "${0##*/}" "${PACKAGE_NAME}" "${PACKAGE_VERSION}" + _cmd_build_header '=' '%-47s %31s' \ + "${source} (${version})" "${build_date}" + + cat <<-EOF + Source: ${source} + Version: ${version} + Build-Architecture: ${build_arch} + Host-Architecture: ${host_arch} + Host-Platform: ${host_plat} + Distribution: ${dist} + Build-Date: ${build_date} + EOF es=0 + _cmd_build_header '-' 'Install Build Dependencies' _cmd_build_build_deps="$(package_get_build_deps \ "${host_arch}" "${host_plat}")" if [ "x${_cmd_build_build_deps}" != 'x' ]; then @@ -90,12 +146,53 @@ _cmd_build_build() fi fi + _cmd_build_header '-' 'Installed Packages' + session_exec opkg list-installed || es=${?} + + _cmd_build_header '-' 'Build' if [ ${es} -eq 0 ]; then session_exec opkbuild "${@}" || es=${?} fi + _cmd_build_header '-' 'Remove Build Dependencies' _cmd_build_fini + changes="${_cmd_build_pkg_dir}/../$(: \ + )${source}_${version}_${host_arch}_${host_plat}.changes" + if [ -r "${changes}" ]; then + _cmd_build_header '-' 'Build Results' + _cmd_build_header '~' "${changes##*/}" + cat "${changes}" + for opk in $(sed -n '/^Files:/,${ s/^ [0-9][0-9]* ..* //p; };' \ + "${changes}"); do + _cmd_build_header '~' "${opk}" + opk="${_cmd_build_pkg_dir}/../${opk}" + tar -xzOf "${opk}" control.tar.gz | tar -xzO ./control + printf '\n' + tar -xzOf "${opk}" data.tar.gz | tar -tvz + done + fi + + _cmd_build_header '-' 'Summary' + build_time=$(($(_cmd_build_time) - ${build_time})) + cat <<-EOF + Source: ${source} + Version: ${version} + Build-Architecture: ${build_arch} + Host-Architecture: ${host_arch} + Host-Platform: ${host_plat} + Distribution: ${dist} + Build-Date: ${build_date} + Finished: $(LC_ALL='C' date '+%a, %d %b %Y %H:%M:%S %z') + Build-Time: ${build_time} + Build-Time-Human: $(printf '%02d:%02d:%02d' \ + $((${build_time} / 60 / 60)) \ + $((${build_time} / 60 % 60)) \ + $((${build_time} % 60))) + Status: $([ ${es} -eq 0 ] \ + && printf 'successful' || printf 'failed') + EOF + return ${es} } @@ -191,8 +288,10 @@ cmd_build_main() { { set +e - _cmd_build_build "${host_arch}" "${host_plat}" \ - "${@}" 2>&1 + _cmd_build_build \ + "${build_arch}" "${build_plat}" \ + "${host_arch}" "${host_plat}" \ + "${dist}" "${@}" 2>&1 printf '%d' ${?} 1>&3 } | tee "${log}" 1>&2 } 3>&1 | { -- cgit v0.9.1