[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 | #
|
---|
| 8 | # Copyright B. Cornec 2007
|
---|
| 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);
|
---|
[1764] | 19 | use Text::Wrap;
|
---|
[1148] | 20 | use ProjectBuilder::Version;
|
---|
[405] | 21 | use ProjectBuilder::Base;
|
---|
| 22 | use ProjectBuilder::Conf;
|
---|
| 23 |
|
---|
| 24 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 25 |
|
---|
[1156] | 26 | use vars qw($VERSION $REVISION @ISA @EXPORT);
|
---|
[405] | 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);
|
---|
[1156] | 34 | ($VERSION,$REVISION) = pb_version_init();
|
---|
[405] | 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 |
|
---|
[409] | 44 | This 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 |
|
---|
| 52 | Function that generates the changelog used in build files, or for announcements (web, mailing-list, ...)
|
---|
| 53 |
|
---|
[916] | 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.
|
---|
[409] | 58 |
|
---|
[405] | 59 | =cut
|
---|
| 60 |
|
---|
| 61 | sub pb_changelog {
|
---|
| 62 |
|
---|
[543] | 63 | my $pb = shift;
|
---|
[1192] | 64 |
|
---|
| 65 | my $dtype = $pb->{'pbos'}->{'type'};
|
---|
[543] | 66 | my $pbrealpkg = $pb->{'realpkg'};
|
---|
| 67 | my $pbver = $pb->{'ver'};
|
---|
| 68 | my $pbtag = $pb->{'tag'};
|
---|
[1432] | 69 | my $pbextdir = $pb->{'extdir'};
|
---|
[1192] | 70 | my $pbsuf = $pb->{'pbos'}->{'suffix'};
|
---|
[405] | 71 | my $OUTPUT = shift;
|
---|
| 72 | my $doit = shift;
|
---|
[1907] | 73 | my $chglog = $pb->{'chglog'};
|
---|
[405] | 74 |
|
---|
| 75 | my $log = "";
|
---|
| 76 |
|
---|
[1192] | 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);
|
---|
[405] | 80 | # For date handling
|
---|
| 81 | $ENV{LANG}="C";
|
---|
| 82 |
|
---|
| 83 | if ((not (defined $dtype)) || ($dtype eq "") ||
|
---|
[543] | 84 | (not (defined $pbrealpkg)) || ($pbrealpkg eq "") ||
|
---|
[405] | 85 | (not (defined $pbver)) || ($pbver eq "") ||
|
---|
| 86 | (not (defined $pbtag)) || ($pbtag eq "") ||
|
---|
[585] | 87 | (not (defined $pbsuf)) || ($pbsuf eq "") ||
|
---|
[405] | 88 | (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
|
---|
| 89 | (not (defined $doit)) || ($doit eq "")) {
|
---|
[1192] | 90 | pb_log(2,"Not enough input params\n");
|
---|
[405] | 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 |
|
---|
[544] | 106 | my @date = pb_get_date();
|
---|
[405] | 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")) {
|
---|
[1192] | 109 | pb_log(2,"No ChangeLog file for $pbrealpkg - faking one\n");
|
---|
[405] | 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");
|
---|
[1432] | 113 | # usefule mostly for test versions
|
---|
| 114 | $pbver .= $pbextdir;
|
---|
[1192] | 115 | if ($dtype eq "rpm") {
|
---|
[642] | 116 | $ver2 = "$pbver-$pbtag";
|
---|
[405] | 117 | print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
|
---|
| 118 | print $OUTPUT "- Updated to $pbver\n";
|
---|
[1192] | 119 | } elsif ($dtype eq "deb") {
|
---|
[544] | 120 | if ($pbver !~ /^[0-9]/) {
|
---|
[916] | 121 | # dpkg-deb doesn't accept non digit versions.
|
---|
| 122 | # Prepending 0 in order to make updates easy hopefully
|
---|
| 123 | $pbver =~ s/^/0/;
|
---|
[544] | 124 | }
|
---|
[916] | 125 | print $OUTPUT "$pbrealpkg ($pbver-$pbtag) unstable; urgency=low\n";
|
---|
| 126 | print $OUTPUT " * Updated to $pbver\n";
|
---|
[405] | 127 | print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}} $n2date\n\n\n";
|
---|
[1192] | 128 | } else {
|
---|
| 129 | pb_log(0,"No ChangeLog file for $pbrealpkg and no way faking one for type $dtype\n");
|
---|
| 130 | }
|
---|
[405] | 131 | return;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[1262] | 134 | die "No changelog file for $pbrealpkg found at $ENV{'PBROOTDIR'}/$pbrealpkg/pbcl" if (not defined $chglog);
|
---|
[1261] | 135 |
|
---|
[405] | 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") {
|
---|
[473] | 143 | chomp($tmp);
|
---|
| 144 | print $OUTPUT "$tmp<br>\n";
|
---|
[405] | 145 | }
|
---|
| 146 | $tmp = <INPUT>;
|
---|
| 147 | if ($dtype eq "announce") {
|
---|
[473] | 148 | chomp($tmp);
|
---|
| 149 | print $OUTPUT "$tmp<br>\n";
|
---|
[405] | 150 | }
|
---|
| 151 |
|
---|
| 152 | my $first=1;
|
---|
| 153 |
|
---|
| 154 | # Handle each block separated by newline
|
---|
| 155 | while (<INPUT>) {
|
---|
| 156 | ($ver, $date) = split(/ /);
|
---|
[1432] | 157 | # In case there is a v before the real version string
|
---|
[405] | 158 | $ver =~ s/^v//;
|
---|
| 159 | chomp($date);
|
---|
| 160 | $date =~ s/\(([0-9-]+)\)/$1/;
|
---|
[916] | 161 | pb_log(3,"**Date:$date**\n");
|
---|
[405] | 162 | $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
|
---|
| 163 | $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
|
---|
[916] | 164 | pb_log(3,"**nDate:$ndate**\n");
|
---|
[405] | 165 |
|
---|
[916] | 166 | pb_log(3,"**Ver:$ver**\n");
|
---|
| 167 | if ($ver !~ /-/) {
|
---|
| 168 | if ($first eq 1) {
|
---|
[1432] | 169 | $ver2 = "$ver$pbextdir-$pbtag";
|
---|
[916] | 170 | $first = 0;
|
---|
[405] | 171 | } else {
|
---|
[916] | 172 | $ver2 = "$ver-1";
|
---|
[405] | 173 | }
|
---|
[916] | 174 | } else {
|
---|
| 175 | $ver2 = $ver;
|
---|
| 176 | }
|
---|
| 177 | pb_log(3,"**Ver2:$ver2**\n");
|
---|
| 178 |
|
---|
| 179 | if (($dtype eq "rpm") || ($dtype eq "fc")) {
|
---|
[405] | 180 | print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
|
---|
| 181 | print $OUTPUT "- Updated to $ver\n";
|
---|
| 182 | }
|
---|
| 183 | if ($dtype eq "deb") {
|
---|
[916] | 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/;
|
---|
[544] | 188 | }
|
---|
[916] | 189 | print $OUTPUT "$pbrealpkg ($ver2) unstable; urgency=low\n";
|
---|
[405] | 190 | print $OUTPUT "\n";
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | $tmp = <INPUT>;
|
---|
[1791] | 194 | while ((defined $tmp) && ($tmp !~ /^$/)) {
|
---|
[405] | 195 | if ($dtype eq "deb") {
|
---|
| 196 | $tmp =~ s/^- //;
|
---|
[1764] | 197 | $Text::Wrap::columns = 80;
|
---|
| 198 | print $OUTPUT " * ".wrap('',' ',$tmp);
|
---|
[405] | 199 | } elsif ($dtype eq "rpm") {
|
---|
| 200 | print $OUTPUT "$tmp";
|
---|
| 201 | } else {
|
---|
[473] | 202 | chomp($tmp);
|
---|
| 203 | print $OUTPUT "$tmp<br>\n";
|
---|
[405] | 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);
|
---|
[1192] | 219 | pb_log(2,"Exiting pb_changelog\n");
|
---|
[405] | 220 | }
|
---|
| 221 |
|
---|
[409] | 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 |
|
---|
[405] | 244 | 1;
|
---|