Make generateHgRevision.sh only regenerate the hgRevision.h file when the revision has changed, cutting out a possible cause of #179. maintenance-1.2
authorPeter Hosey <hg@boredzo.org>
Mon May 09 00:28:34 2011 -0700 (2011-05-09)
branchmaintenance-1.2
changeset 46964b7b06d729b5
parent 4695 dc091855252f
child 4697 53cd0ddf45ad
Make generateHgRevision.sh only regenerate the hgRevision.h file when the revision has changed, cutting out a possible cause of #179.
Tools/printRevision/Makefile
Tools/printRevision/printRevision.c
generateHgRevision.sh
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Tools/printRevision/Makefile	Mon May 09 00:28:34 2011 -0700
     1.3 @@ -0,0 +1,4 @@
     1.4 +CFLAGS+=-std=c99 -include "$(HEADERPATH)"
     1.5 +LDFLAGS+=
     1.6 +
     1.7 +printRevision: printRevision.o
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Tools/printRevision/printRevision.c	Mon May 09 00:28:34 2011 -0700
     2.3 @@ -0,0 +1,6 @@
     2.4 +//Note: hgRevision.h must be included on the command line. The Makefile does this when run by generateHgRevision.sh.
     2.5 +#include <stdio.h>
     2.6 +
     2.7 +int main(void) {
     2.8 +	return !printf("%s\n", HG_REVISION_STRING);
     2.9 +}
     3.1 --- a/generateHgRevision.sh	Sun May 08 23:37:19 2011 -0700
     3.2 +++ b/generateHgRevision.sh	Mon May 09 00:28:34 2011 -0700
     3.3 @@ -22,8 +22,23 @@
     3.4  		REVISION=0
     3.5  	fi
     3.6  fi
     3.7 +
     3.8 +mkdir -p "`dirname "$HEADERPATH"`"
     3.9 +
    3.10 +if [[ -f "$HEADERPATH" ]]; then
    3.11 +	#Determine whether the header already contains our current revision.
    3.12 +	pushd Tools/printRevision > /dev/null
    3.13 +	make HEADERPATH="../../$HEADERPATH" > /dev/null
    3.14 +	LAST_REVISION=$(./printRevision)
    3.15 +	popd > /dev/null
    3.16 +
    3.17 +	if [[ "$REVISION" -eq "$LAST_REVISION" ]]; then
    3.18 +		#The revision has not changed! No need to rewrite the file.
    3.19 +		exit 0
    3.20 +	fi
    3.21 +fi
    3.22 +
    3.23  echo "*** Building Growl Revision: $REVISION"
    3.24 -mkdir -p "`dirname "$HEADERPATH"`"
    3.25  
    3.26  echo "#define HG_REVISION $REVISION" > "$HEADERPATH"
    3.27  echo "#define HG_REVISION_STRING \"$REVISION\"" >> "$HEADERPATH"