From d20206cfc159281ae583274966a11d42318178ac Mon Sep 17 00:00:00 2001 From: pschwan Date: Tue, 26 Nov 2002 11:23:20 +0000 Subject: [PATCH] - legible whitespace - fixed off-by-one month bugs - rearrange the version string into a sensible, sortable string - use IO::File - fix 'use strict' and 'use diagnostics' errors - not everything is a regexp - fewer global variables --- lustre/scripts/version_tag.pl | 239 +++++++++++++++++++++++++----------------- 1 file changed, 145 insertions(+), 94 deletions(-) diff --git a/lustre/scripts/version_tag.pl b/lustre/scripts/version_tag.pl index 828cc13..e810f3f 100644 --- a/lustre/scripts/version_tag.pl +++ b/lustre/scripts/version_tag.pl @@ -1,105 +1,156 @@ #!/usr/bin/perl -$pristine=1; -if($ARGV[0]){chdir($ARGV[0]);} -get_linuxdir(); -get_tag(); -get_latest_mtime(); -generate_ver(); - -sub get_tag +# -*- 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; + +sub get_tag() { - $tag=open(TAG,"CVS/Tag"); - if(!$tag){ - $tag="HEAD"; - } else { - $tag=; - $tag=~/.(.*)$/; - $tag=$1; - close(TAG); - } + my $tag; + + my $tagfile = new IO::File; + if (!$tagfile->open("CVS/Tag")) { + return "HEAD"; + } else { + my $tmp = <$tagfile>; + $tagfile->close(); + + $tmp =~ m/T(.*)/; + return $1; + } } -sub get_latest_mtime + +sub get_latest_mtime() { - use Time::Local; - %months=("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5, - "Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10, - "Nov"=>11,"Dec"=>12); - - $last_mtime=0; - @entries=`find . -name Entries`; - foreach $entry(@entries){ - open(ENTRY,$entry); - while() { - $line=$_; - @temp_file_entry=split("/",$line); - $time_entry=$temp_file_entry[3]; - $file=$temp_file_entry[1]; - - $cur_dir=$entry; - $cur_dir=~s/\/CVS\/Entries$//g; - chomp($cur_dir); - ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, - $atime,$mtime,$ctime,$blksize,$blocks) - = stat($cur_dir."/".$file); - $local_date=gmtime($mtime); - if(! ($local_date =~ /$time_entry/) && - !($temp_file_entry[0] =~ /D/) && - !($file =~ /lustre\.spec\.in/)) { - #print "$file\n"; - $pristine=0; - } - - if($time_entry && - $file =~ m/\.c$|\.h$|\.am$|\.in$/ && - !($file =~ /lustre\.spec\.in/)){ - - @time=split(" ",$time_entry); - ($hours,$min,$sec)=split(":",$time[3]); - ($mday, $mon, $year)=($time[2],$time[1], - $time[4]); - $secs=0; - $mon=$months{$mon}; - if($mon>0 && $mon<13){ - $secs = 47114711; -# $secs=timelocal($sec,$min,$hours,$mday, $mon,$year); - } - if($secs>$last_mtime){ - $last_mtime=$secs; - $show_last=$hours.$min.$sec. - $year.$mon.$mday; - } - - } - } - close(ENTRY); - } + 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]; + 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 +sub get_linuxdir() { - open(CONFIG,"Makefile") or die "Run ./configure first \n"; - while($line=){ - $line =~ /LINUX = (.*)/; - if($1){$linuxdir=$1;last;} - } - close(CONFIG); - open(VER,"$linuxdir/include/linux/version.h") - or die "Run make dep on $linuxdir \n"; - while($line=){ - $line =~ /#define UTS_RELEASE "(.*)"/; - if($1){ $kernver=$1; last;} - } - chomp($kernver); - $linuxdir=~s/\//\./g; - close(VER); + 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 +sub generate_ver($$$) { - print "#define BUILD_VERSION \""; - if($pristine){ - print "$tag-$show_last-PRISTINE-$linuxdir-$kernver\"\n"; - }else{ - print "$tag-$show_last-CHANGED-$linuxdir-$kernver\"\n"; - } + 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 = $year . $mon . $mday . $hour . $min . $sec; + + print "#define BUILD_VERSION \""; + if ($pristine) { + print "$tag-$show_last-PRISTINE-$linuxdir-$kernver\"\n"; + } else { + print "$tag-$show_last-CHANGED-$linuxdir-$kernver\"\n"; + } +} + +if ($ARGV[0]) { + chdir($ARGV[0]); } +my $linuxdir = get_linuxdir(); +my $tag = get_tag(); +my $mtime = get_latest_mtime(); +generate_ver($tag, $mtime, $linuxdir); + +exit(0); -- 1.8.3.1