source: ProjectBuilder/devel/pb/lib/ProjectBuilder/CMS.pm@ 2325

Last change on this file since 2325 was 2325, checked in by Bruno Cornec, 7 years ago

Remove a duplicate log in CMS for Packages:

File size: 8.0 KB
Line 
1#!/usr/bin/perl -w
2#
3# Project Builder CMS module
4# CMS subroutines brought by the the Project-Builder project
5# which can be easily used by pbinit scripts
6#
7# $Id$
8#
9# Copyright B. Cornec 2007-2016
10# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
11# Provided under the GPL v2
12
13package ProjectBuilder::CMS;
14
15use strict 'vars';
16use Carp 'confess';
17use Data::Dumper;
18use English;
19use File::Basename;
20use File::Copy;
21use POSIX qw(strftime);
22use lib qw (lib);
23use ProjectBuilder::Version;
24use ProjectBuilder::Base;
25use ProjectBuilder::Conf;
26use ProjectBuilder::VCS;
27
28# Inherit from the "Exporter" module which handles exporting functions.
29
30use vars qw($VERSION $REVISION @ISA @EXPORT);
31use Exporter;
32
33# Export, by default, all the functions into the namespace of
34# any code which uses this module.
35
36our @ISA = qw(Exporter);
37our @EXPORT = qw(pb_cms_get_pkg pb_cms_get_real_pkg pb_cms_log);
38($VERSION,$REVISION) = pb_version_init();
39
40=pod
41
42=head1 NAME
43
44ProjectBuilder::CMS, part of the project-builder.org
45
46=head1 DESCRIPTION
47
48This modules provides configuration management system functions suitable for pbinit calls.
49
50=head1 USAGE
51
52=over 4
53
54=item B<pb_cms_get_pkg>
55
56This function returns the list of packages we are working on in a CMS action.
57The first parameter is the default list of packages from the configuration file.
58The second parameter is the optional list of packages from the configuration file.
59
60=cut
61
62sub pb_cms_get_pkg {
63
64my @pkgs = ();
65my $defpkgdir = shift;
66my $extpkgdir = shift;
67
68# Get packages list
69if (not defined $ARGV[0]) {
70 @pkgs = keys %$defpkgdir if (defined $defpkgdir);
71} elsif ($ARGV[0] =~ /^all$/) {
72 @pkgs = keys %$defpkgdir if (defined $defpkgdir);
73 push(@pkgs, keys %$extpkgdir) if (defined $extpkgdir);
74} else {
75 @pkgs = @ARGV;
76}
77return(\@pkgs);
78}
79
80=item B<pb_cms_get_real_pkg>
81
82This function returns the real name of a virtual package we are working on in a CMS action.
83It supports the following types: perl.
84The first parameter is the virtual package name
85
86=cut
87
88sub pb_cms_get_real_pkg {
89
90my $pbpkg = shift;
91my $dtype = shift;
92my $pbpkgreal = $pbpkg;
93
94my @nametype = pb_conf_get_if("namingtype");
95my $type = $nametype[0]->{$pbpkg};
96if (defined $type) {
97 if ($type eq "perl") {
98 if ($dtype eq "rpm") {
99 $pbpkgreal = "perl-".$pbpkg;
100 } elsif ($dtype eq "deb") {
101 # Only lower case allowed in Debian
102 # Cf: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Package
103 $pbpkgreal = "lib".lc($pbpkg)."-perl";
104 } elsif ($dtype eq "ebuild") {
105 $pbpkgreal = $pbpkg;
106 } elsif ($dtype eq "hpux") {
107 $pbpkgreal = $pbpkg;
108 } elsif ($dtype eq "pkg") {
109 $pbpkgreal = "PB$pbpkg";
110 } else {
111 die "pb_cms_get_real_pkg not implemented for $dtype yet";
112 }
113 } else {
114 die "nametype $type not implemented yet";
115 }
116}
117
118pb_log(2,"pb_cms_get_real_pkg returns $pbpkgreal\n");
119return($pbpkgreal);
120}
121
122=item B<pb_cms_create_authors>
123
124This function creates a AUTHORS files for the project. It call it AUTHORS.pb if an AUTHORS file already exists.
125The first parameter is the source file for authors information.
126The second parameter is the directory where to create the final AUTHORS file.
127The third parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
128
129=cut
130
131sub pb_cms_create_authors {
132
133my $authors=shift;
134my $dest=shift;
135my $scheme=shift;
136
137return if ($authors eq "/dev/null");
138open(SAUTH,$authors) || die "Unable to open $authors";
139# Save a potentially existing AUTHORS file and write instead to AUTHORS.pb
140my $ext = "";
141if (-f "$dest/AUTHORS") {
142 $ext = ".pb";
143}
144open(DAUTH,"> $dest/AUTHORS$ext") || die "Unable to create $dest/AUTHORS$ext";
145print DAUTH "Authors of the project are:\n";
146print DAUTH "===========================\n";
147while (<SAUTH>) {
148 my ($nick,$gcos) = split(/:/);
149 chomp($gcos);
150 print DAUTH "$gcos";
151 if (defined $scheme) {
152 # Do not give a scheme for flat types
153 my $endstr="";
154 if ("$ENV{'PBREVISION'}" ne "flat") {
155 $endstr = " under $scheme";
156 }
157 print DAUTH " ($nick$endstr)\n";
158 } else {
159 print DAUTH "\n";
160 }
161}
162close(DAUTH);
163close(SAUTH);
164}
165
166=item B<pb_cms_log>
167
168This function creates a ChangeLog file for the project.
169The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
170The second parameter is the directory where the CMS content was checked out.
171The third parameter is the directory where to create the final ChangeLog file.
172The fourth parameter is unused.
173The fifth parameter is the source file for authors information.
174
175It may use a tool like svn2cl or cvs2cl to generate it if present, or the log file from the CMS if not.
176
177=cut
178
179
180sub pb_cms_log {
181
182my $scheme = shift;
183my $pkgdir = shift;
184my $dest = shift;
185my $chglog = shift;
186my $authors = shift;
187my $testver = shift;
188
189pb_cms_create_authors($authors,$dest,$scheme);
190my $vcscmd = pb_vcs_cmd($scheme);
191
192if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
193 if (! -f "$dest/ChangeLog") {
194 open(CL,"> $dest/ChangeLog") || confess "Unable to create $dest/ChangeLog";
195 # We need a minimal version for debian type of build
196 print CL "\n";
197 print CL "\n";
198 print CL "\n";
199 print CL "\n";
200 print CL "1990-01-01 none\n";
201 print CL "\n";
202 print CL " * test version\n";
203 print CL "\n";
204 close(CL);
205 pb_log(0,"Generating fake ChangeLog for test version\n");
206 open(CL,"> $dest/$ENV{'PBCMSLOGFILE'}") || die "Unable to create $dest/$ENV{'PBCMSLOGFILE'}";
207 close(CL);
208 }
209}
210
211if (! -f "$dest/ChangeLog") {
212 if ($scheme =~ /^svn/) {
213 # In case we have no network, just create an empty one before to allow correct build
214 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
215 close(CL);
216 my $command = pb_check_req("svn2cl",1);
217 if ((defined $command) && (-x $command)) {
218 pb_system("$command --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
219 } else {
220 # To be written from pbcl
221 pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
222 }
223 } elsif ($scheme =~ /^svk/) {
224 pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVK");
225 } elsif ($scheme =~ /^hg/) {
226 # In case we have no network, just create an empty one before to allow correct build
227 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
228 close(CL);
229 pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from Mercurial");
230 } elsif ($scheme =~ /^git/) {
231 # In case we have no network, just create an empty one before to allow correct build
232 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
233 close(CL);
234 pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from GIT");
235 } elsif ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)|(dir)\b/o) {
236 pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
237 } elsif ($scheme =~ /^cvs/) {
238 my $tmp=basename($pkgdir);
239 # CVS needs a relative path !
240 # In case we have no network, just create an empty one before to allow correct build
241 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
242 close(CL);
243 my $command = pb_check_req("cvs2cl",1);
244 if (-x $command) {
245 pb_system("$command --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
246 } else {
247 # To be written from pbcl
248 pb_system("$vcscmd log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
249 }
250 } else {
251 die "cms $scheme unknown";
252 }
253}
254if (! -f "$dest/ChangeLog") {
255 copy("$dest/$ENV{'PBCMSLOGFILE'}","$dest/ChangeLog");
256}
257}
258
259=back
260
261=head1 WEB SITES
262
263The 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/>.
264
265=head1 USER MAILING LIST
266
267None exists for the moment.
268
269=head1 AUTHORS
270
271The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
272
273=head1 COPYRIGHT
274
275Project-Builder.org is distributed under the GPL v2.0 license
276described in the file C<COPYING> included with the distribution.
277
278=cut
279
2801;
Note: See TracBrowser for help on using the repository browser.