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

Last change on this file since 1432 was 1432, checked in by bruno, 7 years ago

r4556@localhost: bruno | 2012-03-08 22:31:12 +0100

  • Adds a new extdir member to the pb structure, in order to manage the timestamp tag added in version name for test versions and have a complete correspondance between the tar file content, and the names. Should fix #99. This modification creates an incompatibility in the build part of pb, so requires that the build environment be updated before it's usable (with setupve|vm or sbx2setupve|vm)
  • This patch has been tested with .rpm and .deb test packages successfully. ebuild and solaris are to be tested.
  • Use the new extdir member to update existing projects filter
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
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 ProjectBuilder::Version;
20use ProjectBuilder::Base;
21use ProjectBuilder::Conf;
22
23# Inherit from the "Exporter" module which handles exporting functions.
24 
25use vars qw($VERSION $REVISION @ISA @EXPORT);
26use Exporter;
27 
28# Export, by default, all the functions into the namespace of
29# any code which uses this module.
30 
31our @ISA = qw(Exporter);
32our @EXPORT = qw(pb_changelog);
33($VERSION,$REVISION) = pb_version_init();
34
35=pod
36
37=head1 NAME
38
39ProjectBuilder::Changelog, part of the project-builder.org - module dealing with changelog management
40
41=head1 DESCRIPTION
42
43This modules provides generic functions suitable for changelog management for project-builder.org
44
45=head1 USAGE
46
47=over 4
48
49=item B<pb_changelog>
50
51Function that generates the changelog used in build files, or for announcements (web, mailing-list, ...)
52
53It takes 3 parameters:
54The first parameter is the %pb hash containing packge info
55The second parameter is the file descriptor on which to write the changelog content.
56The third parameter is a flag in the configuration file indicating whether we want changelog expansion or not.
57
58=cut
59
60sub pb_changelog {
61
62my $pb = shift;
63
64my $dtype = $pb->{'pbos'}->{'type'};
65my $pbrealpkg = $pb->{'realpkg'};
66my $pbver = $pb->{'ver'};
67my $pbtag = $pb->{'tag'};
68my $pbextdir = $pb->{'extdir'};
69my $pbsuf = $pb->{'pbos'}->{'suffix'};
70my $OUTPUT = shift;
71my $doit = shift;
72my $chglog = $pb->{'chglog'} || undef;
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    # usefule mostly for test versions
113    $pbver .= $pbextdir;
114    if ($dtype eq "rpm") {
115        $ver2 = "$pbver-$pbtag";
116        print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
117        print $OUTPUT "- Updated to $pbver\n";
118    } elsif ($dtype eq "deb") {
119        if ($pbver !~ /^[0-9]/) {
120            # dpkg-deb doesn't accept non digit versions.
121            # Prepending 0 in order to make updates easy hopefully
122            $pbver =~ s/^/0/;
123        }
124        print $OUTPUT "$pbrealpkg ($pbver-$pbtag) unstable; urgency=low\n";
125        print $OUTPUT "  * Updated to $pbver\n";
126        print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}}  $n2date\n\n\n";
127    } else {
128        pb_log(0,"No ChangeLog file for $pbrealpkg and no way faking one for type $dtype\n");
129    }
130    return;
131}
132
133die "No changelog file for $pbrealpkg found at $ENV{'PBROOTDIR'}/$pbrealpkg/pbcl" if (not defined $chglog);
134
135open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
136
137# Skip first 4 lines
138my $tmp = <INPUT>;
139$tmp = <INPUT>;
140$tmp = <INPUT>;
141if ($dtype eq "announce") {
142    chomp($tmp);
143    print $OUTPUT "$tmp<br>\n";
144}
145$tmp = <INPUT>;
146if ($dtype eq "announce") {
147    chomp($tmp);
148    print $OUTPUT "$tmp<br>\n";
149}
150
151my $first=1;
152
153# Handle each block separated by newline
154while (<INPUT>) {
155    ($ver, $date) = split(/ /);
156    # In case there is a v before the real version string
157    $ver =~ s/^v//;
158    chomp($date);
159    $date =~ s/\(([0-9-]+)\)/$1/;
160    pb_log(3,"**Date:$date**\n");
161    $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
162    $n2date = UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
163    pb_log(3,"**nDate:$ndate**\n");
164
165    pb_log(3,"**Ver:$ver**\n");
166    if ($ver !~ /-/) {
167        if ($first eq 1) {
168            $ver2 = "$ver$pbextdir-$pbtag";
169            $first = 0;
170        } else {
171            $ver2 = "$ver-1";
172        }
173    } else {
174        $ver2 = $ver;
175    }
176    pb_log(3,"**Ver2:$ver2**\n");
177
178    if (($dtype eq "rpm") || ($dtype eq "fc")) {
179        print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
180        print $OUTPUT "- Updated to $ver\n";
181        }
182    if ($dtype eq "deb") {
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/;
187        }
188        print $OUTPUT "$pbrealpkg ($ver2) unstable; urgency=low\n";
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 {
200            chomp($tmp);
201            print $OUTPUT "$tmp<br>\n";
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}
216close(INPUT);
217pb_log(2,"Exiting pb_changelog\n");
218}
219
220
221=back
222
223=head1 WEB SITES
224
225The 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
229None exists for the moment.
230
231=head1 AUTHORS
232
233The 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
237Project-Builder.org is distributed under the GPL v2.0 license
238described in the file C<COPYING> included with the distribution.
239
240=cut
241
2421;
Note: See TracBrowser for help on using the repository browser.