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