Re: [PATCH] configure: add git describe output to PG_VERSION when building a git tree - Mailing list pgsql-hackers

From Oskari Saarenmaa
Subject Re: [PATCH] configure: add git describe output to PG_VERSION when building a git tree
Date
Msg-id 20131105140524.GB26836@saarenmaa.fi
Whole thread Raw
In response to Re: [PATCH] configure: add git describe output to PG_VERSION when building a git tree  (Heikki Linnakangas <hlinnakangas@vmware.com>)
Responses Re: [PATCH] configure: add git describe output to PG_VERSION when building a git tree  (Michael Paquier <michael.paquier@gmail.com>)
Re: [PATCH] configure: add git describe output to PG_VERSION when building a git tree  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, Nov 05, 2013 at 02:06:26PM +0200, Heikki Linnakangas wrote:
> On 05.11.2013 12:22, Oskari Saarenmaa wrote:
> >This makes it easy to see if the binaries were built from a real release
> >or if they were built from a custom git tree.
> 
> Hmm, that would mean that a build from "git checkout REL9_3_1"
> produces a different binary than one built from
> postgresql-9.3.1.tar.gz tarball.

Good point - how about adding git describe information only if the checkout
doesn't match a tag exactly?  So when you build REL9_3_1 there would be no
extra information, but when you have any local changes on top of it we'd add
the git describe output.

> I can see some value in that kind of information, ie. knowing what
> patches a binary was built with, but this would only solve the
> problem for git checkouts. Even for a git checkout, the binaries
> won't be automatically updated unless you run "configure" again,
> which makes it pretty unreliable.
> 
> -1 from me.

I don't think we can solve the problem of finding local changes for all the
things people may do, but I'd guess it's pretty common to build postgresql
from a clean local git checkout and with this change at least some portion
of users would get some extra information.  To solve the "rerun configure"
thing we could put git version in a new header file and have a makefile
dependency on .git/index for regenerating that file when needed.

We could also let users override the extra version with a command line
argument for configure so distributions could put the distribution package
version there, for example "9.3.1-2.fc20" on my Fedora system.

> PS, the git command in the patch doesn't work with my version of git:
> 
> $ git describe --tags --long --dirty HEAD
> fatal: --dirty is incompatible with committishes
> $ git --version
> git version 1.8.4.rc3

I initially used HEAD when looking at the git describe values, but then
added --dirty which obviously doesn't make sense when describing a ref.

Sorry about the broken patch, I was applying these changes manually from
configure.in to configure because I didn't have the proper autoconf version
installed (autoconf 2.63 doesn't seem to be available in many distributions
anymore, maybe the required version could be upgraded at some point..)

How about the patch below to fix the exact tag and --dirty issues?

/ Oskari

diff --git a/configure.in b/configure.in
index a4baeaf..d253286 100644
--- a/configure.in
+++ b/configure.in
@@ -29,7 +29,18 @@ AC_CONFIG_AUX_DIR(config)AC_PREFIX_DEFAULT(/usr/local/pgsql)AC_SUBST(configure_args,
[$ac_configure_args])
-AC_DEFINE_UNQUOTED(PG_VERSION, "$PACKAGE_VERSION", [PostgreSQL version as a string])
+# Append git tag based version to PG_VERSION if we're building from a git
+# checkout that doesn't match a tag exactly.  Don't touch PACKAGE_VERSION
+# which is used to create other version variables (major version and numeric
+# version.)
+PG_VERSION="$PACKAGE_VERSION"
+if test -d .git; then
+  exact="`git describe --tags --exact-match --dirty 2>/dev/null || echo dirty`"
+  if echo "$exact" | grep -q dirty; then
+    PG_VERSION="$PG_VERSION (`git describe --tags --long --dirty || echo unknown`)"
+  fi
+fi
+AC_DEFINE_UNQUOTED(PG_VERSION, "$PG_VERSION", [PostgreSQL version as a string])[PG_MAJORVERSION=`expr
"$PACKAGE_VERSION": '\([0-9][0-9]*\.[0-9][0-9]*\)'`]AC_SUBST(PG_MAJORVERSION)AC_DEFINE_UNQUOTED(PG_MAJORVERSION,
"$PG_MAJORVERSION",[PostgreSQL major version as a string])
 
-- 
1.8.4.2




pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: Row-security writer-side checks proposal
Next
From: Michael Paquier
Date:
Subject: Re: [PATCH] configure: add git describe output to PG_VERSION when building a git tree