diff --git a/collects/meta/build/build b/collects/meta/build/build index 692eeb3dae..a7872086ca 100755 --- a/collects/meta/build/build +++ b/collects/meta/build/build @@ -158,6 +158,8 @@ drtestscript="$scriptdir/test-drracket.rkt" bundlescript="$scriptdir/bundle" # web build script webscript="collects/meta/web/build.rkt" +# status script +statusscript="$scriptdir/current-build-status.cgi" # url mirrors file (relative to $maindir) knownmirrors="known-mirror-urls" # sitemap materials @@ -2176,6 +2178,22 @@ BUILD_PRE_WEB() { > /dev/null fi + ## -------------------------------------------------------------------------- + # Make the status script available for use + + if [[ "$prewebdir" = "$prewebdir_default" ]]; then + { + echo "#!/bin/bash" + local v + for v in tmpdir lockfile statusfile statusfile_last bglogfile; do + echo "$v=$(eval "\$$var")" + done + echo "" + cat "$PLTHOME/$statusscript" + } > "${prewebdir}/$(basename "$statusscript")" + chmod +x "${prewebdir}/$(basename "$statusscript")" + fi + } diff --git a/collects/meta/build/current-build-status.cgi b/collects/meta/build/current-build-status.cgi new file mode 100644 index 0000000000..b1f0537d8a --- /dev/null +++ b/collects/meta/build/current-build-status.cgi @@ -0,0 +1,59 @@ +# these should be writable +cache="/tmp/racket-build-status-cache" +cachelock="$cache-lock" + +printf 'Content-type: text/plain\r\n\r\n' + +# cache status reports (avoids excessive work during builds) + +# use a lockfile as a cheap hack to time cache refreshing +if ! lockfile -r 0 -l 5 -s 0 "$cachelock" && [[ -e "$cache" ]]; then + cat "$cache"; exit +fi + +{ + +files="" +if [[ -e "$lockfile" ]]; then L="Y"; else L="N"; fi +if [[ -e "$statusfile" ]]; then S="Y"; else S="N"; fi +if [[ -e "$statusfile_last" ]]; then S1="Y"; else S1="N"; fi + +if [[ "$L$S" = "NY" ]]; then + printf 'Last build crashed abnormally.\n' +elif [[ "$S" = "Y" ]]; then + printf 'Running: '; cat "$statusfile" + time_for_file() { + local t="$(($(date +"%s") - $(stat -c "%Z" "$1")))" + printf "%d:%02d:%02d" "$((t/3600))" "$(((t%3600)/60))" "$((t%60))" + } + printf "The build has been running for %s, current step for %s\n" \ + "$(time_for_file "$lockfile")" "$(time_for_file "$statusfile")" + shopt -s nullglob + if [[ "x$(echo "$bglogfile"*)" != "x" ]]; then + printf '\n%s build jobs running:\n' "$(ls "$bglogfile"* | wc -l)" + for bg in "$bglogfile"*; do + printf ' %s: ' "${bg#$bglogfile-}" + s="$(grep "^### <<< .* >>>" "$bg" | tail -1 \ + | sed -e 's/^### <<< \(.*\) >>>/\1/')" + if [[ "x$s" = "x" ]]; then echo "(just starting)"; else echo "$s"; fi + done + fi +else + printf 'No build is running.\n' + if [[ "$S1" = "Y" ]]; then + last="$(cat "$statusfile_last")" + if [[ "x$last" = "xDone ("*")" ]]; then + last="${last#Done (}" + last="${last%)}" + printf 'Last build successfully ended at %s\n' "$last" + else + printf 'Last build was unsuccessful (while: %s)\n' "$last" + fi + fi + if [[ "$L" = "Y" ]]; then + printf '(Builds temporarily disabled)\n' + fi +fi + +} > "$cache" 2>&1 +cat "$cache"