2005-03-09 08:07:52

by Ryan Anderson

[permalink] [raw]
Subject: [PATCH] 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.

Signed-Off-By: Ryan Anderson <[email protected]>

diff -Nru a/Makefile b/Makefile
--- a/Makefile 2005-03-09 02:51:15 -05:00
+++ b/Makefile 2005-03-09 02:51:15 -05:00
@@ -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
diff -Nru a/init/Kconfig b/init/Kconfig
--- a/init/Kconfig 2005-03-09 02:51:15 -05:00
+++ b/init/Kconfig 2005-03-09 02:51:15 -05:00
@@ -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
diff -Nru a/scripts/setlocalversion b/scripts/setlocalversion
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/scripts/setlocalversion 2005-03-09 02:51:15 -05:00
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+# 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>
+EOT
+ exit(1);
+}
+
+my $debug = 0;
+
+my ($srctree,$objtree) = @ARGV;
+
+my @LOCALVERSIONS = ();
+
+# 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
+
+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) {
+ # 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;
+
+ }
+}
+
+
+if ( -d "BitKeeper" ) {
+ my $bk = `which bk`;
+ chomp $bk;
+ if (length($bk) != 0) {
+ do_bk_checks();
+ }
+}
+
+printf "-%s\n", join("-",@LOCALVERSIONS) if (scalar @LOCALVERSIONS > 0);
diff -Nru a/scripts/setlocalversion.sh b/scripts/setlocalversion.sh
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/scripts/setlocalversion.sh 2005-03-09 02:51:15 -05:00
@@ -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


--

Ryan Anderson
sometimes Pug Majere


2005-03-14 22:49:48

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH] Automatically append a semi-random version for BK users

On Wed, Mar 09, 2005 at 03:06:38AM -0500, Ryan Anderson wrote:
> 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.

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

>
> #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
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
> --- /dev/null Wed Dec 31 16:00:00 196900
> +++ b/scripts/setlocalversion 2005-03-09 02:51:15 -05:00
> @@ -0,0 +1,62 @@
> +#!/usr/bin/perl
> +# 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

> +EOT
> + exit(1);
> +}
> +
> +my $debug = 0;
remove debug for such a simple script

> +
> +my ($srctree,$objtree) = @ARGV;
> +
> +my @LOCALVERSIONS = ();
> +
> +# 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?

> +
> +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.

> + # 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;
> +
> + }
> +}
> +
> +
> +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

2005-03-15 01:42:52

by Ryan Anderson

[permalink] [raw]
Subject: Re: [PATCH] Automatically append a semi-random version for BK users

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

On Mon, Mar 14, 2005 at 11:43:17PM +0100, Sam Ravnborg wrote:
> On Wed, Mar 09, 2005 at 03:06:38AM -0500, Ryan Anderson wrote:
> > 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.

> > #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
> 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.

> 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.

> diff -Nru a/scripts/setlocalversion b/scripts/setlocalversion
> > --- /dev/null Wed Dec 31 16:00:00 196900
> > +++ b/scripts/setlocalversion 2005-03-09 02:51:15 -05:00

> > +
> > +# 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. :)

> > +
> > +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.

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

> > + # 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;
> > +
> > + }
> > +}
> > +
> > +
> > +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.

--

Ryan Anderson
sometimes Pug Majere

2005-03-15 01:55:56

by Ryan Anderson

[permalink] [raw]
Subject: Re: [PATCH] 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 (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.

Signed-Off-By: Ryan Anderson <[email protected]>


Index: local-quilt/Makefile
===================================================================
--- local-quilt.orig/Makefile 2005-03-14 19:17:41.000000000 -0500
+++ local-quilt/Makefile 2005-03-14 20:45:11.000000000 -0500
@@ -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
Index: local-quilt/init/Kconfig
===================================================================
--- local-quilt.orig/init/Kconfig 2005-03-14 19:17:41.000000000 -0500
+++ local-quilt/init/Kconfig 2005-03-14 20:49:45.000000000 -0500
@@ -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
Index: local-quilt/scripts/setlocalversion
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ local-quilt/scripts/setlocalversion 2005-03-14 20:41:01.000000000 -0500
@@ -0,0 +1,85 @@
+#!/usr/bin/perl
+# Copyright 2004 - Ryan Anderson <[email protected]> GPL v2
+
+use strict;
+use warnings;
+use Digest::MD5;
+require 5.006;
+
+if (@ARGV != 1) {
+ print <<EOT;
+Usage: setlocalversion <srctree>
+EOT
+ exit(1);
+}
+
+my ($srctree) = @ARGV;
+
+my @LOCALVERSIONS = ();
+
+# 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.
+#
+# The process is as follows:
+#
+# 1. Get the key of the top of tree changeset:
+# cset=`bk changes -r+ -k`
+# This will be something like:
+# [email protected][torvalds]|ChangeSet|20050314010036|43252
+#
+# 2. Get the tag, if any, associated with it:
+# bk prs -h -d':TAG:\n' -r$cset
+#
+# 3. If no such tag exists, take the hex-encoded md5sum of the
+# changeset key, extract the first 8 characters of it, and add
+# -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'`;
+
+ if (length($tag) == 0) {
+ # There is no tag at the Top of Tree changeset, so this is not
+ # a release tree. To distinguish this from the previous
+ # release tree, something must be appended to the version to
+ # distinguish it.
+
+ # The changeset key in $changeset is unique, but unsuitable for
+ # direct use as a version, so semi-randomly mangle it using a
+ # MD5 hash.
+ my $localversion = Digest::MD5::md5_hex($changeset);
+ $localversion = substr($localversion,0,8);
+
+ push @LOCALVERSIONS, "BK" . $localversion;
+ }
+}
+
+# Stub for CVS checks
+sub do_cvs_checks {
+
+}
+
+
+if ( -d "BitKeeper" ) {
+ my $bk = `which bk`;
+ chomp $bk;
+ if (length($bk) != 0) {
+ do_bk_checks();
+ }
+}
+
+if ( -d "CVS" ) {
+ my $cvs = `which cvs`;
+ chomp $cvs;
+ if (length($cvs) != 0) {
+ do_cvs_checks();
+ }
+}
+
+printf "-%s\n", join("-",@LOCALVERSIONS) if (scalar @LOCALVERSIONS > 0);

