source: ProjectBuilder/devel/pb/lib/ProjectBuilder/Changelog.pm

Last change on this file was 2498, checked in by Bruno Cornec, 4 years ago

Fix pb_version_init call

File size: 6.1 KB
RevLine 
[405]1#!/usr/bin/perl -w
2#
3# ProjectBuilder Changelog module
4# Changelog management subroutines brought by the the Project-Builder project
5#
6# $Id$
7#
[2488]8# Copyright B. Cornec 2007-today
[405]9# Provided under the GPL v2
10
11package ProjectBuilder::Changelog;
12
13use strict 'vars';
14use Data::Dumper;
15use English;
16use Date::Manip;
17use POSIX qw(strftime);
18use lib qw (lib);
[1764]19use Text::Wrap;
[1148]20use ProjectBuilder::Version;
[405]21use ProjectBuilder::Base;
22use ProjectBuilder::Conf;
23
24# Inherit from the "Exporter" module which handles exporting functions.
25
[1156]26use vars qw($VERSION $REVISION @ISA @EXPORT);
[405]27use Exporter;
28
29# Export, by default, all the functions into the namespace of
30# any code which uses this module.
31
32our @ISA = qw(Exporter);
33our @EXPORT = qw(pb_changelog);
[2498]34our ($VERSION,$REVISION,$PBCONFVER) = pb_version_init();
[405]35
36=pod
37
38=head1 NAME
39
40ProjectBuilder::Changelog, part of the project-builder.org - module dealing with changelog management
41
42=head1 DESCRIPTION
43
[409]44This modules provides generic functions suitable for changelog management for project-builder.org
[405]45
[409]46=head1 USAGE
47
48=over 4
49
50=item B<pb_changelog>
51
52Function that generates the changelog used in build files, or for announcements (web, mailing-list, ...)
53
[916]54It takes 3 parameters:
55The first parameter is the %pb hash containing packge info
56The second parameter is the file descriptor on which to write the changelog content.
57The third parameter is a flag in the configuration file indicating whether we want changelog expansion or not.
[409]58
[405]59=cut
60
61sub pb_changelog {
62
[543]63my $pb = shift;
[1192]64
65my $dtype = $pb->{'pbos'}->{'type'};
[543]66my $pbrealpkg = $pb->{'realpkg'};
67my $pbver = $pb->{'ver'};
68my $pbtag = $pb->{'tag'};
[1192]69my $pbsuf = $pb->{'pbos'}->{'suffix'};
[405]70my $OUTPUT = shift;
71my $doit = shift;
[1907]72my $chglog = $pb->{'chglog'};
[405]73
74my $log = "";
75
[2488]76pb_log(3,"Entering pb_changelog - pb: ".Dumper($pb)."\n");
77pb_log(3,"Entering pb_changelog - doit: $doit\n") if (defined $doit);
[405]78# For date handling
[2287]79$ENV{'LANG'}="C";
[405]80
81if ((not (defined $dtype)) || ($dtype eq "") ||
[543]82 (not (defined $pbrealpkg)) || ($pbrealpkg eq "") ||
[405]83 (not (defined $pbver)) || ($pbver eq "") ||
84 (not (defined $pbtag)) || ($pbtag eq "") ||
[585]85 (not (defined $pbsuf)) || ($pbsuf eq "") ||
[405]86 (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
87 (not (defined $doit)) || ($doit eq "")) {
[1192]88 pb_log(2,"Not enough input params\n");
[405]89 print $OUTPUT "\n";
90 return;
91}
92
93my $date;
94my $ndate;
95my $n2date;
96my $ver;
97my $ver2;
98my ($pbpackager) = pb_conf_get("pbpackager");
99
100if (not defined $pbpackager->{$ENV{'PBPROJ'}}) {
101 $pbpackager->{$ENV{'PBPROJ'}} = "undefined\@noproject.noorg";
102}
103
[544]104my @date = pb_get_date();
[405]105# If we don't need to do it, or don't have it fake something
[2491]106if (((not defined $chglog) || (! -f $chglog)) || ($doit ne "yes")) {
[1192]107 pb_log(2,"No ChangeLog file for $pbrealpkg - faking one\n");
[405]108 $date = strftime("%Y-%m-%d", @date);
109 $ndate = &UnixDate($date,"%a", "%b", "%d", "%Y");
110 $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
[1192]111 if ($dtype eq "rpm") {
[642]112 $ver2 = "$pbver-$pbtag";
[405]113 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
114 print $OUTPUT "- Updated to $pbver\n";
[1192]115 } elsif ($dtype eq "deb") {
[544]116 if ($pbver !~ /^[0-9]/) {
[916]117 # dpkg-deb doesn't accept non digit versions.
118 # Prepending 0 in order to make updates easy hopefully
119 $pbver =~ s/^/0/;
[544]120 }
[916]121 print $OUTPUT "$pbrealpkg ($pbver-$pbtag) unstable; urgency=low\n";
122 print $OUTPUT " * Updated to $pbver\n";
[405]123 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
[1192]124 } else {
125 pb_log(0,"No ChangeLog file for $pbrealpkg and no way faking one for type $dtype\n");
126 }
[405]127 return;
128}
129
[1262]130die "No changelog file for $pbrealpkg found at $ENV{'PBROOTDIR'}/$pbrealpkg/pbcl" if (not defined $chglog);
[1261]131
[405]132open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
133
134# Skip first 4 lines
135my $tmp = <INPUT>;
136$tmp = <INPUT>;
137$tmp = <INPUT>;
138if ($dtype eq "announce") {
[473]139 chomp($tmp);
140 print $OUTPUT "$tmp<br>\n";
[405]141}
142$tmp = <INPUT>;
143if ($dtype eq "announce") {
[473]144 chomp($tmp);
145 print $OUTPUT "$tmp<br>\n";
[405]146}
147
148my $first=1;
149
150# Handle each block separated by newline
151while (<INPUT>) {
152 ($ver, $date) = split(/ /);
[1432]153 # In case there is a v before the real version string
[405]154 $ver =~ s/^v//;
155 chomp($date);
156 $date =~ s/\(([0-9-]+)\)/$1/;
[916]157 pb_log(3,"**Date:$date**\n");
[405]158 $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
159 $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
[916]160 pb_log(3,"**nDate:$ndate**\n");
[405]161
[916]162 pb_log(3,"**Ver:$ver**\n");
163 if ($ver !~ /-/) {
164 if ($first eq 1) {
[2109]165 $ver2 = "$ver-$pbtag";
[916]166 $first = 0;
[405]167 } else {
[916]168 $ver2 = "$ver-1";
[405]169 }
[916]170 } else {
171 $ver2 = $ver;
172 }
173 pb_log(3,"**Ver2:$ver2**\n");
174
175 if (($dtype eq "rpm") || ($dtype eq "fc")) {
[405]176 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
177 print $OUTPUT "- Updated to $ver\n";
178 }
179 if ($dtype eq "deb") {
[916]180 if ($ver2 !~ /^[0-9]/) {
181 # dpkg-deb doesn't accept non digit versions.
182 # Prepending 0 in order to make updates easy hopefully
183 $ver2 =~ s/^/0/;
[544]184 }
[916]185 print $OUTPUT "$pbrealpkg ($ver2) unstable; urgency=low\n";
[405]186 print $OUTPUT "\n";
[2107]187 }
[405]188
189 $tmp = <INPUT>;
[1791]190 while ((defined $tmp) && ($tmp !~ /^$/)) {
[405]191 if ($dtype eq "deb") {
192 $tmp =~ s/^- //;
[1764]193 $Text::Wrap::columns = 80;
194 print $OUTPUT " * ".wrap('',' ',$tmp);
[405]195 } elsif ($dtype eq "rpm") {
196 print $OUTPUT "$tmp";
197 } else {
[473]198 chomp($tmp);
199 print $OUTPUT "$tmp<br>\n";
[405]200 }
201 last if (eof(INPUT));
202 $tmp = <INPUT>;
203 }
204 print $OUTPUT "\n";
205
206 if ($dtype eq "deb") {
207 # Cf: http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
208 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
209 }
210
211 last if (eof(INPUT));
212 last if ($dtype eq "announce");
213}
214close(INPUT);
[2488]215pb_log(3,"Exiting pb_changelog\n");
[405]216}
217
[409]218
219=back
220
221=head1 WEB SITES
222
223The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
224
225=head1 USER MAILING LIST
226
227None exists for the moment.
228
229=head1 AUTHORS
230
231The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
232
233=head1 COPYRIGHT
234
235Project-Builder.org is distributed under the GPL v2.0 license
236described in the file C<COPYING> included with the distribution.
237
238=cut
239
[405]2401;
Note: See TracBrowser for help on using the repository browser.