~ubuntu-branches/ubuntu/intrepid/net-snmp/intrepid-updates

« back to all changes in this revision

Viewing changes to local/Version-Munge.pl

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2006-11-28 12:29:34 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128122934-82xxzy2zcvypnvy7
Tags: 5.2.3-4ubuntu1
* Merge from debian unstable, remaining changes:
  - remove stop links from rc0 and rc6

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
  -D           Compare files (cvs diff)
15
15
  -f FILE      Just do a particular file
16
16
  -t TYPE      Just do a particular type of file
17
 
 
 
17
  -P           Print resulting modified lines
18
18
  -V           verbose
19
19
";
20
20
    exit 1;
21
21
}
22
22
 
23
 
getopts("v:T:RCMDhnf:t:V",\%opts) || usage();
 
23
getopts("Pv:T:RCMDhnf:t:V",\%opts) || usage();
24
24
if ($opts{'h'}) { usage(); }
25
25
 
26
26
if (!$opts{'v'} && $opts{'M'} && !$opts{'T'}) {
43
43
             { type => 'docs',
44
44
               expr => 'Version: [\.0-9a-zA-Z]+' =>
45
45
               repl => 'Version: $VERSION', 
46
 
               files => [qw(README FAQ dist/net-snmp.spec)]},
 
46
               files => [qw(README FAQ dist/net-snmp.spec)],
 
47
               not_required => {'dist/net-snmp.spec' => 1}
 
48
             },
47
49
 
48
50
             # sed files
49
51
             { type => 'sed',
55
57
             { type => 'Makefile',
56
58
               expr => 'VERSION = \'(.*)\'',
57
59
               repl => 'VERSION = \'$VERSION\'',
58
 
               files => [qw(dist/Makefile)]},
 
60
               files => [qw(dist/Makefile)],
 
61
               not_required => {'dist/Makefile' => 1}
 
62
             },
59
63
 
60
64
             # Doxygen config
61
65
             { type => 'doxygen',
62
66
               expr => 'PROJECT_NUMBER(\s+)=(\s+)\'(.*)\'',
63
67
               repl => 'PROJECT_NUMBER$1=$2\'$VERSION\'',
64
 
               files => [qw(doxygen.conf)]},
 
68
               files => [qw(doxygen.conf)]
 
69
             },
65
70
 
66
71
             # perl files
67
72
             { type => 'perl',
68
73
               expr => 'VERSION = \'(.*)\'',
69
 
               repl => 'VERSION = \'$VERSION\'',
 
74
               repl => 'VERSION = \'$VERSION_FLOAT\'',
70
75
               files => [qw(perl/SNMP/SNMP.pm
71
76
                            perl/agent/agent.pm
 
77
                            perl/agent/Support/Support.pm
72
78
                            perl/agent/default_store/default_store.pm
73
79
                            perl/default_store/default_store.pm
74
80
                            perl/OID/OID.pm
76
82
                            perl/AnyData_SNMP/Storage.pm
77
83
                            perl/AnyData_SNMP/Format.pm
78
84
                            perl/TrapReceiver/TrapReceiver.pm
79
 
                           )]}
 
85
                           )],
 
86
               not_required => {'perl/agent/Support/Support.pm' => 1}
 
87
             },
 
88
 
 
89
             # configure script files
 
90
             { type => 'configure',
 
91
               expr => 'AC_INIT\\(\\[Net-SNMP\\], \\[([^\\]]+)\\]',
 
92
               repl => 'AC_INIT([Net-SNMP], [$VERSION]',
 
93
               files => [qw(configure.in)],
 
94
               exec => 'autoconf',
 
95
               exfiles => [qw(configure)],
 
96
             },
 
97
 
 
98
             # configure script files
 
99
             { type => 'doxygen',
 
100
               expr => 'PROJECT_NUMBER\s*= (.*)',
 
101
               repl => 'PROJECT_NUMBER         = $VERSION',
 
102
               files => [qw(doxygen.conf)],
 
103
             },
80
104
            );
81
105
 
 
106
#
 
107
# set up versioning information
 
