diff mbox

[kteam-tools] git-build-kernel: embed sha in the /tmp/kernel-user-xxxxxxx build dir name

Message ID 1485903542-17611-1-git-send-email-kamal@canonical.com
State New
Headers show

Commit Message

Kamal Mostafa Jan. 31, 2017, 10:59 p.m. UTC
Instead of using just random digits in the /tmp/kernel-user-xxxxxxxx
build dir name, embed the commit sha of the pushed branch head as well.

This makes it easy to associate a bunch of built /tmp/kernel-user-sha-xxxx
dirs with the exact commits that were used to build them.

Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 git-build-kernel/git-build-kernel | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Stefan Bader Feb. 1, 2017, 10:06 a.m. UTC | #1
On 31.01.2017 23:59, Kamal Mostafa wrote:
> Instead of using just random digits in the /tmp/kernel-user-xxxxxxxx
> build dir name, embed the commit sha of the pushed branch head as well.
> 
> This makes it easy to associate a bunch of built /tmp/kernel-user-sha-xxxx
> dirs with the exact commits that were used to build them.
> 
> Signed-off-by: Kamal Mostafa <kamal@canonical.com>
> ---
>  git-build-kernel/git-build-kernel | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/git-build-kernel/git-build-kernel b/git-build-kernel/git-build-kernel
> index c1e885a..a0eec96 100755
> --- a/git-build-kernel/git-build-kernel
> +++ b/git-build-kernel/git-build-kernel
> @@ -61,6 +61,10 @@ GITREPO="${GITREPO%/.git}"
>      exit 1
>  }
>  
> +GITSHASHORT="`git log -1 --pretty=%h ${GITBRANCH%%refs/heads/} --`"
> +[ -z "$GITSHASHORT" ] && {
> +    echo "warning: Can't determine GITSHASHORT from GITBRANCH=$GITBRANCH" 1>&2
> +}
>  
>  ### Get the var "DEBIAN=debian.master" from debian/debian.env
>  eval `git show $GITBRANCH:debian/debian.env | grep DEBIAN=`
> @@ -97,7 +101,8 @@ VERSION=`echo "$chg" | sed -n -e '1s/^.*(\([^)]*\)).*$/\1/p'`
>  
>  ### Set up the /tmp work directory
>  
> -WORKDIR="`mktemp -u -d -t kernel-$LOGNAME-XXXXXXXX`"
> +WORKDIR="kernel-$LOGNAME-$GITSHASHORT-XXXX"
> +WORKDIR="`mktemp -u -d -t $WORKDIR`"

Maybe it would be better to just fallback to the old naming when GITSHASHORT
happens to be ""...

>  mkdir "$WORKDIR" || exit
>  
>  BUILDDIR="$WORKDIR/build"
>
Kamal Mostafa Feb. 2, 2017, 5:03 p.m. UTC | #2
On Wed, Feb 01, 2017 at 11:06:40AM +0100, Stefan Bader wrote:
> > +GITSHASHORT="`git log -1 --pretty=%h ${GITBRANCH%%refs/heads/} --`"
> > +[ -z "$GITSHASHORT" ] && {
> > +    echo "warning: Can't determine GITSHASHORT from GITBRANCH=$GITBRANCH" 1>&2
> > +}
> 
> Maybe it would be better to just fallback to the old naming when GITSHASHORT
> happens to be ""...

I'm pretty sure that GITSHASHORT can't ever actually end up blank there.
The test and warning are just in case I'm wrong about that (and the
script works even if that somehow does occur).

Anyway, [PATCH v2] makes it even clearer that this can-never-happen
situation happened, if it does.  :-)
 
 -Kamal
diff mbox

Patch

diff --git a/git-build-kernel/git-build-kernel b/git-build-kernel/git-build-kernel
index c1e885a..a0eec96 100755
--- a/git-build-kernel/git-build-kernel
+++ b/git-build-kernel/git-build-kernel
@@ -61,6 +61,10 @@  GITREPO="${GITREPO%/.git}"
     exit 1
 }
 
+GITSHASHORT="`git log -1 --pretty=%h ${GITBRANCH%%refs/heads/} --`"
+[ -z "$GITSHASHORT" ] && {
+    echo "warning: Can't determine GITSHASHORT from GITBRANCH=$GITBRANCH" 1>&2
+}
 
 ### Get the var "DEBIAN=debian.master" from debian/debian.env
 eval `git show $GITBRANCH:debian/debian.env | grep DEBIAN=`
@@ -97,7 +101,8 @@  VERSION=`echo "$chg" | sed -n -e '1s/^.*(\([^)]*\)).*$/\1/p'`
 
 ### Set up the /tmp work directory
 
-WORKDIR="`mktemp -u -d -t kernel-$LOGNAME-XXXXXXXX`"
+WORKDIR="kernel-$LOGNAME-$GITSHASHORT-XXXX"
+WORKDIR="`mktemp -u -d -t $WORKDIR`"
 mkdir "$WORKDIR" || exit
 
 BUILDDIR="$WORKDIR/build"