Skip to contentSkip to conversation

coccinelle: add localversion information

PATCH Superseded Luis R. Rodriguez 2 participants 4 messages Jul 24, 2015 Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover coccinelle: add localversion information

From: "Luis R. Rodriguez" <[email protected]>

This v2 removes the superfluous tr calls and switches to using stdin instead of using cat for the first look at the version file. While at it, since I am taking this from the Linux kernel and since the script used had quite a bit of love over the years I've provided attribution information to the file. Since Coccinelle does not currently used PGP signed tags I've also added support for that and enabled its use by default but am in hopes we can consider using PGP keys for signed tags in the future.

I also made a small note about using PGP subkeys for deprecating releases, for details on why that may be good see:

http://lkml.kernel.org/r/20150721002438.GG30479 at wotan.suse.de

In short, I'd encourage folks to use PGP subkeys for different purposes. For instance use one PGP subkey for making releases, and another different PGP subkey for deprecating releaes. Using two different PGP keys (different keys are overkill, hence why I say just use subkeys) can help tools to infer what releases are supported and unsupported, directly from the git tree. Feel free to ignore all this if you do not care for tools to infer releases for coccinelle, but if for instance you do care for it and if it is desirable for the release page to be made automatically, I can volunteer to help integrate it as part of rel-html. Example release pages with rel-html:

http://drvbp1.linux-foundation.org/~mcgrof/rel-html/

Lastly, I realize a 'make release' is used right now for releases, I didn't amend those instructions (on Makefile.release) but here's a way to use upkeep a linear git tree (not done right now on Coccinelle) even if you wanted to bump release with autotools:

Say you have a linear set of history and you are about to make a 1.0.2 release, you'd do this:

a) edit version file and bump it to 1.0.2
b) git clean -f -x -d
Careful, this will delete *everything* that is not commited in your git tree.
c) make a temporary tag for git with 1.0.2, so that when you run ./autogen it will pick up all the 1.0.2 tag and detect your tree is intact and all code is part of the release.
git tag -s 1.0.2
d) run ./autogen
e) git commit -a -s
f) delete the temporary tag:
git tag -d 1.0.2
g) make a new tag now that matches the autogen run:
git tag -s 1.0.2

This allows you to keep using 1 tag for both git development and autotools official releases. This means that if people check out a release on the tag 1.0.2 you will always get 1.0.2 on the version information so long as you didn't do any modifications and provided your autotools versions match (this later requirement is less important to developers). It also means that same git tree checkout for non-developers, who do not run ./autgen but just run ./configure will always get the same version information.

Luis R. Rodriguez (2):
autotools: unify the way to determine version information
autotools: add localversion information

 Makefile                |   2 +-
 configure.ac            |   2 +-
 scripts/setlocalversion | 117 ++++++++++++++++++++++++++++++++++++++++++++++++
 version.sh              |   4 ++
 4 files changed, 123 insertions(+), 2 deletions(-)
 create mode 100755 scripts/setlocalversion
 create mode 100755 version.sh
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
#1 lore raw

PATCH v2 1/2 autotools: unify the way to determine version information

From: "Luis R. Rodriguez" <[email protected]>

The version information you get when you run: spatch --version comes from what ./confgure.ac ends up figuring out for you. The top level Makefile uses the same mechanism to tell you and use the version information at build time, but if the strategy is updated in one place it would need to be updated in both places.

Avoid this duplicatin of work and instead just make version information come from ./version.sh script. Then if we update how we get the version information it just needs to be done in one place.

We make the version.sh script use old shell mechanisms to be able to work on any supported unix system.

Cc Peter Senna Tschudin <[email protected]>
Cc Nikolay Orlyuk <[email protected]>
Cc S?bastien Hinderer <[email protected]>
Cc Quentin Lambert <[email protected]>
---
 Makefile     | 2 +-
 configure.ac | 2 +-
 version.sh   | 3 +++
 3 files changed, 5 insertions(+), 2 deletions(-)
 create mode 100755 version.sh
Makefile +1 -1
index fd369415b1ec..57e01e2afb1c 100644
@@ -19,7 +19,7 @@ endif
 -include /etc/Makefile.coccinelle  # local customizations, if any
 
 
