Hello again, Following the earlier thread a few months back ("RFE: allow for computed version number"), I was looking for a solution to this problem at the time, and implemented a scheme similar to that proposed. In case it's useful for anyone else, I'll detail what I'm doing below.
I use git, and end up having the PACKAGE and VERSION in multiple places, including: configure.ac NEWS git release tags Being able to eliminate some of this redundant information would be great. The scripts and files below /are/ hacky; having some support for this in the tools would remove most, if not all, of that: I think looking at the bigger picture, what would be really useful would be for both autoconf and automake to have a generalised mechanism for getting information about a package. This could be as simple as calling a hook script which is written by the user. Like the script below, it could return key: value pairs and parse out the needed bits, or it could have an argument requesting the wanted bit of information. This script could get the information directly from the VCS and/or files in the source distribution (so it will work both with and without the presence of a VCS). Information that would be useful: PACKAGE VERSION Release date Distributor/Origin (to indicate origin if redistributed modified) [already hacked into e.g. binutils and gcc; having a standardised method would be good] Regards, Roger bootstrap ═════════ Call a script git-version to generate a VERSION file, containing the information necessary for configure.ac and then autoreconf. NOTE: automake --gnu requires a ChangeLog, but nowadays this might be generated at "make dist" time; please consider making --gnu mandate a changelog in $distdir instead. This has the same result for the end distributed source, but doesn't constrain the developer to maintain a manually written changelog. ─[bootstrap]─────────────────────────────────────────────────────────── #!/bin/sh set -e # Generate version information from git release tag ./scripts/git-version > VERSION # To satisfy automake touch ChangeLog # Bootstrap autotools autoreconf --verbose --force --install rm -rf autom4te.cache ─────────────────────────────────────────────────────────────────────── VERSION ═══════ Generated using the git-version script (see below) ─[VERSION]─────────────────────────────────────────────────────────── Package: sbuild Version: 0.59.1-rc1 Release-Date: 02 Aug 2009 Released-By: Roger Leigh <rle...@debian.org> Git-Tag: release/sbuild-0.59.1-rc1 ─────────────────────────────────────────────────────────────────────── configure.ac ════════════ Similar to what others are doing. I just changed the command to parse the particular syntax in my generated VERSION file above. I've just added a prefix so I don't conflict with autoconf/automake's implementation. ─[configure.ac]──────────────────────────────────────────────────────── dnl m4 magic from Eric Blake <e...@byu.net>, prior to automake inclusion m4_define([sbuild_m4_chomp], [m4_format([[%.*s]], m4_bregexp(m4_translit([$1], [ ]]m4_dquote(_m4_defn([m4_cr_all]))[, [/]]m4_format([%255s], [])[), [/*$]), [$1])]) m4_define([sbuild_m4_esyscmd_s], [sbuild_m4_chomp(m4_esyscmd([$1]))]) AC_PREREQ(2.59) dnl Quoting the first argument results in a bizarrely corrupted package tarname AC_INIT(sbuild_m4_esyscmd_s([sed -ne '/^Package:/{s/Package:[[:space:]][[:space:]]*//p;q}' VERSION]), [sbuild_m4_esyscmd_s([sed -ne '/^Version:/{s/Version:[[:space:]][[:space:]]*//p;q}' VERSION])], [buildd-tools-de...@lists.alioth.debian.org]) ─────────────────────────────────────────────────────────────────────── git-version ═══════════ I use a tagging scheme where releases are named release/PACKAGE-VERSION so we get the version by looking for the release tag, chopping it up, and then writing out the information, which includes other information such as the release date and who make the release. The release date is currently also used in configure.ac and then AC_DEFINED. Yes, this is backwards. You shouldn't have to tag the release prior to actually making it. This means I now create -rc1 version tags after making a release in order to get a sensible release number. Ideally, I should get that from NEWS, as done below for the tagging script, and create the release version in dist-hook. ─[git-version]───────────────────────────────────────────────────────── #!/bin/sh TAG="$(git describe --abbrev=0 --match='release/*')" PKGVER="${TAG#release/}" PACKAGE="$(echo "$PKGVER" | sed -e 's/^\([^-]*\)-\(.*\)$/\1/')" VERSION="$(echo "$PKGVER" | sed -e 's/^\([^-]*\)-\(.*\)$/\2/')" COMMIT="$(git rev-parse "$TAG^{}")" COMMIT_DATE="$(git log -1 --date=iso "$COMMIT" --pretty="format:%ad")" RELEASE_DATE="$(date --date="$COMMIT_DATE" '+%d %b %Y')" RELEASE_BY="$(git show "$TAG" | sed -ne '/^Tagger:/{s/Tagger:[[:space:]][[:space:]]*//p;q}')" echo "Package: $PACKAGE" echo "Version: $VERSION" echo "Release-Date: $RELEASE_DATE" echo "Released-By: $RELEASE_BY" echo "Git-Tag: $TAG" ─────────────────────────────────────────────────────────────────────── git-tag-release ═══════════════ Use to make the release tags. We use the package name and version from the NEWS file. This is one bit of custom scripting that will be replaced by the dist-git rule. ─[git-tag-release]───────────────────────────────────────────────────── #!/bin/sh set -e PACKAGE="$(sed -ne '/^Welcome to /{s/Welcome to[[:space:]][[:space:]]*\([[:alnum:]][[:alnum:]]*\)[[:space:]][[:space:]]*\([[:alnum:]][[:alnum:].-]*\)\..*/\1/p;q}' < NEWS)" VERSION="$(sed -ne '/^Welcome to /{s/Welcome to[[:space:]][[:space:]]*\([[:alnum:]][[:alnum:]]*\)[[:space:]][[:space:]]*\([[:alnum:]][[:alnum:].-]*\)\..*/\2/p;q}' < NEWS)" if [ -z "$PACKAGE" ] || [ -z "$VERSION" ]; then echo "Error parsing package name and version from NEWS" exit 1 fi echo "Tagging ${PACKAGE} version ${VERSION} as 'release/${PACKAGE}-${VERSION}'" git tag -s "release/${PACKAGE}-${VERSION}" -m "${PACKAGE} version ${VERSION}" ─────────────────────────────────────────────────────────────────────── Regards, Roger -- .''`. Roger Leigh : :' : Debian GNU/Linux http://people.debian.org/~rleigh/ `. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/ `- GPG Public Key: 0x25BFB848 Please GPG sign your mail.
signature.asc
Description: Digital signature