--
Ryan Anderson
sometimes Pug Majere

2005-03-18 06:24:19

by Ryan Anderson

[permalink] [raw]
Subject: Re: [PATCH] Automatically append a semi-random version for BK users

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)

Signed-Off-By: Ryan Anderson <[email protected]>


Index: local-quilt/Makefile
===================================================================
--- local-quilt.orig/Makefile 2005-03-14 20:53:59.000000000 -0500
+++ local-quilt/Makefile 2005-03-14 20:54:02.000000000 -0500
@@ -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
Index: local-quilt/init/Kconfig
===================================================================
--- local-quilt.orig/init/Kconfig 2005-03-14 20:53:59.000000000 -0500
+++ local-quilt/init/Kconfig 2005-03-17 23:49:44.000000000 -0500
@@ -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
Index: local-quilt/scripts/setlocalversion
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ local-quilt/scripts/setlocalversion 2005-03-17 23:02:02.000000000 -0500
@@ -0,0 +1,120 @@
+#!/usr/bin/perl
+# Copyright 2004 - Ryan Anderson <[email protected]> GPL v2
+
+use strict;
+use warnings;
+use Digest::MD5;
+require 5.006;
+
+if (@ARGV != 1) {
+ print <<EOT;
+Usage: setlocalversion <srctree>
+EOT
+ exit(1);
+}
+
+my ($srctree) = @ARGV;
+
+my @LOCALVERSIONS = ();
+
+# 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.
+#
+# The process is as follows:
+#
+# 1. Get the key of the top of tree changeset:
+# cset=`bk changes -r+ -k`
+# This will be something like:
+# [email protected][torvalds]|ChangeSet|20050314010036|43252
+#
+# 2. Get the tag, if any, associated with it:
+# bk prs -h -d':TAG:\n' -r$cset
+#
+# 3. If no such tag exists, take the hex-encoded md5sum of the
+# changeset key, extract the first 8 characters of it, and add
+# -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'`;
+
+ if (length($tag) == 0) {
+ # There is no tag at the Top of Tree changeset, so this is not
+ # a release tree. To distinguish this from the previous
+ # release tree, something must be appended to the version to
+ # distinguish it.
+
+ # The changeset key in $changeset is unique, but unsuitable for
+ # direct use as a version, so semi-randomly mangle it using a
+ # MD5 hash.
+ my $localversion = Digest::MD5::md5_hex($changeset);
+ $localversion = substr($localversion,0,8);
+
+ push @LOCALVERSIONS, "BK" . $localversion;
+ }
+}
+
+# The BK->CVS gateway puts all tag information
+# in the file "ChangeSet", a 0-byte file.
+# The canonical top-of-tree can be found by looking at
+# the working revision of this file, and comparing that
+# to the version of the first tag encountered.
+#
+# 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;
+
+ my ($working_revision,$revision_of_first_tag, $foundtag);
+ $foundtag = 0;
+
+ foreach my $l (@lines) {
+ if ($l =~ m/Working revision:\W+(\d+\.\d+)\W/) {
+ $working_revision = $1;
+ next;
+ }
+
+ if ($l =~ m/Existing Tags:/) {
+ $foundtag = 1;
+ next;
+ }
+
+ if ($foundtag && $l =~ m/revision:\W+(\d+\.\d+)\)/) {
+ $revision_of_first_tag = $1;
+ last;
+ }
+ }
+
+ if ($working_revision != $revision_of_first_tag) {
+ push @LOCALVERSIONS, "cvs",$working_revision;
+ }
+
+
+}
+
+
+if ( -d "BitKeeper" ) {
+ my $bk = `which bk`;
+ chomp $bk;
+ if (length($bk) != 0) {
+ do_bk_checks();
+ }
+}
+
+if ( -d "CVS" ) {
+ my $cvs = `which cvs`;
+ chomp $cvs;
+ if (length($cvs) != 0) {
+ do_cvs_checks();
+ }
+}
+
+printf "-%s\n", join("-",@LOCALVERSIONS) if (scalar @LOCALVERSIONS > 0);

2005-04-02 23:43:29

by Ryan Anderson

[permalink] [raw]
Subject: Re: [PATCH] Automatically append a semi-random version for BK users

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.

Signed-Off-By: Ryan Anderson <[email protected]>

Index: local-quilt/scripts/setlocalversion
===================================================================
--- local-quilt.orig/scripts/setlocalversion 2005-04-02 18:29:21.000000000 -0500
+++ local-quilt/scripts/setlocalversion 2005-04-02 18:29:54.000000000 -0500
@@ -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;



--

Ryan Anderson
sometimes Pug Majere