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

Last change on this file was 2632, checked in by Bruno Cornec, 4 years ago

More aur support

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