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

Last change on this file since 2109 was 2109, checked in by Bruno Cornec, 8 years ago

Fix changelog generation with new test names

File size: 6.1 KB
Line 
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#
8# Copyright B. Cornec 2007-2016
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);
19use Text::Wrap;
20use ProjectBuilder::Version;
21use ProjectBuilder::Base;
22use ProjectBuilder::Conf;
23
24# Inherit from the "Exporter" module which handles exporting functions.
25
26use vars qw($VERSION $REVISION @ISA @EXPORT);
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);
34($VERSION,$REVISION) = pb_version_init();
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
44This modules provides generic functions suitable for changelog management for project-builder.org
45
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
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.
58
59=cut
60
61sub pb_changelog {
62
63my $pb = shift;
64
65my $dtype = $pb->{'pbos'}->{'type'};
66my $pbrealpkg = $pb->{'realpkg'};
67my $pbver = $pb->{'ver'};
68my $pbtag = $pb->{'tag'};
69my $pbsuf = $pb->{'pbos'}->{'suffix'};
70my $OUTPUT = shift;
71my $doit = shift;
72my $chglog = $pb->{'chglog'};
73
74my $log = "";
75
76pb_log(2,"Entering pb_changelog - pb: ".Dumper($pb)."\n");
77pb_log(2,"Entering pb_changelog - doit: $doit\n") if (defined $doit);
78pb_log(2,"Entering pb_changelog - OUTPUT: $OUTPUT\n") if (defined $OUTPUT);
79# For date handling
80$ENV{LANG}="C";
81
82if ((not (defined $dtype)) || ($dtype eq "") ||
83 (not (defined $pbrealpkg)) || ($pbrealpkg eq "") ||
84 (not (defined $pbver)) || ($pbver eq "") ||
85 (not (defined $pbtag)) || ($pbtag eq "") ||
86 (not (defined $pbsuf)) || ($pbsuf eq "") ||
87 (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
88 (not (defined $doit)) || ($doit eq "")) {
89 pb_log(2,"Not enough input params\n");
90 print $OUTPUT "\n";
91 return;
92}
93
94my $date;
95my $ndate;
96my $n2date;
97my $ver;
98my $ver2;
99my ($pbpackager) = pb_conf_get("pbpackager");
100
101if (not defined $pbpackager->{$ENV{'PBPROJ'}}) {
102 $pbpackager->{$ENV{'PBPROJ'}} = "undefined\@noproject.noorg";
103}
104
105my @date = pb_get_date();
106# If we don't need to do it, or don't have it fake something
107if (((not defined $chglog) || (! -f $chglog)) && ($doit ne "yes")) {
108 pb_log(2,"No ChangeLog file for $pbrealpkg - faking one\n");
109 $date = strftime("%Y-%m-%d", @date);
110 $ndate = &UnixDate($date,"%a", "%b", "%d", "%Y");
111 $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
112 if ($dtype eq "rpm") {
113 $ver2 = "$pbver-$pbtag";
114 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
115 print $OUTPUT "- Updated to $pbver\n";
116 } elsif ($dtype eq "deb") {
117 if ($pbver !~ /^[0-9]/) {
118 # dpkg-deb doesn't accept non digit versions.
119 # Prepending 0 in order to make updates easy hopefully
120 $pbver =~ s/^/0/;
121 }
122 print $OUTPUT "$pbrealpkg ($pbver-$pbtag) unstable; urgency=low\n";
123 print $OUTPUT " * Updated to $pbver\n";
124 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
125 } else {
126 pb_log(0,"No ChangeLog file for $pbrealpkg and no way faking one for type $dtype\n");
127 }
128 return;
129}
130
131die "No changelog file for $pbrealpkg found at $ENV{'PBROOTDIR'}/$pbrealpkg/pbcl" if (not defined $chglog);
132
133open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
134
135# Skip first 4 lines
136my $tmp = <INPUT>;
137$tmp = <INPUT>;
138$tmp = <INPUT>;
139if ($dtype eq "announce") {
140 chomp($tmp);
141 print $OUTPUT "$tmp<br>\n";
142}
143$tmp = <INPUT>;
144if ($dtype eq "announce") {
145 chomp($tmp);
146 print $OUTPUT "$tmp<br>\n";
147}
148
149my $first=1;
150
151# Handle each block separated by newline
152while (<INPUT>) {
153 ($ver, $date) = split(/ /);
154 # In case there is a v before the real version string
155 $ver =~ s/^v//;
156 chomp($date);
157 $date =~ s/\(([0-9-]+)\)/$1/;
158 pb_log(3,"**Date:$date**\n");
159 $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
160 $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
161 pb_log(3,"**nDate:$ndate**\n");
162
163 pb_log(3,"**Ver:$ver**\n");
164 if ($ver !~ /-/) {
165 if ($first eq 1) {
166 $ver2 = "$ver-$pbtag";
167 $first = 0;
168 } else {
169 $ver2 = "$ver-1";
170 }
171 } else {
172 $ver2 = $ver;
173 }
174 pb_log(3,"**Ver2:$ver2**\n");
175
176 if (($dtype eq "rpm") || ($dtype eq "fc")) {
177 print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
178 print $OUTPUT "- Updated to $ver\n";
179 }
180 if ($dtype eq "deb") {
181 if ($ver2 !~ /^[0-9]/) {
182 # dpkg-deb doesn't accept non digit versions.
183 # Prepending 0 in order to make updates easy hopefully
184 $ver2 =~ s/^/0/;
185 }
186 print $OUTPUT "$pbrealpkg ($ver2) unstable; urgency=low\n";
187 print $OUTPUT "\n";
188 }
189
190 $tmp = <INPUT>;
191 while ((defined $tmp) && ($tmp !~ /^$/)) {
192 if ($dtype eq "deb") {
193 $tmp =~ s/^- //;
194 $Text::Wrap::columns = 80;
195 print $OUTPUT " * ".wrap('',' ',$tmp);
196 } elsif ($dtype eq "rpm") {
197 print $OUTPUT "$tmp";
198 } else {
199 chomp($tmp);
200 print $OUTPUT "$tmp<br>\n";
201 }
202 last if (eof(INPUT));
203 $tmp = <INPUT>;
204 }
205 print $OUTPUT "\n";
206
207 if ($dtype eq "deb") {
208 # Cf: http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
209 print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
210 }
211
212 last if (eof(INPUT));
213 last if ($dtype eq "announce");
214}
215close(INPUT);
216pb_log(2,"Exiting pb_changelog\n");
217}
218
219
220=back
221
222=head1 WEB SITES
223
224The 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/>.
225
226=head1 USER MAILING LIST
227
228None exists for the moment.
229
230=head1 AUTHORS
231
232The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
233
234=head1 COPYRIGHT
235
236Project-Builder.org is distributed under the GPL v2.0 license
237described in the file C<COPYING> included with the distribution.
238
239=cut
240
2411;
Note: See TracBrowser for help on using the repository browser.