Ignore:
Timestamp:
May 30, 2016, 6:43:54 PM (9 years ago)
Author:
dmik
Message:

rpmbuild-bot: Print elapsed time after each succeded step and overall.

The overall elapsed time is printed even on failure. Also the start and
end datetime of the overall build process is printed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rpmbuild-bot/rpmbuild-bot.sh

    r768 r769  
    186186#
    187187
     188print_elapsed()
     189{
     190  # $1 = start timestamp, in seconds (as returned by `date +%s`)
     191  # $2 = string containg \$e (will be replaced with the elapsed time)
     192
     193  [ -z "$1" -o -z "$2" ] && return
     194
     195  local e=$(($(date +%s) - $1))
     196  local e_min=$(($e / 60))
     197  local e_sec=$(($e % 60))
     198  local e_hrs=$((e_min / 60))
     199  e_min=$((e_min % 60))
     200  e="${e_hrs}h ${e_min}m ${e_sec}s"
     201
     202  eval "echo \"$2\""
     203}
     204
     205quit()
     206{
     207  if [ -n "$start_time" ] ; then
     208    echo "Build ended on $(date -R)."
     209    if [ $1 = 0 ] ; then
     210      print_elapsed start_time "Build succeeded (took \$e)."
     211    else
     212      print_elapsed start_time "Build failed (took \$e)."
     213    fi
     214  fi
     215  exit $1
     216}
     217
    188218run()
    189219{
     
    193223    echo "ERROR: The following command failed with error code $rc:"
    194224    echo $@
    195     exit $rc
     225    quit $rc
    196226  fi
    197227}
     
    209239    echo "You will find more information in file '$log'."
    210240    echo "Here are the last 10 lines of output:"
    211     echo ""
     241    echo "------------------------------------------------------------------------------"
    212242    tail "$log" -n 10
    213     exit $rc
     243    echo "------------------------------------------------------------------------------"
     244    quit $rc
    214245  fi
    215246}
     
    223254{
    224255  echo "ERROR: $1"
    225   exit 1
     256  quit 1
    226257}
    227258
     
    254285    [ -n "$3" ] && eval $3
    255286    [ -f "$file" ] || die "File '$file' is not found."
    256     echo "Checking tmestamp of $file..."
     287    echo "Checking timestamp of $file..."
    257288    local act_ts=`stat -c '%Y' "$file"`
    258289    if [ "$ts" != "$act_ts" ] ; then
     
    269300  echo "Usage:"
    270301  sed -n -e "s/rpmbuild-bot.sh/${0##*/}/g" -e 's/^# > /  /p' < "$0"
    271   exit 255
     302  quit 255
    272303}
    273304
     
    328359  fi
    329360
     361  local start_time=
     362
    330363  # Generate RPMs.
    331364  for arch in $RPMBUILD_BOT_ARCH_LIST ; do
    332365    echo "Creating RPMs for '$arch' target (logging to $log_base.$arch.log)..."
     366    start_time=$(date +%s)
    333367    log_run "$log_base.$arch.log" rpmbuild.exe --target=$arch -bb "$spec_full"
     368    print_elapsed start_time "Completed in \$e."
    334369  done
    335370
    336371  # Generate SRPM.
    337372  echo "Creating SRPM (logging to $log_base.srpm.log)..."
     373  start_time=$(date +%s)
    338374  log_run "$log_base.srpm.log" rpmbuild -bs "$spec_full"
     375  print_elapsed start_time "Completed in \$e."
    339376
    340377  # Find SRPM file name in the log.
     
    360397  # Generate ZIP.
    361398  echo "Creating ZIP (logging to $log_base.zip.log)..."
     399  start_time=$(date +%s)
    362400  create_zip()
    363401  {(
     
    374412  )}
    375413  log_run "$log_base.zip.log" create_zip
     414  print_elapsed start_time "Completed in \$e."
    376415
    377416  local ver_list="$log_base.$ver_full.list"
     
    730769spec_list="$log_base.list"
    731770
     771start_time=$(date +%s)
     772
     773echo "Build started on $(date -R)."
    732774echo "Package:   $spec_name"
    733775echo "Command:   $command $options"
     
    741783run eval "${command_name}_cmd"
    742784
    743 echo "All done."
    744 
    745 exit 0
     785quit 0
Note: See TracChangeset for help on using the changeset viewer.