Skip to contentSkip to conversation

Automatically append a semi-random version for BK users

PATCH In review Ryan Anderson 2 participants 6 messages Mar 9, 2005 – Apr 2, 2005 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Automatically append a semi-random version for BK users

Automatically append a semi-random version if the tree we're building isn't tagged in BitKeeper and CONFIG_LOCALVERSION_AUTO is set.

This fixes the case when Linus (or someone else) does a release and tags it, someone else does a build of that release tree (i.e, 2.6.11), and installs it. Later, before another release occurs (i.e, -rc1), another build happens, and the actual, released 2.6.11 is overwritten with the -current tree.

Two approachs are present here, a Perl version that is setup to handle other automatic version appends (i.e, a CVS version shouldn't be much effort to add), and a simplistic shell version that depends on "md5sum". Both approaches generate the same hash.

I've sent this twice before, gotten no comments, so I'm really looking for feedback on the approach and idea, more than anything else.

Makefile +18 -0
diff -Nru a/Makefile b/Makefile
@@ -550,6 +550,24 @@
 
 #export	INSTALL_PATH=/boot
 
+# If CONFIG_LOCALVERSION_AUTO is set, we automatically perform some tests
+# and try to determine if the current source tree is a release tree, of any sort,
+# or if is a pure development tree.
+# A 'release tree' is any tree with a BitKeeper TAG associated with it.
+# The primary goal of this is to make it safe for a native BitKeeper user to
+# build a release tree (i.e, 2.6.9) and also to continue developing against the
+# current Linus tree, without having the Linus tree overwrite the 2.6.9 tree 
+# when installed.
+#
+# (In the future, CVS and SVN support will be added as well.)
+
+ifeq ($(CONFIG_LOCALVERSION_AUTO),y)
+	ifeq ($(shell ls -d $(srctree)/BitKeeper 2>/dev/null),$(srctree)/BitKeeper)
+		localversion-bk := $(shell $(srctree)/scripts/setlocalversion.sh $(srctree) $(objtree))
+		LOCALVERSION := $(LOCALVERSION)$(localversion-bk)
+	endif
+endif
+
 #
 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
 # relocations required by build roots.  This is not defined in the
init/Kconfig +12 -0
diff -Nru a/init/Kconfig b/init/Kconfig
@@ -69,6 +69,18 @@
 	  object and source tree, in that order.  Your total string can
 	  be a maximum of 64 characters.
 
+config LOCALVERSION_AUTO
+	bool "Automatically append version information to the version string"
+	default y
+	help
+	  This will try to automatically determine if the current tree is a
+	  release tree by looking for BitKeeper tags that belong to the
+	  current top of tree revision.
+	  A string of the format -BKxxxxxxxx will be added to the
+	  localversion.  The string generated by this will be appended 
+	  after any matching localversion* files, and after the 
+	  value set in CONFIG_LOCALVERSION
+
 config SWAP
 	bool "Support for paging of anonymous memory (swap)"
 	depends on MMU
scripts/setlocalversion new file +62 -0

62 lines not on this page · raw message

scripts/setlocalversion.sh new file +26 -0
diff -Nru a/scripts/setlocalversion.sh b/scripts/setlocalversion.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+BK=`which bk`
+MD5SUM=`which md5sum`
+
+srctree=$1
+objtree=$2
+
+if [ "$BK" == "" ];
+then
+	echo "scripts/setlocalversion.sh: Failed to find BK, not appending a -BK* version" >&2
+	exit 0
+fi
+
+if [ "$MD5SUM" == "" ];
+then
+	echo "scripts/setlocalversion.sh: Couldn't find md5sum, trying Perl version instead." >&2
+	exec perl scripts/setlocalversion $srctree $objtree
+fi
+
+cd $srctree
+changeset=`$BK changes -r+ -k`
+tag=`$BK prs -h -d':TAG:' -r'$changeset'`
+if [ "$tag" == "" ]; then
+	echo -n $changeset | md5sum | awk '{printf "-BK%s",substr($1,1,8)}'
+fi
Signature · 2 lines
Ryan Anderson
  sometimes Pug Majere
#1 lore raw
Quoted 9 lines · Ryan Anderson

Automatically append a semi-random version if the tree we're building isn't tagged in BitKeeper and CONFIG_LOCALVERSION_AUTO is set.

This fixes the case when Linus (or someone else) does a release and tags it, someone else does a build of that release tree (i.e, 2.6.11), and installs it. Later, before another release occurs (i.e, -rc1), another build happens, and the actual, released 2.6.11 is overwritten with the -current tree.

Quoted 4 lines

Two approachs are present here, a Perl version that is setup to handle other automatic version appends (i.e, a CVS version shouldn't be much effort to add), and a simplistic shell version that depends on "md5sum". Both approaches generate the same hash.

Please skip the shell version - add a note in Kconfig that enabling this option requires perl.

Quoted 10 lines

#export INSTALL_PATH=/boot

Makefile +7 -0
+# If CONFIG_LOCALVERSION_AUTO is set, we automatically perform some tests
+# and try to determine if the current source tree is a release tree, of any sort,
+# or if is a pure development tree.
+# A 'release tree' is any tree with a BitKeeper TAG associated with it.
+# The primary goal of this is to make it safe for a native BitKeeper user to
+# build a release tree (i.e, 2.6.9) and also to continue developing against the
+# current Linus tree, without having the Linus tree overwrite the 2.6.9 tree 

Makefile line 569

Quoted 10 lines
Makefile +10 -0
+# when installed.
+#
+# (In the future, CVS and SVN support will be added as well.)
+
+ifeq ($(CONFIG_LOCALVERSION_AUTO),y)
+	ifeq ($(shell ls -d $(srctree)/BitKeeper 2>/dev/null),$(srctree)/BitKeeper)
+		localversion-bk := $(shell $(srctree)/scripts/setlocalversion.sh $(srctree) $(objtree))
+		LOCALVERSION := $(LOCALVERSION)$(localversion-bk)
+	endif
+endif

Move the logic to determine the SCM system into the perl script. And do not assume bk, select more generic names.

Also use:
ifdef CONFIG_LOCALVERSION_AUTO
like in rest of Makefile.

Something like this:
ifdef CONFIG_LOCALVERSION_AUTO

    LOCALVERSION += $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion.sh $(srctree)

endif
note - perl script does not use objtree.

diff -Nru a/scripts/setlocalversion b/scripts/setlocalversion

Quoted 4 lines
scripts/setlocalversion new file +1 -0
@@ -0,0 +1,62 @@
+#!/usr/bin/perl

scripts/setlocalversion line 11

Quoted 10 lines
scripts/setlocalversion new file +10 -0
+# Copyright 2004 - Ryan Anderson <[email protected]>  GPL v2
+
+use strict;
+use warnings;
+use Digest::MD5;
+require 5.006;
+
+if (@ARGV != 2) {
+	print <<EOT;
+Usage: setlocalversion <srctree> <objtree>

wrong - objtree is not needed

scripts/setlocalversion line 16

Quoted 5 lines
scripts/setlocalversion new file +5 -0
+EOT
+	exit(1);
+}
+
+my $debug = 0;

remove debug for such a simple script

Quoted 4 lines
scripts/setlocalversion new file +4 -0
+
+my ($srctree,$objtree) = @ARGV;
+
+my @LOCALVERSIONS = ();

scripts/setlocalversion line 30

Quoted 10 lines
scripts/setlocalversion new file +10 -0
+
+# BitKeeper Version Checks
+
+# We are going to use the following commands to try and determine if
+# this repository is at a Version boundary (i.e, 2.6.10 vs 2.6.10 + some patches)
+# We currently assume that all meaningful version boundaries are marked by a tag.
+# We don't care what the tag is, just that something exists.
+
+#ryan@mythryan2 ~/dev/linux/local$ T=`bk changes -r+ -k`
+#ryan@mythryan2 ~/dev/linux/local$ bk prs -h -d':TAG:\n' -r$T

- to be deleted?

scripts/setlocalversion line 40

Quoted 10 lines
scripts/setlocalversion new file +10 -0
+
+sub do_bk_checks {
+	chdir($srctree);
+	my $changeset = `bk changes -r+ -k`;
+	chomp $changeset;
+	my $tag = `bk prs -h -d':TAG:' -r'$changeset'`;
+
+	printf("ChangeSet Key = '%s'\nTAG = '%s'\n", $changeset, $tag) if ($debug > 0);
+
+	if (length($tag) == 0) {

if this imply that this is not a release tree then please write so - to be consistent with comment in top-level makefile.
Thats good for poor sould like me that does not know perl.

Quoted 10 lines
scripts/setlocalversion new file +10 -0
+		# We do not have a tag at the Top of Tree, so we need to generate a localversion file
+		# We'll use the given $changeset as input into this.
+		my $localversion = Digest::MD5::md5_hex($changeset);
+		$localversion = substr($localversion,0,8);
+
+		printf("localversion = '%s'\n",$localversion) if ($debug > 0);
+
+		push @LOCALVERSIONS, "BK" . $localversion;
+
+	}

scripts/setlocalversion line 60

Quoted 10 lines
scripts/setlocalversion new file +10 -0
+}
+
+
+if ( -d "BitKeeper" ) {
+	my $bk = `which bk`;
+	chomp $bk;
+	if (length($bk) != 0) {
+		do_bk_checks();
+	}
+}

And this part should be prepared for cvs+svn.

Sam

#2 lore raw

Snipping a bit as I go, thanks for the feedback, Sam.

Quoted 8 lines · Sam Ravnborg
Quoted 4 lines · Ryan Anderson

Two approachs are present here, a Perl version that is setup to handle other automatic version appends (i.e, a CVS version shouldn't be much effort to add), and a simplistic shell version that depends on "md5sum". Both approaches generate the same hash.

Please skip the shell version - add a note in Kconfig that enabling this option requires perl.

Thanks. That makes this much easier to do.

Quoted 13 lines
Quoted 13 lines

#export INSTALL_PATH=/boot

Makefile +11 -0
+# If CONFIG_LOCALVERSION_AUTO is set, we automatically perform some tests
+# and try to determine if the current source tree is a release tree, of any sort,
+# or if is a pure development tree.
+# A 'release tree' is any tree with a BitKeeper TAG associated with it.
+# The primary goal of this is to make it safe for a native BitKeeper user to
+# build a release tree (i.e, 2.6.9) and also to continue developing against the
+# current Linus tree, without having the Linus tree overwrite the 2.6.9 tree 
+# when installed.
+#
+# (In the future, CVS and SVN support will be added as well.)
+
Quoted 8 lines

Makefile line 569

Quoted 6 lines
Makefile +6 -0
+ifeq ($(CONFIG_LOCALVERSION_AUTO),y)
+	ifeq ($(shell ls -d $(srctree)/BitKeeper 2>/dev/null),$(srctree)/BitKeeper)
+		localversion-bk := $(shell $(srctree)/scripts/setlocalversion.sh $(srctree) $(objtree))
+		LOCALVERSION := $(LOCALVERSION)$(localversion-bk)
+	endif
+endif

Move the logic to determine the SCM system into the perl script. And do not assume bk, select more generic names.

Ok, simple enough to do.

Quoted 9 lines

Also use:
ifdef CONFIG_LOCALVERSION_AUTO
like in rest of Makefile.

Something like this:
ifdef CONFIG_LOCALVERSION_AUTO

    LOCALVERSION += $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion.sh $(srctree)

endif
note - perl script does not use objtree.

I forget why I had that there - I'll remove it.

Quoted 4 lines

diff -Nru a/scripts/setlocalversion b/scripts/setlocalversion

Quoted 2 lines
scripts/setlocalversion new file +0 -0
Quoted 9 lines

scripts/setlocalversion line 30

Quoted 8 lines
scripts/setlocalversion new file +8 -0
+
+# We are going to use the following commands to try and determine if
+# this repository is at a Version boundary (i.e, 2.6.10 vs 2.6.10 + some patches)
+# We currently assume that all meaningful version boundaries are marked by a tag.
+# We don't care what the tag is, just that something exists.
+
+#ryan@mythryan2 ~/dev/linux/local$ T=`bk changes -r+ -k`
+#ryan@mythryan2 ~/dev/linux/local$ bk prs -h -d':TAG:\n' -r$T

- to be deleted?

I'll simply rewrite as a better explanation of what's going on, for the poor Perl neophytes. :)

Quoted 5 lines
Quoted 5 lines
scripts/setlocalversion new file +5 -0
+
+sub do_bk_checks {
+	chdir($srctree);
+	my $changeset = `bk changes -r+ -k`;
+	chomp $changeset;
Quoted 8 lines

scripts/setlocalversion line 40

Quoted 5 lines
scripts/setlocalversion new file +5 -0
+	my $tag = `bk prs -h -d':TAG:' -r'$changeset'`;
+
+	printf("ChangeSet Key = '%s'\nTAG = '%s'\n", $changeset, $tag) if ($debug > 0);
+
+	if (length($tag) == 0) {

if this imply that this is not a release tree then please write so - to be consistent with comment in top-level makefile.
Thats good for poor sould like me that does not know perl.

Ok, I think I've made what's going on much more apparent in my revised version.

Quoted 13 lines
Quoted 13 lines
scripts/setlocalversion new file +13 -0
+		# We do not have a tag at the Top of Tree, so we need to generate a localversion file
+		# We'll use the given $changeset as input into this.
+		my $localversion = Digest::MD5::md5_hex($changeset);
+		$localversion = substr($localversion,0,8);
+
+		printf("localversion = '%s'\n",$localversion) if ($debug > 0);
+
+		push @LOCALVERSIONS, "BK" . $localversion;
+
+	}
+}
+
+
Quoted 8 lines

scripts/setlocalversion line 60

Quoted 7 lines
scripts/setlocalversion new file +7 -0
+if ( -d "BitKeeper" ) {
+	my $bk = `which bk`;
+	chomp $bk;
+	if (length($bk) != 0) {
+		do_bk_checks();
+	}
+}

And this part should be prepared for cvs+svn.

I was going to implement the CVS version tonight, but I can't seem to find the bk2cvs tree (Google is failing).

I'll send an incremental patch when I do track it down, for now, I'll reply to this with my new version.

Again, thanks for the feedback.

Signature · 2 lines
Ryan Anderson
  sometimes Pug Majere
#3 lore raw

Automatically append a semi-random version if the tree we're building isn't tagged in BitKeeper (or another SCM) and CONFIG_LOCALVERSION_AUTO is set.

This fixes the case when Linus (or someone else) does a release and tags it, someone else does a build of that release tree (i.e, 2.6.11), and installs it. Later, before another release occurs (i.e, -rc1), another build happens, and the actual, released 2.6.11 is overwritten with the -current tree.

This currently supports BitKeeper only, but support for other SCMs is easy to add.

Makefile +20 -0
Index: local-quilt/Makefile
===================================================================
@@ -549,6 +549,26 @@ export KBUILD_IMAGE ?= vmlinux
 # images. Default is /boot, but you can set it to other values
 export	INSTALL_PATH ?= /boot
 
+# If CONFIG_LOCALVERSION_AUTO is set, we automatically perform some tests
+# and try to determine if the current source tree is a release tree, of any sort,
+# or if is a pure development tree.
+#
+# A 'release tree' is any tree with a BitKeeper, or other SCM, TAG associated
+# with it.  The primary goal of this is to make it safe for a native
+# BitKeeper/CVS/SVN user to build a release tree (i.e, 2.6.9) and also to
+# continue developing against the current Linus tree, without having the Linus
+# tree overwrite the 2.6.9 tree when installed.
+#
+# Currently, only BitKeeper is supported.
+# Other SCMs can edit scripts/setlocalversion and add the appropriate
+# checks as needed.
+
+
+ifdef CONFIG_LOCALVERSION_AUTO
+	localversion-auto := $(shell $(PERL) $(srctree)/scripts/setlocalversion $(srctree))
+	LOCALVERSION := $(LOCALVERSION)$(localversion-auto)
+endif
+
 #
 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
 # relocations required by build roots.  This is not defined in the
init/Kconfig +15 -0
Index: local-quilt/init/Kconfig
===================================================================
@@ -69,6 +69,21 @@ config LOCALVERSION
 	  object and source tree, in that order.  Your total string can
 	  be a maximum of 64 characters.
 
+config LOCALVERSION_AUTO
+	bool "Automatically append version information to the version string"
+	default y
+	help
+	  This will try to automatically determine if the current tree is a
+	  release tree by looking for BitKeeper, or other SCM tags that
+	  belong to the current top of tree revision.
+
+	  A string of the format -BKxxxxxxxx will be added to the
+	  localversion.  The string generated by this will be appended 
+	  after any matching localversion* files, and after the 
+	  value set in CONFIG_LOCALVERSION
+	  Note: This requires Perl and the Digest::MD5 module, as well
+	  as BitKeeper.
+
 config SWAP
 	bool "Support for paging of anonymous memory (swap)"
 	depends on MMU
scripts/setlocalversion new file +85 -0

85 lines not on this page · raw message

--
Ryan Anderson
sometimes Pug Majere

#4 lore raw

Sam, this version includes the CVS portion.

Automatically append a semi-random version if the tree we're building isn't tagged in BitKeeper or CVS and CONFIG_LOCALVERSION_AUTO is set.

This fixes the case when Linus (or someone else) does a release and tags it, someone else does a build of that release tree (i.e, 2.6.11), and installs it. Later, before another release occurs (i.e, -rc1), another build happens, and the actual, released 2.6.11 is overwritten with the -current tree.

This currently supports BitKeeper and CVS (assuming the format is the same as the BK->CVS tree)

Makefile +20 -0
Index: local-quilt/Makefile
===================================================================
@@ -549,6 +549,26 @@ export KBUILD_IMAGE ?= vmlinux
 # images. Default is /boot, but you can set it to other values
 export	INSTALL_PATH ?= /boot
 
+# If CONFIG_LOCALVERSION_AUTO is set, we automatically perform some tests
+# and try to determine if the current source tree is a release tree, of any sort,
+# or if is a pure development tree.
+#
+# A 'release tree' is any tree with a BitKeeper, or other SCM, TAG associated
+# with it.  The primary goal of this is to make it safe for a native
+# BitKeeper/CVS/SVN user to build a release tree (i.e, 2.6.9) and also to
+# continue developing against the current Linus tree, without having the Linus
+# tree overwrite the 2.6.9 tree when installed.
+#
+# Currently, only BitKeeper is supported.
+# Other SCMs can edit scripts/setlocalversion and add the appropriate
+# checks as needed.
+
+
+ifdef CONFIG_LOCALVERSION_AUTO
+	localversion-auto := $(shell $(PERL) $(srctree)/scripts/setlocalversion $(srctree))
+	LOCALVERSION := $(LOCALVERSION)$(localversion-auto)
+endif
+
 #
 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
 # relocations required by build roots.  This is not defined in the
init/Kconfig +18 -0
Index: local-quilt/init/Kconfig
===================================================================
@@ -69,6 +69,24 @@ config LOCALVERSION
 	  object and source tree, in that order.  Your total string can
 	  be a maximum of 64 characters.
 
+config LOCALVERSION_AUTO
+	bool "Automatically append version information to the version string"
+	default y
+	help
+	  This will try to automatically determine if the current tree is a
+	  release tree by looking for BitKeeper or CVS tags that
+	  belong to the current top of tree revision.
+
+	  A string of the format -BKxxxxxxxx will be added to the localversion
+	  if a BitKeeper based tree is found.  The string -cvs-$version will be
+	  added to the localversion if a CVS tree based on the BK->CVS tree is
+	  found.  The string generated by this will be appended after any
+	  matching localversion* files, and after the value set in
+	  CONFIG_LOCALVERSION
+
+	  Note: This requires Perl and the Digest::MD5 module, as well
+	  as BitKeeper and/or CVS.
+
 config SWAP
 	bool "Support for paging of anonymous memory (swap)"
 	depends on MMU
scripts/setlocalversion new file +120 -0

120 lines not on this page · raw message

#5 lore raw

Sam, my patch to automatically include a random value based upon the BitKeeper or CVS version in the kernel version had one, rather minor, bug related to building in seperate object and source trees.

This patch fixes that up.

scripts/setlocalversion +1 -2
Index: local-quilt/scripts/setlocalversion
===================================================================
@@ -14,6 +14,7 @@ EOT
 }
 
 my ($srctree) = @ARGV;
+chdir($srctree);
 
 my @LOCALVERSIONS = ();
 
@@ -39,7 +40,6 @@ my @LOCALVERSIONS = ();
 # -BK and the above 8 characters to the end of the version.
 
 sub do_bk_checks {
-	chdir($srctree);
 	my $changeset = `bk changes -r+ -k`;
 	chomp $changeset; # strip trailing \n safely
 	my $tag = `bk prs -h -d':TAG:' -r'$changeset'`;
@@ -69,7 +69,6 @@ sub do_bk_checks {
 # On this check, there is no real need for a MD5 hash, so
 # the revision number is used directly.
 sub do_cvs_checks {
-	chdir($srctree);
 	my $status = `LANG=C cvs status -v ChangeSet`;
 	my @lines = split /\n/, $status;
 
Signature · 2 lines
Ryan Anderson
  sometimes Pug Majere