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

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

pb_cms_init becomes pb_vcs_init to be used in env_init

File size: 8.1 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}
77pb_log(0,"Packages: ".join(',',@pkgs)."\n");
78return(\@pkgs);
79}
80
81=item B<pb_cms_get_real_pkg>
82
83This function returns the real name of a virtual package we are working on in a CMS action.
84It supports the following types: perl.
85The first parameter is the virtual package name
86
87=cut
88
89sub pb_cms_get_real_pkg {
90
91my $pbpkg = shift;
92my $dtype = shift;
93my $pbpkgreal = $pbpkg;
94
95my @nametype = pb_conf_get_if("namingtype");
96my $type = $nametype[0]->{$pbpkg};
97if (defined $type) {
98 if ($type eq "perl") {
99 if ($dtype eq "rpm") {
100 $pbpkgreal = "perl-".$pbpkg;
101 } elsif ($dtype eq "deb") {
102 # Only lower case allowed in Debian
103 # Cf: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Package
104 $pbpkgreal = "lib".lc($pbpkg)."-perl";
105 } elsif ($dtype eq "ebuild") {
106 $pbpkgreal = $pbpkg;
107 } elsif ($dtype eq "hpux") {
108 $pbpkgreal = $pbpkg;
109 } elsif ($dtype eq "pkg") {
110 $pbpkgreal = "PB$pbpkg";
111 } else {
112 die "pb_cms_get_real_pkg not implemented for $dtype yet";
113 }
114 } else {
115 die "nametype $type not implemented yet";
116 }
117}
118
119pb_log(2,"pb_cms_get_real_pkg returns $pbpkgreal\n");
120return($pbpkgreal);
121}
122
123=item B<pb_cms_create_authors>
124
125This function creates a AUTHORS files for the project. It call it AUTHORS.pb if an AUTHORS file already exists.
126The first parameter is the source file for authors information.
127The second parameter is the directory where to create the final AUTHORS file.
128The third parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
129
130=cut
131
132sub pb_cms_create_authors {
133
134my $authors=shift;
135my $dest=shift;
136my $scheme=shift;
137
138return if ($authors eq "/dev/null");
139open(SAUTH,$authors) || die "Unable to open $authors";
140# Save a potentially existing AUTHORS file and write instead to AUTHORS.pb
141my $ext = "";
142if (-f "$dest/AUTHORS") {
143 $ext = ".pb";
144}
145open(DAUTH,"> $dest/AUTHORS$ext") || die "Unable to create $dest/AUTHORS$ext";
146print DAUTH "Authors of the project are:\n";
147print DAUTH "===========================\n";
148while (<SAUTH>) {
149 my ($nick,$gcos) = split(/:/);
150 chomp($gcos);
151 print DAUTH "$gcos";
152 if (defined $scheme) {
153 # Do not give a scheme for flat types
154 my $endstr="";
155 if ("$ENV{'PBREVISION'}" ne "flat") {
156 $endstr = " under $scheme";
157 }
158 print DAUTH " ($nick$endstr)\n";
159 } else {
160 print DAUTH "\n";
161 }
162}
163close(DAUTH);
164close(SAUTH);
165}
166
167=item B<pb_cms_log>
168
169This function creates a ChangeLog file for the project.
170The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
171The second parameter is the directory where the CMS content was checked out.
172The third parameter is the directory where to create the final ChangeLog file.
173The fourth parameter is unused.
174The fifth parameter is the source file for authors information.
175
176It may use a tool like svn2cl or cvs2cl to generate it if present, or the log file from the CMS if not.
177
178=cut
179
180
181sub pb_cms_log {
182
183my $scheme = shift;
184my $pkgdir = shift;
185my $dest = shift;
186my $chglog = shift;
187my $authors = shift;
188my $testver = shift;
189
190pb_cms_create_authors($authors,$dest,$scheme);
191my $vcscmd = pb_vcs_cmd($scheme);
192
193if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
194 if (! -f "$dest/ChangeLog") {
195 open(CL,"> $dest/ChangeLog") || confess "Unable to create $dest/ChangeLog";
196 # We need a minimal version for debian type of build
197 print CL "\n";
198 print CL "\n";
199 print CL "\n";
200 print CL "\n";
201 print CL "1990-01-01 none\n";
202 print CL "\n";
203 print CL " * test version\n";
204 print CL "\n";
205 close(CL);
206 pb_log(0,"Generating fake ChangeLog for test version\n");
207 open(CL,"> $dest/$ENV{'PBCMSLOGFILE'}") || die "Unable to create $dest/$ENV{'PBCMSLOGFILE'}";
208 close(CL);
209 }
210}
211
212if (! -f "$dest/ChangeLog") {
213 if ($scheme =~ /^svn/) {
214 # In case we have no network, just create an empty one before to allow correct build
215 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
216 close(CL);
217 my $command = pb_check_req("svn2cl",1);
218 if ((defined $command) && (-x $command)) {
219 pb_system("$command --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
220 } else {
221 # To be written from pbcl
222 pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
223 }
224 } elsif ($scheme =~ /^svk/) {
225 pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVK");
226 } elsif ($scheme =~ /^hg/) {
227 # In case we have no network, just create an empty one before to allow correct build
228 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
229 close(CL);
230 pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from Mercurial");
231 } elsif ($scheme =~ /^git/) {
232 # In case we have no network, just create an empty one before to allow correct build
233 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
234 close(CL);
235 pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from GIT");
236 } elsif ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)|(dir)\b/o) {
237 pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
238 } elsif ($scheme =~ /^cvs/) {
239 my $tmp=basename($pkgdir);
240 # CVS needs a relative path !
241 # In case we have no network, just create an empty one before to allow correct build
242 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
243 close(CL);
244 my $command = pb_check_req("cvs2cl",1);
245 if (-x $command) {
246 pb_system("$command --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
247 } else {
248 # To be written from pbcl
249 pb_system("$vcscmd log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
250 }
251 } else {
252 die "cms $scheme unknown";
253 }
254}
255if (! -f "$dest/ChangeLog") {
256 copy("$dest/$ENV{'PBCMSLOGFILE'}","$dest/ChangeLog");
257}
258}
259
260=back
261
262=head1 WEB SITES
263
264The 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/>.
265
266=head1 USER MAILING LIST
267
268None exists for the moment.
269
270=head1 AUTHORS
271
272The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
273
274=head1 COPYRIGHT
275
276Project-Builder.org is distributed under the GPL v2.0 license
277described in the file C<COPYING> included with the distribution.
278
279=cut
280
2811;
Note: See TracBrowser for help on using the repository browser.