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