-
Notifications
You must be signed in to change notification settings - Fork 12
/
UpDateChangeLog.pl
executable file
·258 lines (229 loc) · 7.05 KB
/
UpDateChangeLog.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env perl
#=======================================================================
#
# This is a script to update the ChangeLog
#
# Usage:
#
# perl ChangeLog tag-name One-line summary
#
#
#=======================================================================
use strict;
use Getopt::Long;
use IO::File;
#use warnings;
#use diagnostics;
use English;
my $ProgName;
($ProgName = $PROGRAM_NAME) =~ s!(.*)/!!; # name of program
my $ProgDir = $1; # name of directory where program lives
sub usage {
die <<EOF;
SYNOPSIS
$ProgName [options] <tag-name> <one-line-summary>
OPTIONS
-compbrnch version Enter clm branch version to compare to (under branch_tags in repo).
[or -cb]
-comptrunk version Enter clm trunk version to compare to (under trunk_tags in repo).
[or -ct]
-help [or -h] Help on this script.
-update [or -u] Just update the date/time for the latest tag
In this case no other arguments should be given.
ARGUMENTS
<tag-name> Tag name of tag to document
<one-line-summary> Short summary description of this tag
EXAMPLES:
To just update the date/time for the latest tag
$ProgName -update
To document a new tag
$ProgName clm3_7_1 "Description of this tag"
To document a new tag and compare expected fails to previous tag.
$ProgName clm4_0_27 "Description of this tag" -ct clm4_0_26
EOF
}
my %opts = {
help => 0,
update => 0,
comptrunk => undef,
compbrnch => undef,
};
GetOptions(
"h|help" => \$opts{'help'},
"u|update" => \$opts{'update'},
"ct|comptrunk=s" => \$opts{'comptrunk'},
"cb|compbrnch=s" => \$opts{'compbrnch'},
);
if ( $opts{'help'} ) {
usage();
}
my $tag; my $sum;
if ( ! $opts{'update'} ) {
if ( $#ARGV != 1 ) {
print "ERROR: wrong number of arguments: $ARGV\n";
usage();
}
$tag = $ARGV[0];
$sum = $ARGV[1];
if ( $tag !~ /clm[0-9]+_(expa|[0-9]+)_[0-9]+/ ) {
print "ERROR: bad tagname: $tag\n";
usage();
}
} else {
if ( $#ARGV != -1 ) {
print "ERROR: wrong number of arguments when update option picked: $ARGV\n";
usage();
}
}
my $EDITOR = $ENV{EDITOR};
if ( $EDITOR !~ /.+/ ) {
print "ERROR: editor NOT set -- set the env variable EDITOR to the text editor you would like to use\n";
usage();
}
my $template = ".ChangeLog_template";
my $changelog = "ChangeLog";
my $changesum = "ChangeSum";
my $changelog_tmp = "ChangeLog.tmp";
my $changesum_tmp = "ChangeSum.tmp";
my $user = $ENV{USER};
if ( $user !~ /.+/ ) {
die "ERROR: Could not get user name: $user";
}
my @list = getpwnam( $user );
my $fullname = $list[6];
my $date = `date`;
chomp( $date );
if ( $date !~ /.+/ ) {
die "ERROR: Could not get date: $date\n";
}
#
# Deal with ChangeLog file
#
my $fh = IO::File->new($changelog_tmp, '>') or die "** $ProgName - can't open file: $changelog_tmp\n";
#
# If adding a new tag -- read in template and add information in
#
if ( ! $opts{'update'} ) {
open( TL, "<$template" ) || die "ERROR:: trouble opening file: $template";
while( $_ = <TL> ) {
if ( $_ =~ /Tag name:/ ) {
chomp( $_ );
print $fh "$_ $tag\n";
} elsif ( $_ =~ /Originator/ ) {
chomp( $_ );
print $fh "$_ $user ($fullname)\n";
} elsif ( $_ =~ /Date:/ ) {
chomp( $_ );
print $fh "$_ $date\n";
} elsif ( $_ =~ /One-line Summary:/ ) {
chomp( $_ );
print $fh "$_ $sum\n";
} elsif ( $_ =~ /CLM tag used for the baseline comparison tests if applicable:/ ) {
chomp( $_ );
if ( defined($opts{'comptrunk'}) ) {
print $fh "$_ $opts{'comptrunk'}\n";
&AddExpectedFailDiff( $fh, "trunk_tags/$opts{'comptrunk'}" );
} elsif ( defined($opts{'compbrnch'}) ) {
print $fh "$_ $opts{'compbrnch'}\n";
&AddExpectedFailDiff( $fh, "branch_tags/$opts{'compbrnch'}" );
} else {
print $fh "$_\n";
}
} else {
print $fh $_;
}
}
close( TL );
}
open( CL, "<$changelog" ) || die "ERROR:: trouble opening file: $changelog";
my $update = $opts{'update'};
my $oldTag = "";
while( $_ = <CL> ) {
# If adding a new tag check that new tag name does NOT match any old tag
if ( $_ =~ /Tag name:[ ]*(clm.+)/ ) {
$oldTag = $1;
if ( (! $opts{'update'}) && ($tag eq $oldTag) ) {
close( CL );
close( $fh );
system( "/bin/rm -f $changelog_tmp" );
print "ERROR:: New tag $tag matches a old tag name\n";
usage();
}
# If updating the date -- find first occurance of data and change it
# Then turn the update option to off
} elsif ( ($update) && ($_ =~ /(Date:)/) ) {
print $fh "Date: $date\n";
print "Update $oldTag with new date: $date\n";
$update = undef;
$_ = <CL>;
}
print $fh $_;
}
# Close files and move to final name
close( CL );
$fh->close( );
system( "/bin/mv $changelog_tmp $changelog" );
#
# Deal with ChangeSum file
#
open( FH, ">$changesum_tmp" ) || die "ERROR:: trouble opening file: $changesum_tmp";
open( CS, "<$changesum" ) || die "ERROR:: trouble opening file: $changesum";
my $update = $opts{'update'};
$date = `date "+%m/%d/%Y"`;
chomp( $date );
while( $_ = <CS> ) {
# Find header line
if ( $_ =~ /=====================/ ) {
print FH $_;
my $format = "%12.12s %12.12s %10.10s %s\n";
if ( $update ) {
$_ = <CS>;
if ( /^(.{12}) (.{12}) (.{10}) (.+)$/ ) {
$tag = $1;
$user = $2;
$sum = $4;
} else {
die "ERROR: bad format for ChangeSum file\n";
}
}
printf FH $format, $tag, $user, $date, $sum;
$_ = <CS>;
}
print FH $_;
}
# Close files and move to final name
close( CS );
close( FH );
system( "/bin/mv $changesum_tmp $changesum" );
#
# Edit the files
#
if ( ! $opts{'update'} ) {
system( "$EDITOR $changelog" );
system( "$EDITOR $changesum" );
}
system( "/bin/cp -fp $changelog models/lnd/clm/doc/." );
system( "/bin/cp -fp $changesum models/lnd/clm/doc/." );
system( "/bin/chmod 0444 models/lnd/clm/doc/$changelog" );
system( "/bin/chmod 0444 models/lnd/clm/doc/$changesum" );
sub AddExpectedFailDiff {
#
# Add information about the expected fail difference
#
my $fh = shift;
my $version = shift;
my $SVN_MOD_URL = "https://svn-ccsm-models.cgd.ucar.edu/clm2/";
my $expectedFail = `find . -name 'expected*Fail*.xml' -print`;
if ( $expectedFail eq "" ) {
die "ERROR:: expectedFails file NOT found here\n";
}
`svn ls $SVN_MOD_URL/$version` || die "ERROR:: Bad version to compare to: $version\n";
`svn ls $SVN_MOD_URL/$version/$expectedFail` || die "ERROR:: expectedFails file NOT found in: $version\n";
print $fh "\nDifference in expected fails from testing:\n\n";
my $diff = `svn diff --old $SVN_MOD_URL/$version/$expectedFail \ \n --new $expectedFail`;
if ( $diff eq "" ) {
print $fh " No change in expected failures in testing\n";
} else {
print $fh $diff;
}
}