lkml.org 
[lkml]   [2005]   [Mar]   [18]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateFri, 18 Mar 2005 01:23:41 -0500
FromRyan Anderson <>
SubjectRe: [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 <ryan@michonline.com>


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 <ryan@michonline.com>  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:
+#    bunk@stusta.de[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);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 14:11    [from the cache]
©2003-2008