-VERSION=$(shell cat ./version | tr -d '\n')
+VERSION=$(shell ./version.sh)
 CCVERSION=$(shell cat scripts/coccicheck/README | egrep -o '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | head -n1)
 PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \
 	 | sed -n 's/^Version: \(.*\)/\1/p' )
configure.ac +1 -1
index d4072004228c..4c610afa5a2d 100644
@@ -3,7 +3,7 @@ dnl  run 'automake -acf' to update setup/{install-sh,missing}
 
 dnl  standard initialization (we only use autoconf not automake)
 AC_PREREQ([2.68])
-AC_INIT([coccinelle], m4_esyscmd([cat ./version | tr -d '\n']), [cocci at systeme.lip6.fr], [], [http://coccinelle.lip6.fr/])
+AC_INIT([coccinelle], m4_esyscmd([./version.sh]), [cocci at systeme.lip6.fr], [], [http://coccinelle.lip6.fr/])
 AC_CONFIG_MACRO_DIR([setup])
 AC_CONFIG_AUX_DIR([setup])
 AC_SUBST([CONFIGURE_FLAGS], ["$*"])
version.sh new file +3 -0
new file mode 100755
index 000000000000..a464ab47dbd6
@@ -0,0 +1,3 @@
+#!/bin/sh
+VERSION=`tr -d '\n' < ./version`
+printf '%s' $VERSION
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
#2 lore raw

PATCH v2 2/2 autotools: add localversion information

In reply to Luis R. Rodriguez

From: "Luis R. Rodriguez" <[email protected]>

When someone is building Coccinelle from source on a git tree with some modifications we currently cannot tell what type of modifications were, if any, were done. Add a localversion info postix which will be pegged onto the version string *iff* the git tree used has either a change non-commited yet or if the git tree has some commits beyond what was officially released and tagged.

So if you have a dirty tree with some uncommited changes the version will be postfixed with -dirty. For example if 1.0.2 was blessed and released and you had a series of uncommited changes you'd end yup with:

1.0.2-dirty

Likewise if your tree has some commits not upstream these will be reflected. For instance, say you had one extra commit, you'd end up with:

1.0.2-00001-g8870d8b0cf33

The purpose of this is to enable developers and tools within Coccinelle to be able to tell when folks have modified upstream code.

The setlocalversion file was take and modified from the Linux kernel, it was repurposed for Coccinelle by just simplifying it by hardcoding it to use the long version string if there is any delta. It also supports unsigned and un-annotated tags (how Coccinelle makes releases today) but encourages folks to switch to PGP signed releases, as well as using another PGP subkey for deprecating releases.

Cc Peter Senna Tschudin <[email protected]>
Cc Nikolay Orlyuk <[email protected]>
Cc S?bastien Hinderer <[email protected]>
Cc Quentin Lambert <[email protected]>
---
 scripts/setlocalversion | 117 ++++++++++++++++++++++++++++++++++++++++++++++++
 version.sh              |   3 +-
 2 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100755 scripts/setlocalversion
scripts/setlocalversion new file +117 -0
new file mode 100755
index 000000000000..728b54e9ee9f
@@ -0,0 +1,117 @@
+#!/bin/sh
+#
+# Copyright (c) 2005-2006 Ryan Anderson <[email protected]>
+# Copyright (c) 2006 Rene Scharfe <[email protected]>
+# Copyright (c) 2006 Uwe Zeisberger <[email protected]>
+# Copyright (c) 2007 Aron Griffis <[email protected]>
+# Copyright (c) 2007 Theodore Ts'o <[email protected]>
+# Copyright (c) 2008 Bryan Wu <[email protected]>
+# Copyright (c) 2008 Mike Frysinger <[email protected]>
+# Copyright (c) 2008 Peter Korsgaard <[email protected]>
+# Copyright (c) 2008 Sebastian Siewior <[email protected]>
+# Copyright (c) 2008 Trent Piepho <[email protected]>
+# Copyright (c) 2009 Mike Frysinger <[email protected]>
+# Copyright (c) 2009 Nico Schottelius <[email protected]>
+# Copyright (c) 2009 Peter Korsgaard <[email protected]>
+# Copyright (c) 2010 Linus Torvalds <[email protected]>
+# Copyright (c) 2010 Michael Prokop <[email protected]>
+# Copyright (c) 2010 Micha? G?rny <[email protected]>
+# Copyright (c) 2010 Michal Marek <[email protected]>
+# Copyright (c) 2010 Milton Miller <[email protected]>
+# Copyright (c) 2011 Mike Crowe <[email protected]>
+# Copyright (c) 2012 Roland Dreier <[email protected]>
+# Copyright (c) 2013 Christian Kujau <[email protected]>
+# Copyright (c) 2013 Christophe Leroy <[email protected]>
+# Copyright (c) 2013 Franck Bui-Huu <[email protected]>
+# Copyright (c) 2015 Luis R. Rodriguez <[email protected]>
+#
+# This file is released under the GPLv2.
+#
+# Taken from the Linux kernel as of v4.2-rc2 with a few modifications
+# described below.
+#
+# This scripts adds local version information from the version
+# control systems. It was taken from the Linux kernel as of v4.2-rc2
+# and simplified for use on Coccinelle by mcgrof. The version info
+# was hard coded to use long version. The svn postfix details were
+# also removed. I also added the option to enable this script to
+# work well for trees that do not use PGP signed tags or annotated
+# tags (git tag -s or git tag -a), git describe by default will only
+# look for these tags. If you do not use these you will want to set
+# the below variable to TAGS="--tags". If  you requires --tags, consider
+# to start signing your releases "git tag -s" and use a subkey for that.
+# If you do that, consider also using another PGP subkey for annotating
+# releases as deprecated.
+#
+# Set to emtpy variable if you use properly signed tags. You should do this!
+TAGS="--tags"
+
+srctree=.
+
+scm_version()
+{
+	local short
+	short=false
+
+
+	# Check for git and a git repo.
+	if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
+	   head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+
+		# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
+		# it, because this version is defined in the top level Makefile.
+		if [ -z "`git describe $TAGS --exact-match 2>/dev/null`" ]; then
+
+			# If only the short version is requested, don't bother
+			# running further git commands
+			if $short; then
+				echo "+"
+				return
+			fi
+			# If we are past a tagged commit (like
+			# "v2.6.30-rc5-302-g72357d5"), we pretty print it.
+			if atag="`git describe $TAGS 2>/dev/null`"; then
+				echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
+
+			# If we don't have a tag at all we print -g{commitish}.
+			else
+				printf '%s%s' -g $head
+			fi
+		fi
+
+		# Check for uncommitted changes
+		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+			printf '%s' -dirty
+		fi
+
+		# All done with git
+		return
+	fi
+
+	# Check for mercurial and a mercurial repo.
+	if test -d .hg && hgid=`hg id 2>/dev/null`; then
+		# Do we have an tagged version?  If so, latesttagdistance == 1
+		if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
+			id=`hg log -r . --template '{latesttag}'`
+			printf '%s%s' -hg "$id"
+		else
+			tag=`printf '%s' "$hgid" | cut -d' ' -f2`
+			if [ -z "$tag" -o "$tag" = tip ]; then
+				id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
+				printf '%s%s' -hg "$id"
+			fi
+		fi
+
+		# Are there uncommitted changes?
+		# These are represented by + after the changeset id.
+		case "$hgid" in
+			*+|*+\ *) printf '%s' -dirty ;;
+		esac
+
+		# All done with mercurial
+		return
+	fi
+}
+
+res="$res$(scm_version)"
+echo "$res"
version.sh +2 -1
index a464ab47dbd6..157b3e2d549c 100755
@@ -1,3 +1,4 @@
 #!/bin/sh
 VERSION=`tr -d '\n' < ./version`
-printf '%s' $VERSION
+LOCALVERSION=`./scripts/setlocalversion | tr -d '\n'`
+printf '%s%s' $VERSION $LOCALVERSION
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
#3 lore raw

v2 cover coccinelle: add localversion information

In reply to Luis R. Rodriguez
Quoted 1 line · Luis R. Rodriguez

a) edit version file and bump it to 1.0.2

Forgot to mention you'd need to commit this after as part of this step.

Luis