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

Last change on this file since 615 was 615, checked in by Bruno Cornec, 15 years ago

typo

File size: 22.7 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
10# Provided under the GPL v2
11
12package ProjectBuilder::CMS;
13
14use strict 'vars';
15use Data::Dumper;
16use English;
17use File::Basename;
18use File::Copy;
19use POSIX qw(strftime);
20use lib qw (lib);
21use ProjectBuilder::Base;
22use ProjectBuilder::Conf;
23
24# Inherit from the "Exporter" module which handles exporting functions.
25
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_cms_init pb_cms_export pb_cms_get_uri pb_cms_copy pb_cms_checkout pb_cms_up pb_cms_checkin pb_cms_isdiff pb_cms_get_pkg pb_cms_get_real_pkg pb_cms_compliant pb_cms_log pb_cms_add);
33
34=pod
35
36=head1 NAME
37
38ProjectBuilder::CMS, part of the project-builder.org
39
40=head1 DESCRIPTION
41
42This modules provides configuration management system functions suitable for pbinit calls.
43
44=head1 USAGE
45
46=over 4
47
48=item B<pb_cms_init>
49
50This function setup the environment for the CMS system related to the URL given by the pburl configuration parameter.
51The potential parameter indicates whether we should inititate the context or not.
52It sets up environement variables (PBPROJDIR, PBDIR, PBREVISION, PBCMSLOGFILE)
53
54=cut
55
56sub pb_cms_init {
57
58my $pbinit = shift || undef;
59
60my ($pburl) = pb_conf_get("pburl");
61pb_log(2,"DEBUG: Project URL of $ENV{'PBPROJ'}: $pburl->{$ENV{'PBPROJ'}}\n");
62my ($scheme, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
63
64my ($pbprojdir) = pb_conf_get_if("pbprojdir");
65
66if ((defined $pbprojdir) && (defined $pbprojdir->{$ENV{'PBPROJ'}})) {
67 $ENV{'PBPROJDIR'} = $pbprojdir->{$ENV{'PBPROJ'}};
68} else {
69 $ENV{'PBPROJDIR'} = "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}";
70}
71
72# Computing the default dir for PBDIR.
73# what we have is PBPROJDIR so work from that.
74# Tree identical between PBCONFDIR and PBROOTDIR on one side and
75# PBPROJDIR and PBDIR on the other side.
76
77my $tmp = $ENV{'PBROOTDIR'};
78$tmp =~ s|^$ENV{'PBCONFDIR'}||;
79
80#
81# Check project cms compliance
82#
83pb_cms_compliant(undef,'PBDIR',"$ENV{'PBPROJDIR'}/$tmp",$pburl->{$ENV{'PBPROJ'}},$pbinit);
84
85if ($scheme =~ /^hg/) {
86 # svnversion more precise than svn info
87 $tmp = `(cd "$ENV{'PBDIR'}" ; hg identify )`;
88 chomp($tmp);
89 $tmp =~ s/^.* //;
90 $ENV{'PBREVISION'}=$tmp;
91 $ENV{'PBCMSLOGFILE'}="hg.log";
92} elsif (($scheme eq "file") || ($scheme eq "ftp") || ($scheme eq "http")) {
93 $ENV{'PBREVISION'}="flat";
94 $ENV{'PBCMSLOGFILE'}="flat.log";
95} elsif ($scheme =~ /^svn/) {
96 $tmp = `(cd "$ENV{'PBDIR'}" ; svnversion .)`;
97 chomp($tmp);
98 $ENV{'PBREVISION'}=$tmp;
99 $ENV{'PBCMSLOGFILE'}="svn.log";
100} elsif ($scheme =~ /^cvs/) {
101 # Way too slow
102 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOTDIR'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
103 #chomp($ENV{'PBREVISION'});
104 $ENV{'PBREVISION'}="cvs";
105 $ENV{'PBCMSLOGFILE'}="cvs.log";
106 $ENV{'CVS_RSH'} = "ssh" if ($scheme =~ /ssh/);
107} else {
108 die "cms $scheme unknown";
109}
110
111return($scheme,$pburl->{$ENV{'PBPROJ'}});
112}
113
114=item B<pb_cms_export>
115
116This function exports a CMS content to a directory.
117The first parameter is the URL of the CMS content.
118The second parameter is the directory in which it is locally exposed (result of a checkout). If undef, then use the original CMS content.
119The third parameter is the directory where we want to deliver it (result of export).
120It returns the original tar file if we need to preserve it and undef if we use the produced one.
121
122=cut
123
124sub pb_cms_export {
125
126my $uri = shift;
127my $source = shift;
128my $destdir = shift;
129my $tmp;
130my $tmp1;
131
132my @date = pb_get_date();
133# If it's not flat, then we have a real uri as source
134my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
135
136if ($scheme =~ /^svn/) {
137 if (defined $source) {
138 if (-d $source) {
139 $tmp = $destdir;
140 } else {
141 $tmp = "$destdir/".basename($source);
142 }
143 $source = pb_cms_mod_svn_http($source);
144 pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp ");
145 } else {
146 $uri = pb_cms_mod_svn_http($uri);
147 pb_system("svn export $uri $destdir","Exporting $uri from SVN to $destdir ");
148 }
149} elsif ($scheme eq "dir") {
150 pb_system("cp -a $path $destdir","Copying $uri from DIR to $destdir ");
151} elsif (($scheme eq "http") || ($scheme eq "ftp")) {
152 my $f = basename($path);
153 unlink "$ENV{'PBTMP'}/$f";
154 if (-x "/usr/bin/wget") {
155 pb_system("/usr/bin/wget -nv -O $ENV{'PBTMP'}/$f $uri"," ");
156 } elsif (-x "/usr/bin/curl") {
157 pb_system("/usr/bin/curl $uri -o $ENV{'PBTMP'}/$f","Downloading $uri with curl to $ENV{'PBTMP'}/$f\n");
158 } else {
159 die "Unable to download $uri.\nNo wget/curl available, please install one of those";
160 }
161 # We want to preserve the original tar file
162 pb_cms_export("file://$ENV{'PBTMP'}/$f",$source,$destdir);
163 return("$ENV{'PBTMP'}/$f");
164} elsif ($scheme eq "file") {
165 use File::MimeInfo;
166 my $mm = mimetype($path);
167 pb_log(2,"mimetype: $mm\n");
168
169 if (defined $source) {
170 # Check whether the file is well formed
171 # (containing already a directory with the project-version name)
172 #
173 # If it's not the case, we try to adapt, but distro needing
174 # to verify the checksum will have issues (Fedora)
175 # Then upstream should be notified that they need to change their rules
176 my ($pbwf) = pb_conf_get_if("pbwf");
177 if ((defined $pbwf) && (defined $pbwf->{$ENV{'PBPROJ'}})) {
178 $destdir = dirname($destdir);
179 }
180 }
181 pb_mkdir_p($destdir);
182
183 if ($mm =~ /\/x-bzip-compressed-tar$/) {
184 # tar+bzip2
185 pb_system("cd $destdir ; tar xfj $path","Extracting $path in $destdir ");
186 } elsif ($mm =~ /\/x-lzma-compressed-tar$/) {
187 # tar+lzma
188 pb_system("cd $destdir ; tar xfY $path","Extracting $path in $destdir ");
189 } elsif ($mm =~ /\/x-compressed-tar$/) {
190 # tar+gzip
191 pb_system("cd $destdir ; tar xfz $path","Extracting $path in $destdir ");
192 } elsif ($mm =~ /\/x-tar$/) {
193 # tar
194 pb_system("cd $destdir ; tar xf $path","Extracting $path in $destdir ");
195 } elsif ($mm =~ /\/zip$/) {
196 # zip
197 pb_system("cd $destdir ; unzip $path","Extracting $path in $destdir ");
198 } else {
199 # simple file: copy it (patch e.g.)
200 copy($path,$destdir);
201 }
202} elsif ($scheme =~ /^hg/) {
203 if (defined $source) {
204 if (-d $source) {
205 $tmp = $destdir;
206 } else {
207 $tmp = "$destdir/".basename($source);
208 }
209 $source = pb_cms_mod_hg_http($source);
210 pb_system("hg export $source $tmp","Exporting $source from Mercurial to $tmp ");
211 } else {
212 $uri = pb_cms_mod_hg_http($uri);
213 pb_system("hg export $uri $destdir","Exporting $uri from Mercurial to $destdir ");
214 }
215} elsif ($scheme =~ /^cvs/) {
216 # CVS needs a relative path !
217 my $dir=dirname($destdir);
218 my $base=basename($destdir);
219 if (defined $source) {
220 # CVS also needs a modules name not a dir
221 $tmp1 = basename($source);
222 } else {
223 # Probably not right, should be checked, but that way I'll notice it :-)
224 $tmp1 = $uri;
225 }
226 # If we're working on the CVS itself
227 my $cvstag = basename($ENV{'PBROOTDIR'});
228 my $cvsopt = "";
229 if ($cvstag eq "cvs") {
230 my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
231 $cvsopt = "-D \"$pbdate\"";
232 } else {
233 # we're working on a tag which should be the last part of PBROOTDIR
234 $cvsopt = "-r $cvstag";
235 }
236 pb_system("cd $dir ; cvs -d $account\@$host:$path export $cvsopt -d $base $tmp1","Exporting $tmp1 from $source under CVS to $destdir ");
237} else {
238 die "cms $scheme unknown";
239}
240return(undef);
241}
242
243=item B<pb_cms_get_uri>
244
245This function is only called with a real CMS system and gives the URL stored in the checked out directory.
246The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
247The second parameter is the directory in which it is locally exposed (result of a checkout).
248
249=cut
250
251sub pb_cms_get_uri {
252
253my $scheme = shift;
254my $dir = shift;
255
256my $res = "";
257my $void = "";
258
259if ($scheme =~ /^svn/) {
260 open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
261 while (<PIPE>) {
262 ($void,$res) = split(/^URL:/) if (/^URL:/);
263 }
264 $res =~ s/^\s*//;
265 close(PIPE);
266 chomp($res);
267} elsif ($scheme =~ /^hg/) {
268 open(HGRC,".hg/hgrc/") || return("");
269 while (<HGRC>) {
270 ($void,$res) = split(/^default.*=/) if (/^default.*=/);
271 }
272 close(HGRC);
273 chomp($res);
274} elsif ($scheme =~ /^cvs/) {
275 # This path is always the root path of CVS, but we may be below
276 open(FILE,"$dir/CVS/Root") || die "$dir isn't CVS controlled";
277 $res = <FILE>;
278 chomp($res);
279 close(FILE);
280 # Find where we are in the tree
281 my $rdir = $dir;
282 while ((! -d "$rdir/CVSROOT") && ($rdir ne "/")) {
283 $rdir = dirname($rdir);
284 }
285 die "Unable to find a CVSROOT dir in the parents of $dir" if (! -d "$rdir/CVSROOT");
286 #compute our place under that root dir - should be a relative path
287 $dir =~ s|^$rdir||;
288 my $suffix = "";
289 $suffix = "$dir" if ($dir ne "");
290
291 my $prefix = "";
292 if ($scheme =~ /ssh/) {
293 $prefix = "cvs+ssh://";
294 } else {
295 $prefix = "cvs://";
296 }
297 $res = $prefix.$res.$suffix;
298} else {
299 die "cms $scheme unknown";
300}
301pb_log(2,"Found CMS info: $res\n");
302return($res);
303}
304
305=item B<pb_cms_copy>
306
307This function copies a CMS content to another.
308The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
309The second parameter is the URL of the original CMS content.
310The third parameter is the URL of the destination CMS content.
311
312Only coded for SVN now as used for pbconf itself not the project
313
314=cut
315
316sub pb_cms_copy {
317my $scheme = shift;
318my $oldurl = shift;
319my $newurl = shift;
320
321if ($scheme =~ /^svn/) {
322 $oldurl = pb_cms_mod_svn_http($oldurl);
323 $newurl = pb_cms_mod_svn_http($newurl);
324 pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
325} elsif ($scheme eq "flat") {
326} elsif ($scheme =~ /^cvs/) {
327} else {
328 die "cms $scheme unknown";
329}
330}
331
332=item B<pb_cms_checkout>
333
334This function checks a CMS content out to a directory.
335The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
336The second parameter is the URL of the CMS content.
337The third parameter is the directory where we want to deliver it (result of export).
338
339=cut
340
341sub pb_cms_checkout {
342my $scheme = shift;
343my $url = shift;
344my $destination = shift;
345
346if ($scheme =~ /^svn/) {
347 $url = pb_cms_mod_svn_http($url);
348 pb_system("svn co $url $destination","Checking out $url to $destination ");
349} elsif ($scheme =~ /^hg/) {
350 $url = pb_cms_mod_hg_http($url);
351 pb_system("hg clone $url $destination","Checking out $url to $destination ");
352} elsif (($scheme eq "ftp") || ($scheme eq "http")) {
353 return;
354} elsif ($scheme =~ /^cvs/) {
355 my ($scheme, $account, $host, $port, $path) = pb_get_uri($url);
356
357 # If we're working on the CVS itself
358 my $cvstag = basename($ENV{'PBROOTDIR'});
359 my $cvsopt = "";
360 if ($cvstag eq "cvs") {
361 my @date = pb_get_date();
362 my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
363 $cvsopt = "-D \"$pbdate\"";
364 } else {
365 # we're working on a tag which should be the last part of PBROOTDIR
366 $cvsopt = "-r $cvstag";
367 }
368 pb_mkdir_p("$destination");
369 pb_system("cd $destination ; cvs -d $account\@$host:$path co $cvsopt .","Checking out $url to $destination ");
370} elsif ($scheme =~ /^file/) {
371 pb_cms_export($url,undef,$destination);
372} else {
373 die "cms $scheme unknown";
374}
375}
376
377=item B<pb_cms_up>
378
379This function updates a local directory with the CMS content.
380The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
381The second parameter is the directory to update.
382
383=cut
384
385sub pb_cms_up {
386my $scheme = shift;
387my $dir = shift;
388
389if ($scheme =~ /^svn/) {
390 pb_system("svn up $dir","Updating $dir ");
391} elsif ($scheme eq "flat") {
392} elsif ($scheme =~ /^hg/) {
393 pb_system("cd $dir ; hg up","Updating $dir ");
394} elsif ($scheme =~ /^cvs/) {
395 pb_system("cvs up $dir","Updating $dir ");
396} else {
397 die "cms $scheme unknown";
398}
399}
400
401=item B<pb_cms_checkin>
402
403This function updates a CMS content from a local directory.
404The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
405The second parameter is the directory to update from.
406The third parameter indicates if we are in a new version creation (undef) or in a new project creation (1)
407
408=cut
409
410sub pb_cms_checkin {
411my $scheme = shift;
412my $dir = shift;
413my $pbinit = shift || undef;
414
415my $ver = basename($dir);
416my $msg = "updated to $ver";
417$msg = "Project $ENV{PBPROJ} creation" if (defined $pbinit);
418
419if ($scheme =~ /^svn/) {
420 pb_system("svn ci -m \"$msg\" $dir","Checking in $dir ");
421} elsif ($scheme eq "flat") {
422} elsif ($scheme =~ /^hg/) {
423 pb_system("hg ci -m \"$msg\" $dir","Checking in $dir ");
424} elsif ($scheme =~ /^cvs/) {
425 pb_system("cvs ci -m \"$msg\" $dir","Checking in $dir ");
426} else {
427 die "cms $scheme unknown";
428}
429pb_cms_up($scheme,$dir);
430}
431
432=item B<pb_cms_add>
433
434This function adds to a CMS content from a local directory.
435The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
436The second parameter is the directory/file to add.
437
438=cut
439
440sub pb_cms_add {
441my $scheme = shift;
442my $f = shift;
443
444if ($scheme =~ /^svn/) {
445 pb_system("svn add $f","Adding $f to SVN ");
446} elsif ($scheme eq "flat") {
447} elsif ($scheme =~ /^hg/) {
448 pb_system("hg add $f","Adding $f to Mercurial ");
449} elsif ($scheme =~ /^cvs/) {
450 pb_system("cvs add $f","Adding $f to CVS ");
451} else {
452 die "cms $scheme unknown";
453}
454pb_cms_up($scheme,$f);
455}
456
457=item B<pb_cms_isdiff>
458
459This function returns a integer indicating the number f differences between the CMS content and the local directory where it's checked out.
460The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
461The second parameter is the directory to consider.
462
463=cut
464
465sub pb_cms_isdiff {
466my $scheme = shift;
467my $dir =shift;
468
469if ($scheme =~ /^svn/) {
470 open(PIPE,"svn diff $dir |") || die "Unable to get svn diff from $dir";
471 my $l = 0;
472 while (<PIPE>) {
473 $l++;
474 }
475 return($l);
476} elsif ($scheme =~ /^hg/) {
477 open(PIPE,"hg diff $dir |") || die "Unable to get hg diff from $dir";
478 my $l = 0;
479 while (<PIPE>) {
480 $l++;
481 }
482 return($l);
483} elsif ($scheme eq "flat") {
484} elsif ($scheme =~ /^cvs/) {
485 open(PIPE,"cvs diff $dir |") || die "Unable to get svn diff from $dir";
486 my $l = 0;
487 while (<PIPE>) {
488 # Skipping normal messages
489 next if (/^cvs diff:/);
490 $l++;
491 }
492 return($l);
493} else {
494 die "cms $scheme unknown";
495}
496}
497
498=item B<pb_cms_get_pkg>
499
500This function returns the list of packages we are working on in a CMS action.
501The first parameter is the default list of packages from the configuration file.
502The second parameter is the optional list of packages from the configuration file.
503
504=cut
505
506sub pb_cms_get_pkg {
507
508my @pkgs = ();
509my $defpkgdir = shift || undef;
510my $extpkgdir = shift || undef;
511
512# Get packages list
513if (not defined $ARGV[0]) {
514 @pkgs = keys %$defpkgdir if (defined $defpkgdir);
515} elsif ($ARGV[0] =~ /^all$/) {
516 @pkgs = keys %$defpkgdir if (defined $defpkgdir);
517 push(@pkgs, keys %$extpkgdir) if (defined $extpkgdir);
518} else {
519 @pkgs = @ARGV;
520}
521pb_log(0,"Packages: ".join(',',@pkgs)."\n");
522return(\@pkgs);
523}
524
525=item B<pb_cms_get_real_pkg>
526
527This function returns the real name of a virtual package we are working on in a CMS action.
528It supports the following types: perl.
529The first parameter is the virtual package name
530
531=cut
532
533sub pb_cms_get_real_pkg {
534
535my $pbpkg = shift || undef;
536my $dtype = shift;
537my $pbpkgreal = $pbpkg;
538
539my @nametype = pb_conf_get_if("namingtype");
540my $type = $nametype[0]->{$pbpkg};
541if (defined $type) {
542 if ($type eq "perl") {
543 if ($dtype eq "rpm") {
544 $pbpkgreal = "perl-".$pbpkg;
545 } elsif ($dtype eq "deb") {
546 # Only lower case allowed in Debian
547 # Cf: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Package
548 $pbpkgreal = "lib".lc($pbpkg)."-perl";
549 } elsif ($dtype eq "ebuild") {
550 $pbpkgreal = $pbpkg;
551 } else {
552 die "pb_cms_get_real_pkg not implemented for $dtype yet";
553 }
554 } else {
555 die "nametype $type not implemented yet";
556 }
557}
558
559pb_log(2,"Real Package: $pbpkgreal\n");
560return($pbpkgreal);
561}
562
563=item B<pb_cms_compliant>
564
565This function checks the compliance of the project and the pbconf directory.
566The first parameter is the key name of the value that needs to be read in the configuration file.
567The second parameter is the environment variable this key will populate.
568The third parameter is the location of the pbconf dir.
569The fourth parameter is the URI of the CMS content related to the pbconf dir.
570The fifth parameter indicates whether we should inititate the context or not.
571
572=cut
573
574sub pb_cms_compliant {
575
576my $param = shift;
577my $envar = shift;
578my $defdir = shift;
579my $uri = shift;
580my $pbinit = shift;
581my %pdir;
582
583my ($pdir) = pb_conf_get_if($param) if (defined $param);
584if (defined $pdir) {
585 %pdir = %$pdir;
586}
587
588
589if ((defined $pdir) && (%pdir) && (defined $pdir{$ENV{'PBPROJ'}})) {
590 # That's always the environment variable that will be used
591 $ENV{$envar} = $pdir{$ENV{'PBPROJ'}};
592} else {
593 if (defined $param) {
594 pb_log(1,"WARNING: no $param defined, using $defdir\n");
595 pb_log(1," Please create a $param reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
596 pb_log(1," if you want to use another directory\n");
597 }
598 $ENV{$envar} = "$defdir";
599}
600
601# Expand potential env variable in it
602eval { $ENV{$envar} =~ s/(\$ENV.+\})/$1/eeg };
603pb_log(2,"$envar: $ENV{$envar}\n");
604
605my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
606
607if ((! -d "$ENV{$envar}") || (defined $pbinit)) {
608 if (defined $pbinit) {
609 pb_mkdir_p("$ENV{$envar}");
610 } else {
611 pb_log(1,"Checking out $uri\n");
612 pb_cms_checkout($scheme,$uri,$ENV{$envar});
613 }
614} elsif (($scheme !~ /^cvs/) || ($scheme !~ /^svn/) || ($scheme !~ /^hg/)) {
615 # Do not compare if it's not a real cms
616 return;
617} else {
618 pb_log(1,"$uri found locally, checking content\n");
619 my $cmsurl = pb_cms_get_uri($scheme,$ENV{$envar});
620 my ($scheme2, $account2, $host2, $port2, $path2) = pb_get_uri($cmsurl);
621 if ($cmsurl ne $uri) {
622 # The local content doesn't correpond to the repository
623 pb_log(0,"ERROR: Inconsistency detected:\n");
624 pb_log(0," * $ENV{$envar} refers to $cmsurl but\n");
625 pb_log(0," * $ENV{'PBETC'} refers to $uri\n");
626 die "Project $ENV{'PBPROJ'} is not Project-Builder compliant.";
627 } else {
628 pb_log(1,"Content correct - doing nothing - you may want to update your repository however\n");
629 # they match - do nothing - there may be local changes
630 }
631}
632}
633
634=item B<pb_cms_create_authors>
635
636This function creates a AUTHORS files for the project. It call it AUTHORS.pb if an AUTHORS file already exists.
637The first parameter is the source file for authors information.
638The second parameter is the directory where to create the final AUTHORS file.
639The third parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
640
641=cut
642
643sub pb_cms_create_authors {
644
645my $authors=shift;
646my $dest=shift;
647my $scheme=shift;
648
649return if ($authors eq "/dev/null");
650open(SAUTH,$authors) || die "Unable to open $authors";
651# Save a potentially existing AUTHORS file and write instead to AUTHORS.pb
652my $ext = "";
653if (-f "$dest/AUTHORS") {
654 $ext = ".pb";
655}
656open(DAUTH,"> $dest/AUTHORS$ext") || die "Unable to create $dest/AUTHORS$ext";
657print DAUTH "Authors of the project are:\n";
658print DAUTH "===========================\n";
659while (<SAUTH>) {
660 my ($nick,$gcos) = split(/:/);
661 chomp($gcos);
662 print DAUTH "$gcos";
663 if (defined $scheme) {
664 # Do not give a scheme for flat types
665 my $endstr="";
666 if ("$ENV{'PBREVISION'}" ne "flat") {
667 $endstr = " under $scheme";
668 }
669 print DAUTH " ($nick$endstr)\n";
670 } else {
671 print DAUTH "\n";
672 }
673}
674close(DAUTH);
675close(SAUTH);
676}
677
678=item B<pb_cms_log>
679
680This function creates a ChangeLog file for the project.
681The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
682The second parameter is the directory where the CMS content was checked out.
683The third parameter is the directory where to create the final ChangeLog file.
684The fourth parameter is unused.
685The fifth parameter is the source file for authors information.
686
687It may use a tool like svn2cl or cvs2cl to generate it if present, or the log file from the CMS if not.
688
689=cut
690
691
692sub pb_cms_log {
693
694my $scheme = shift;
695my $pkgdir = shift;
696my $dest = shift;
697my $chglog = shift;
698my $authors = shift;
699my $testver = shift || undef;
700
701pb_cms_create_authors($authors,$dest,$scheme);
702
703if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
704 if (! -f "$dest/ChangeLog") {
705 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
706 # We need a minimal version for debian type of build
707 print CL "\n";
708 print CL "\n";
709 print CL "\n";
710 print CL "\n";
711 print CL "1990-01-01 none\n";
712 print CL "\n";
713 print CL " * test version\n";
714 print CL "\n";
715 close(CL);
716 pb_log(0,"Generating fake ChangeLog for test version\n");
717 open(CL,"> $dest/$ENV{'PBCMSLOGFILE'}") || die "Unable to create $dest/$ENV{'PBCMSLOGFILE'}";
718 close(CL);
719 }
720}
721
722if ($scheme =~ /^svn/) {
723 if (! -f "$dest/ChangeLog") {
724 # In case we have no network, just create an empty one before to allow correct build
725 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
726 close(CL);
727 if (-x "/usr/bin/svn2cl") {
728 pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
729 } else {
730 # To be written from pbcl
731 pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
732 }
733 }
734} elsif ($scheme =~ /^hg/) {
735 if (! -f "$dest/ChangeLog") {
736 # In case we have no network, just create an empty one before to allow correct build
737 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
738 close(CL);
739 pb_system("hg log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
740 }
741} elsif (($scheme eq "file") || ($scheme eq "dir") || ($scheme eq "http") || ($scheme eq "ftp")) {
742 if (! -f "$dest/ChangeLog") {
743 pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
744 }
745} elsif ($scheme =~ /^cvs/) {
746 my $tmp=basename($pkgdir);
747 # CVS needs a relative path !
748 if (! -f "$dest/ChangeLog") {
749 # In case we have no network, just create an empty one before to allow correct build
750 open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
751 close(CL);
752 if (-x "/usr/bin/cvs2cl") {
753 pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
754 } else {
755 # To be written from pbcl
756 pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
757 }
758 }
759} else {
760 die "cms $scheme unknown";
761}
762}
763
764sub pb_cms_mod_svn_http {
765
766my $url = shift;
767
768$url =~ s/^svn\+(http[s]*):/$1:/;
769return($url);
770}
771
772sub pb_cms_mod_hg_http {
773
774my $url = shift;
775
776$url =~ s/^hg\+(http[s]*):/$1:/;
777return($url);
778}
779
780=back
781
782=head1 WEB SITES
783
784The 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/>.
785
786=head1 USER MAILING LIST
787
788None exists for the moment.
789
790=head1 AUTHORS
791
792The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
793
794=head1 COPYRIGHT
795
796Project-Builder.org is distributed under the GPL v2.0 license
797described in the file C<COPYING> included with the distribution.
798
799=cut
800
8011;
Note: See TracBrowser for help on using the repository browser.