108
#
82
109
if ($opts{'T'} && !$opts{'v'}) {
83
110
    $opts{'v'} = $opts{'T'};
84
111
    die "usage error: version tag must begin with Ext-" if ($opts{'T'} !~ /^Ext-/);
86
113
    $opts{'v'} =~ s/-/./g;
87
114
}
88
115
$VERSION = $opts{'v'};
89
 
 
 
116
$VERSION_FLOAT = floatize_version($VERSION);
 
117
 
 
118
 
 
119
#
 
120
# loop through all the expression types
 
121
#
 
122
my @files;
90
123
for ($i = 0; $i <= $#exprs; $i++) {
 
124
 
 
125
    # drop other file types if only one was requested.
91
126
    next if ($opts{'t'} && $exprs[$i]{'type'} ne $opts{'t'});
 
127
 
 
128
    # loop through each file and process
92
129
    foreach my $f (@{$exprs[$i]->{'files'}}) {
 
130
 
 
131
        # skip files that weren't specifically in the todo list if need be
93
132
        next if ($opts{'f'} && $f ne $opts{'f'});
 
133
 
 
134
        # remove the changes and revert to CVS
94
135
        if ($opts{'R'}) {
95
136
            print "removing changes and updating $f\n" if ($opts{'V'});
96
137
            unlink($f);
97
138
            system("cvs update $f");
98
139
        }
 
140
 
 
141
        # make sure it exists
 
142
        if (! -f $f) {
 
143
            if (!exists($exprs[$i]->{'not_required'}{$f})) {
 
144
                print STDERR "FAILED to find file $f\n";
 
145
                exit(1);
 
146
            } else {
 
147
                print STDERR "SKIPPING file $f\n";
 
148
                next;
 
149
            }
 
150
        }
 
151
 
 
152
        # modify the files with the version
99
153
        if ($opts{'M'}) {
100
154
            rename ($f,"$f.bak");
101
155
            open(I,"$f.bak");
102
156
            open(O,">$f");
103
157
            while (<I>) {
104
 
                eval "s/$exprs[$i]->{'expr'}/$exprs[$i]->{'repl'}/";
 
158
                my $res = eval "s/$exprs[$i]->{'expr'}/$exprs[$i]->{'repl'}/";
 
159
                if ($res && $opts{'P'}) {
 
160
                    my $shortened = $_;
 
161
                    $shortened =~ s/^\s*//;
 
162
                    printf("%s:\n          %s", $f, $shortened);
 
163
                }
105
164
                print O;
106
165
            }
107
166
            close(I);
108
167
            close(O);
109
168
            unlink("$f.bak");
 
169
            push @files, $f;
110
170
            print "modified $f using s/$exprs[$i]->{'expr'}/$exprs[$i]->{'repl'}/\n" if ($opts{'V'});
111
171
        }
 
172
 
 
173
        # run CVS diff if requested.
112
174
        if ($opts{'D'}) {
113
175
            print "diffing $f\n" if ($opts{'V'});
114
176
            system("cvs diff $f");
115
177
        }
116
 
        if ($opts{'C'}) {
117
 
            print "committing $f\n" if ($opts{'V'});
118
 
            system("cvs commit -m \"- ($f): version tag ( $VERSION )\" $f");
119
 
        }
120
178
    }
 
179
    system($exprs[$i]->{'exec'}) if ($exprs[$i]->{'exec'});
 
180
    push @files, @{$exprs[$i]->{'exfiles'}} if ($exprs[$i]->{'exfiles'});
 
181
}
 
182
 
 
183
#
 
184
# CVS commit the modified files
 
185
#
 
186
if ($opts{'C'}) {
 
187
    my $files = join(" ",@files);
 
188
    print "committing $files\n" if ($opts{'V'});
 
189
    $ret = system("cvs commit -m \"- version tag ( $VERSION )\" $files");
 
190
    exit($ret);
 
191
}
 
192
 
 
193
sub floatize_version {
 
194
    my ($major, $minor, $patch, $opps) = ($_[0] =~ /^(\d+)\.(\d+)\.?(\d*)\.?(\d*)/);
 
195
    return $major + $minor/100 + $patch/10000 + $opps/100000;
121
196
}