From 4b550a38c5e261abe74ec323780d22c631988f16 Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 10 Jun 2009 20:22:14 +0000 Subject: [PATCH] b=16424 i=rread i=yangsheng Allow builds from tarball (i.e. those without CVS subdirs) to properly populate the Lustre version field. This is done by saving the date that would have been found in the CVS files into a status file when buiding the tarball and then using that when building from tarball. --- autoMakefile.am | 5 + build/autoMakefile.am.toplevel | 4 + lustre/autoconf/lustre-core.m4 | 1 - lustre/scripts/Makefile.am | 7 +- lustre/scripts/version_tag.pl | 247 +++++++++++++++++++++++++++++++++++++++ lustre/scripts/version_tag.pl.in | 197 ------------------------------- 6 files changed, 261 insertions(+), 200 deletions(-) create mode 100644 lustre/scripts/version_tag.pl delete mode 100644 lustre/scripts/version_tag.pl.in diff --git a/autoMakefile.am b/autoMakefile.am index 4cf28fb..0876803 100644 --- a/autoMakefile.am +++ b/autoMakefile.am @@ -32,3 +32,8 @@ checkstack-update: checkstack-clean: rm -f ${CSTK} ${CSTKO} + +module-dist-hook: + if [ -d CVS -o -d .git ]; then \ + perl lustre/scripts/tree_status.pl > $(distdir)/tree_status; \ + fi diff --git a/build/autoMakefile.am.toplevel b/build/autoMakefile.am.toplevel index f07df3e..3f4e235 100644 --- a/build/autoMakefile.am.toplevel +++ b/build/autoMakefile.am.toplevel @@ -74,7 +74,11 @@ dist-hook: find $(distdir) -name .deps -o \ -name CVS -o \ -name .svn -o \ + -name .git -o \ -name .#* | xargs rm -rf + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$(top_distdir)" distdir="$(distdir)" \ + module-dist-hook EXTRA_DIST = @PACKAGE_TARNAME@.spec \ build/Makefile build/autoMakefile.am.toplevel build/lbuild \ diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index bcf509e..77ac191 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -2196,7 +2196,6 @@ lustre/ptlrpc/gss/autoMakefile lustre/quota/Makefile lustre/quota/autoMakefile lustre/scripts/Makefile -lustre/scripts/version_tag.pl lustre/tests/Makefile lustre/tests/mpi/Makefile lustre/utils/Makefile diff --git a/lustre/scripts/Makefile.am b/lustre/scripts/Makefile.am index 15d05c2..8eebb58 100644 --- a/lustre/scripts/Makefile.am +++ b/lustre/scripts/Makefile.am @@ -43,9 +43,9 @@ genscripts = lustre_config lc_modprobe lc_net lc_hb lc_cluman lustre_createcsv \ sbin_SCRIPTS = $(genscripts) $(sbinscripts) bin_SCRIPTS = lustre_req_history -EXTRA_DIST = license-status maketags.sh version_tag.pl.in lc_common \ +EXTRA_DIST = license-status maketags.sh version_tag.pl lc_common \ $(addsuffix .in,$(genscripts)) lc_mon $(sbinscripts) \ - $(bin_SCRIPTS) + $(bin_SCRIPTS) tree_status.pl scriptlibdir = $(libdir)/@PACKAGE@ scriptlib_DATA = lc_common @@ -55,3 +55,6 @@ CLEANFILES = $(genscripts) $(genscripts): %: %.in sed -e 's#@scriptlibdir@#$(scriptlibdir)#' < $< > $@ chmod +x $@ + +tree_status.pl: version_tag.pl + ln version_tag.pl tree_status.pl diff --git a/lustre/scripts/version_tag.pl b/lustre/scripts/version_tag.pl new file mode 100644 index 0000000..8ae53ae --- /dev/null +++ b/lustre/scripts/version_tag.pl @@ -0,0 +1,247 @@ +#!/usr/bin/perl +# -*- Mode: perl; indent-tabs-mode: nil; cperl-indent-level: 4 -*- + +use strict; +use diagnostics; +use IO::File; +use Time::Local; + +my $pristine = 1; +my $kernver = ""; + +# Use the CVS tag first otherwise use the portals version +sub get_tag() +{ + my $tag; + my $line; + + my $tagfile = new IO::File; + if (!$tagfile->open("lustre/CVS/Tag")) { + # is there a good way to do this with git or should the git case just + # fall through to use config.h? it is always nice to know if we are + # working on a tag or branch. + my $verfile = new IO::File; + if (!$verfile->open("config.h")) { + return "UNKNOWN"; + } + while(defined($line = <$verfile>)) { + $line =~ /\#define VERSION "(.*)"/; + if ($1) { + $tag = $1; + last; + } + } + $verfile->close(); + return $tag + } else { + my $tmp = <$tagfile>; + $tagfile->close(); + + $tmp =~ m/[TN](.*)/; + return $1; + } +} + +sub get_latest_mtime() +{ + my %months=("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, + "Jun" => 5, "Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, + "Nov" => 10, "Dec" => 11); + + my $last_mtime = 0; + + # a CVS checkout + if (-d "CVS") { + # if we got here, we are operating in a CVS checkout + my @entries = `find . -name Entries`; + my $entry_file; + foreach $entry_file (@entries) { + chomp($entry_file); + my $entry = new IO::File; + if (!$entry->open($entry_file)) { + die "unable to open $entry_file: $!\n"; + } + my $line; + while (defined($line = <$entry>)) { + chomp($line); + #print "line: $line\n"; + my ($junk, $file, $version, $date) = split(/\//, $line); + + #print "junk: $junk\nfile: $file\nver: $version\ndate: $date\n"; + #print "last_mtime: " . localtime($last_mtime) . "\n"; + + if ($junk eq "D" || + $file eq "lustre.spec.in") { + # also used to skip: "$file !~ m/\.(c|h|am|in)$/" but I see + # no good reason why only the above file patterns should + # count towards pristine/changed. it should be any file, + # surely. + next; + } + + my $cur_dir = $entry_file; + $cur_dir =~ s/\/CVS\/Entries$//; + my @statbuf = stat("$cur_dir/$file"); + my $mtime = $statbuf[9]; + if (!defined($mtime)) { + next; + } + my $local_date = gmtime($mtime); + if ($local_date ne $date && + $file ne "lustre.spec.in") { + #print "$file : " . localtime($mtime) . "\n"; + $pristine = 0; + } + + if ($mtime > $last_mtime) { + $last_mtime = $mtime; + } + + if ($date) { + my @t = split(/ +/, $date); + if (int(@t) != 5) { + #print "skipping: $date\n"; + next; + } + my ($hours, $min, $sec) = split(/:/, $t[3]); + my ($mon, $mday, $year) = ($t[1], $t[2], $t[4]); + my $secs = 0; + $mon = $months{$mon}; + $secs = timelocal($sec, $min, $hours, $mday, $mon, $year); + if ($secs > $last_mtime) { + $last_mtime = $secs; + } + } + } + $entry->close(); + } + } elsif (-d ".git") { + # a git checkout + # TODO: figure out how to determine the most recently modified file + # in a git working copy. + # NOTE: this is not simply the newest file in the whole tree, + # but the newest file in the tree that is from the + # repository. + $last_mtime = time(); + } else { + my $tree_status = new IO::File; + if (!$tree_status->open("tree_status")) { + die "unable to open the tree_status file: $!\n"; + } + my $line; + while (defined($line = <$tree_status>)) { + if ($line =~ /^PRISTINE\s*=\s*(\d)/) { + $pristine = $1; + } elsif ($line =~ /^MTIME\s*=\s*(\d+)/) { + $last_mtime = $1; + } + } + } + return $last_mtime; + +} + +sub get_linuxdir() +{ + my $config = new IO::File; + my ($line, $dir); + if (!$config->open("autoMakefile")) { + die "Run ./configure first\n"; + } + while (defined($line = <$config>)) { + chomp($line); + if ($line =~ /LINUX :?= (.*)/) { + $dir = $1; + last; + } + } + $config->close(); + my $ver = new IO::File; + if (!$ver->open("$dir/include/linux/utsrelease.h")) { + if (!$ver->open("$dir/include/linux/version.h")) { + die "Run make dep on $dir\n"; + } + } + while(defined($line = <$ver>)) { + $line =~ /\#define UTS_RELEASE "(.*)"/; + if ($1) { + $kernver = $1; + last; + } + } + $ver->close(); + chomp($kernver); + $dir =~ s/\//\./g; + return $dir; +} + +sub mtime2date($) +{ + my $mtime = shift; + + my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = + localtime($mtime); + $year += 1900; + $mon++; + my $show_last = sprintf("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, + $hour, $min, $sec); + + return $show_last; +} + +sub generate_ver($$$) +{ + my $tag = shift; + my $mtime = shift; + my $linuxdir = shift; + + #print "localtime: " . localtime($mtime) . "\n"; + + my $show_last = mtime2date($mtime); + + print "#define BUILD_VERSION \""; + + my $lustre_vers = $ENV{LUSTRE_VERS}; + + if ($lustre_vers) { + print "$tag-$lustre_vers\"\n"; + # if we want to get rid of the PRISTINE/CHANGED thing, get rid of these + # lines. maybe we only want to print -CHANGED when something is changed + # and print nothing when it's pristine + } elsif ($pristine) { + print "$tag-$show_last-PRISTINE-$linuxdir-$kernver\"\n"; + } else { + print "$tag-$show_last-CHANGED-$linuxdir-$kernver\"\n"; + } +} + +my $progname = $0; +$progname =~ s/.*\///; + +if ($progname eq "tree_status.pl" && !-d "CVS" && !-d ".git") { + die("a tree status can only be determined in an source code control system checkout\n"); +} + +chomp(my $cwd = `pwd`); + +# ARGV[0] = srcdir +# ARGV[1] = builddir + +# for get_latest_mtime and get_tag you need to be in srcdir + +if ($ARGV[0]) { + chdir($ARGV[0]); +} +my $tag = get_tag(); +my $mtime = get_latest_mtime(); + +if ($progname eq "version_tag.pl") { + my $linuxdir = get_linuxdir(); + $linuxdir =~ s/\//\./g; + generate_ver($tag, $mtime, $linuxdir); +} elsif ($progname eq "tree_status.pl") { + print "PRISTINE = $pristine\n"; + print "MTIME = $mtime\n"; +} + +exit(0); diff --git a/lustre/scripts/version_tag.pl.in b/lustre/scripts/version_tag.pl.in deleted file mode 100644 index c341642..0000000 --- a/lustre/scripts/version_tag.pl.in +++ /dev/null @@ -1,197 +0,0 @@ -#!/usr/bin/perl -# -*- Mode: perl; indent-tabs-mode: nil; cperl-indent-level: 4 -*- - -use strict; -use diagnostics; -use IO::File; -use Time::Local; - -my $pristine = 1; -my $kernver; - -# Use the CVS tag first otherwise use the portals version -sub get_tag() -{ - my $tag; - my $line; - - my $tagfile = new IO::File; - if (!$tagfile->open("lustre/CVS/Tag")) { - my $verfile = new IO::File; - if (!$verfile->open("config.h")) { - return "UNKNOWN"; - } - while(defined($line = <$verfile>)) { - $line =~ /\#define VERSION "(.*)"/; - if ($1) { - $tag = $1; - last; - } - } - $verfile->close(); - return $tag - } else { - my $tmp = <$tagfile>; - $tagfile->close(); - - $tmp =~ m/T(.*)/; - return $1; - } -} - -sub get_latest_mtime() -{ - my %months=("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, - "Jun" => 5, "Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, - "Nov" => 10, "Dec" => 11); - - my $last_mtime = 0; - my @entries = `find . -name Entries`; - my $entry_file; - foreach $entry_file (@entries) { - chomp($entry_file); - my $entry = new IO::File; - if (!$entry->open($entry_file)) { - die "unable to open $entry_file: $!\n"; - } - my $line; - while (defined($line = <$entry>)) { - chomp($line); - #print "line: $line\n"; - my ($junk, $file, $version, $date) = split(/\//, $line); - - #print "junk: $junk\nfile: $file\nver: $version\ndate: $date\n"; - #print "last_mtime: " . localtime($last_mtime) . "\n"; - - if ($junk eq "D" || - $file eq "lustre.spec.in" || - $file !~ m/\.(c|h|am|in)$/) { - next; - } - - my $cur_dir = $entry_file; - $cur_dir =~ s/\/CVS\/Entries$//; - my @statbuf = stat("$cur_dir/$file"); - my $mtime = $statbuf[9]; - if (!defined($mtime)) { - next; - } - my $local_date = gmtime($mtime); - if ($local_date ne $date && - $file ne "lustre.spec.in") { - #print "$file : " . localtime($mtime) . "\n"; - $pristine = 0; - } - - if ($mtime > $last_mtime) { - $last_mtime = $mtime; - } - - if ($date) { - my @t = split(/ +/, $date); - if (int(@t) != 5) { - #print "skipping: $date\n"; - next; - } - my ($hours, $min, $sec) = split(/:/, $t[3]); - my ($mon, $mday, $year) = ($t[1], $t[2], $t[4]); - my $secs = 0; - $mon = $months{$mon}; - $secs = timelocal($sec, $min, $hours, $mday, $mon, $year); - if ($secs > $last_mtime) { - $last_mtime = $secs; - } - } - } - $entry->close(); - } - return $last_mtime; -} - -sub get_linuxdir() -{ - my $config = new IO::File; - my ($line, $dir); - if (!$config->open("Makefile")) { - die "Run ./configure first\n"; - } - while (defined($line = <$config>)) { - chomp($line); - if ($line =~ /LINUX :?= (.*)/) { - $dir = $1; - last; - } - } - $config->close(); - my $ver = new IO::File; - if (!$ver->open("$dir/include/linux/version.h")) { - die "Run make dep on $dir\n"; - } - while(defined($line = <$ver>)) { - $line =~ /\#define UTS_RELEASE "(.*)"/; - if ($1) { - $kernver = $1; - last; - } - } - $ver->close(); - chomp($kernver); - $dir =~ s/\//\./g; - return $dir; -} - -sub generate_ver($$$) -{ - my $tag = shift; - my $mtime = shift; - my $linuxdir = shift; - - #print "localtime: " . localtime($mtime) . "\n"; - - my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = - localtime($mtime); - $year += 1900; - $mon++; - my $show_last = sprintf("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, - $hour, $min, $sec); - - print "#define BUILD_VERSION \""; - - my $lustre_vers = $ENV{LUSTRE_VERS}; - - if ($lustre_vers) { - print "$tag-$lustre_vers\"\n"; - } elsif ($pristine) { - print "$tag-$show_last-PRISTINE-$linuxdir-$kernver\"\n"; - } else { - print "$tag-$show_last-CHANGED-$linuxdir-$kernver\"\n"; - } -} -chomp(my $cwd = `pwd`); - -# ARGV[0] = srcdir -# ARGV[1] = builddir - -# for get_latest_mtime and get_tag you need to be in srcdir - -if ($ARGV[0]) { - chdir($ARGV[0]); -} -my $tag = get_tag(); -my $mtime = get_latest_mtime(); - -# for get_linuxdir you need to be in builddir - -#if ($ARGV[1]) { -# chdir($cwd); -# chdir($ARGV[1]); -#} -#my $linuxdir = get_linuxdir(); - -my $linuxdir = '@LINUX@'; -$linuxdir =~ s/\//\./g; -$kernver = '@LINUXRELEASE@'; - -generate_ver($tag, $mtime, $linuxdir); - -exit(0); -- 1.8.3.1