31 May 2013, 10:01

Git tip: build-test a branch

As a kernel contributor, I often like to build test my series of patches to make sure they are bisectable - that is, to make sure the code still builds (and hopefully runs) after each one of my changes. However, I did not find any easy and automatic way to do this, so I ended up writing a very simple implementation of it in sh, which I will show you here.

First, you will need to create a shell script and put it somewhere on your $PATH; I used ~/bin/git-build-test. Make sure you chmod +x it as well so we can then run it.

#!/bin/sh

# git reference, eg v3.10-rc2..
REF=$1
# list of hashes in that reference
HASHES=$(git rev-list $REF)
# current branch
BRANCH=$(git symbolic-ref HEAD | sed 's#refs/heads/##')
# build command, default to 'make'
BUILD=$(echo $@ | sed "s#$REF##")
[ -z "$BUILD" ] && BUILD="make -j16"

for H in $HASHES; do
    git checkout $H
    $BUILD || exit
done

echo "Success!"
git checkout $BRANCH

Then, we need to add a git alias to make it easily callable. On ~/.gitconfig, add

[alias]
    buildtest = !sh -c 'git-build-test $*' -

Then you can call it as git buildtest v3.10-rc2.. to test building every single commit from v3.10-rc2 to HEAD using make. You can also use more complex incantations like git buildtest v3.10-rc2.. make dtbs for example, to just test device tree building.