[pacman-dev] [PATCH] makepkg: Log commands to logfile

Alain Kalker a.c.kalker at gmail.com
Tue Jul 2 19:45:17 EDT 2013


On 07/02/2013 11:07 PM, Dave Reisner wrote:
> You make zero mention of makepkg or any external build tool in that 
> environment. I'm not sure how you expect anyone to pick up your veil 
> and dispute your method of compilation. Quite frankly, this is rude of 
> you, regardless of whether or not makepkg is at fault. 
Please take this kind of musdlinging somewhere else, IRC, 4chan, a muddy 
beach, or whatever.

My final try at proving my point is the following script: it takes a 
logfile from makepkg -L (with my patch applied), and an optional 
makepkg.conf file (defaulting to /etc/makepkg), then generates a script 
containing selected environment variables from the configfile, followed 
by a replay of all commands executed during the build or package phase 
(determined by the name of the logfile.
Script is self-documenting, but here is the gist of how to use it for TL;DR:

- Build package using patched `makepkg -L`
- Run makereplay on the generated logfile
- Clean out src and pkg directories
- Run `makepkg -o`
- Change to the top of the extracted source tree
- Run `clean-build` and `clean-package` as per the docs inside.

<<Here is where the fun begins>>

- Now you can do a diff between the log generated by `makepkg -L` and 
from running the clean-* scripts.
- If the build failure occurs with the clean build also, simply submit 
the logs and clean-* scripts upstream along with your bug report and any 
needed patches used in the build.
- ???
- Profit!!

And I mean it, for great justice or whatever.

Feel free to use this stuff to track down your core package breakage, 
feel free even to include it in some toolbox, as long as this pissing 
contest stops here, i'm allergic to flamethrowers.

Kind regards, Alain

---[file: makereplay]---
#!/bin/bash

# makereplay - Generate a script to replay commands from a makepkg logfile
#              using environment variables from a makepkg.conf file

PROGNAME=$(basename "$0")

usage() {
     echo "usage:  $PROGNAME [option] logfile [makepkg.conf file]"
}

help() {
     usage
     echo
     echo " Options:"
     echo "  -d       Use debug variables from makepkg.conf"
}

[[ $# -eq 0 ]] && usage && exit 1
[[ $1 == "-h" ]] && help && exit 0
[[ $1 == "-d" ]] && { debugbuild=yes; shift; } || debugbuild=no
[[ $# -eq 0 ]] && usage && exit 1
logfile=$1; shift
[[ ! -f $logfile ]] && echo "Error: logfile does not exist" >&2 && exit 1
[[ $logfile =~ "build.log" ]] && scriptname=replay-build.sh
[[ $logfile =~ "package.log" ]] && scriptname=replay-package.sh
makepkgconf=$1; shift
[[ -z $makepkgconf ]] && makepkgconf=/etc/makepkg.conf
[[ ! -f $makepkgconf ]] && echo "Error: makepkg.conf file does not 
exist" >&2 && exit 1

if [[ $debug = "yes" ]]; then
     debugfilter="s/^DEBUG_//g"
else
     debugfilter="/^DEBUG_/d"
fi

badvars=('CARCH' 'CHOST' 'BUILDENV' 'OPTIONS' 'INTEGRITY_CHECK'
         'STRIP_.*' '.*_DIRS' '.*_TARGETS' 'COMPRESS.*' '.*EXT')
badvarsfilter=$(IFS='|'; echo "/""${badvars[*]}""/d")

{
     cat <<-EOF
         #!/bin/bash

         # $scriptname - Replay commands from a makepkg logfile

         # This script was created using the following configuration:
         # Log file: $logfile
         # Build settings: $makepkgconf
         # Debug build: $debugbuild

         # Example usage:

         # $ cd <directory containing PKGBUILD>
         # $ rm -rf pkg src
         # $ mkdir pkg src
         # $ makepkg -o
         #
         # Do a clean build or install
         # $ cd src/<top of source tree>
         # $ ../../$scriptname 2>&1 | tee ../../$logfile.clean
         #
         # Then compare the logs
         # $ cd ../..
         # $ diff -u $logfile{,.clean}

         EOF

     echo "# Set up environment"
     grep "^[^#].*=[^(]" "$makepkgconf" | \
         sed -re "$badvarsfilter" | \
         sed -re "$debugfilter" | \
         sed -re "s/^/export /g"

     echo

     echo "# Set up command logging"
     echo 'restoreps4=$PS4'
     echo "PS4='$ '"
     echo "set -x"

     echo

     echo "# Replay commands from logfile"
     sed -n "s/^\$ \(.*\)$/\1/gp" < $logfile

     echo

     echo "# Restore command logging"
     echo "set +x"
     echo "PS4=$restoreps4"
} > $scriptname

chmod +x "$scriptname"
echo "Script written to: $scriptname"
---[end: makereplay]---


More information about the pacman-dev mailing list