source: ProjectBuilder/devel/pb/lib/ProjectBuilder/Base.pm@ 319

Last change on this file since 319 was 319, checked in by Bruno Cornec, 16 years ago

pb_cms_export ready to host the real stuff for file.

File size: 41.5 KB
RevLine 
[2]1#!/usr/bin/perl -w
2#
[74]3# Base subroutines for the Project-Builder project
[2]4#
5# $Id$
6#
7
[318]8package ProjectBuilder::Base;
9
[18]10use strict;
[5]11use lib qw (lib);
[2]12use File::Basename;
[9]13use File::Path;
[315]14use File::Copy;
[318]15use File::Temp qw(tempdir);
[8]16use Data::Dumper;
[315]17use POSIX qw(strftime);
[318]18use Time::localtime qw(localtime);
[2]19
[199]20use ProjectBuilder::Changelog qw (pb_changelog);
21
[318]22# Inherit from the "Exporter" module which handles exporting functions.
23
24use Exporter;
25
26# Export, by default, all the functions into the namespace of
27# any code which uses this module.
28
29our $debug = 0;
30our $LOG = \*STDOUT;
31
32our @ISA = qw(Exporter);
33our @EXPORT = qw(pb_env_init pb_conf_read pb_conf_get pb_conf_get_if pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_filter_file_inplace pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout pb_get_date pb_log pb_log_init pb_get_pkg $debug $LOG);
34
[49]35$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
[5]36
[74]37sub pb_env_init {
[2]38
[273]39my $proj=shift || undef;
40my $pbinit=shift || undef;
[5]41my $ver;
42my $tag;
[2]43
[8]44#
[5]45# Check project name
[49]46# Could be with env var PBPROJ
47# or option -p
48# if not define take the first in conf file
[8]49#
[5]50if ((defined $ENV{'PBPROJ'}) &&
51 (not (defined $proj))) {
52 $proj = $ENV{'PBPROJ'};
53}
[69]54
[49]55#
[313]56# We get the pbconf file for that project
[69]57# and use its content
58#
[313]59my ($pbconf) = pb_conf_read("$ENV{'PBETC'}","pbconf");
[315]60pb_log(2,"DEBUG pbconf: ".Dumper($pbconf)."\n");
[69]61
[313]62my %pbconf = %$pbconf;
[69]63if (not defined $proj) {
64 # Take the first as the default project
[313]65 $proj = (keys %pbconf)[0];
[315]66 if (defined $proj) {
[316]67 pb_log(0,"WARNING: using $proj as default project as none has been specified\n");
[318]68 pb_log(0," Please either create a pbconf reference for project $proj in $ENV{'PBETC'}\n");
[319]69 pb_log(0," or call pb with the -p project option or use the env var PBPROJ\n");
70 pb_log(0," if you want to use another project\n");
[313]71 }
[69]72}
[313]73die "No project defined - use env var PBPROJ or -p proj or a pbconf entry in $ENV{'PBETC'}" if (not (defined $proj));
[69]74
[313]75# That's always the environment variable that will be used
76$ENV{'PBPROJ'} = $proj;
[318]77pb_log(2,"PBPROJ: $ENV{'PBPROJ'}\n");
[313]78
79if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
80 die "Please create a pbconf reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
81}
82
[69]83#
[313]84# Detect the root dir for hosting all the content generated with pb
[69]85#
[314]86# Tree will look like this:
87#
[315]88# maint pbdir PBDIR dev dir (optional) PBDEVDIR
89# | |
90# ------------------------ --------------------
91# | | | |
92# pbproj1 pbproj2 PBPROJ pbproj1 pbproj2 PBDEVPROJ
93# | |
94# --------------------------------------------- ----------
95# * * | | | | * *
[319]96# 1.0 dev pbconf ... build delivery PBCONF dev tag PBDEVROOT
97# | | PBDESTDIR |
98# ------ pbrc PBBUILDDIR -------
99# | | | |
100# dev tag PBROOT 1.0 1.1
[314]101# |
[319]102# -------
103# | |
104# 1.0 1.1
105# |
[314]106# ----------------------------------
107# | | | |
108# pkg1 pbproj1.pb pbfilter pbcl
109# |
110# -----------------
111# | | |
112# rpm deb pbfilter
113#
114#
115# (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdir (when appropriate)
116# Names under a pbproj and the corresponding pbconf should be similar
117#
[313]118
[314]119my ($pbdir) = pb_conf_get_if("pbdir");
120my %pbdir = %$pbdir;
121
122if (not defined $ENV{'PBDIR'}) {
[316]123 if ((not defined $pbdir) || (not defined $pbdir{$ENV{'PBPROJ'}})) {
124 pb_log(0,"WARNING: no pbdir defined, using /var/cache\n");
[318]125 pb_log(0," Please create a pbdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
126 pb_log(0," if you want to use another directory\n");
[316]127 $ENV{'PBDIR'} = "/var/cache";
128 } else {
129 # That's always the environment variable that will be used
130 $ENV{'PBDIR'} = $pbdir{$ENV{'PBPROJ'}};
[313]131 }
[273]132}
[108]133# Expand potential env variable in it
[314]134eval { $ENV{'PBDIR'} =~ s/(\$ENV.+\})/$1/eeg };
[69]135
[318]136pb_log(2,"PBDIR: $ENV{'PBDIR'}\n");
[69]137#
[313]138# Set delivery directory
[49]139#
[314]140$ENV{'PBDESTDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/delivery";
[313]141
[318]142pb_log(2,"PBDESTDIR: $ENV{'PBDESTDIR'}\n");
[313]143#
144# Removes all directory existing below the delivery dir
145# as they are temp dir only
146# Files stay and have to be cleaned up manually if needed
147# those files serves as communication channels between pb phases
148# Removing them prevents a following phase to detect what has been done before
149#
150if (-d $ENV{'PBDESTDIR'}) {
151 opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
152 foreach my $d (readdir(DIR)) {
153 next if ($d =~ /^\./);
154 next if (-f "$ENV{'PBDESTDIR'}/$d");
155 pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
[67]156 }
[313]157 closedir(DIR);
[49]158}
[313]159if (! -d "$ENV{'PBDESTDIR'}") {
160 pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
161}
[2]162
[8]163#
[313]164# Set build directory
[8]165#
[314]166$ENV{'PBBUILDDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/build";
[313]167if (! -d "$ENV{'PBBUILDDIR'}") {
168 pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
169}
170
[318]171pb_log(2,"PBBUILDDIR: $ENV{'PBBUILDDIR'}\n");
[313]172#
173# Set temp directory
174#
175if (not defined $ENV{'TMPDIR'}) {
176 $ENV{'TMPDIR'}="/tmp";
177}
178$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
[318]179pb_log(2,"PBTMP: $ENV{'PBTMP'}\n");
[313]180
181#
182# Check pbconf compliance
183#
[314]184$ENV{'PBCONF'} = "$ENV{'PBDIR'}/$ENV{'PBPROJ'}/pbconf";
[318]185pb_log(2,"PBCONF: $ENV{'PBCONF'}\n");
[313]186
[314]187my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbconf{$ENV{'PBPROJ'}});
[313]188
[318]189if ((! -d "$ENV{'PBCONF'}") || (defined $pbinit)) {
[316]190 pb_log(1,"Checking out pbconf\n");
[315]191 pb_cms_checkout($scheme,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
[314]192} else {
[316]193 pb_log(1,"pbconf found, checking content\n");
[315]194 my $cmsurl = pb_cms_getinfo($scheme,$ENV{'PBCONF'},"URL:");
[318]195 my ($scheme2, $account2, $host2, $port2, $path2) = pb_get_uri($cmsurl);
196 if ($scheme2 ne $scheme) {
197 pb_log(1,"WARNING: Content of $ENV{'PBCONF'} irrelevant, cleaning up and checking it out\n");
[314]198 pb_rm_rf("$ENV{'PBCONF'}");
[315]199 pb_cms_checkout($scheme,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
[314]200 } elsif ($cmsurl ne $pbconf{$ENV{'PBPROJ'}}) {
201 # The local content doesn't correpond to the repository
[316]202 pb_log(0,"ERROR: Inconsistency detected:\n");
[318]203 pb_log(0," * $ENV{'PBCONF'} refers to $cmsurl but\n");
204 pb_log(0," * $ENV{'PBETC'} refers to $pbconf{$ENV{'PBPROJ'}}\n");
[314]205 die "Project $ENV{'PBPROJ'} is not Project-Builder compliant.";
206 } else {
[316]207 pb_log(1,"Content correct - doing nothing - you may want to update your repository however\n");
[314]208 # they match - do nothing - there may be local changes
[273]209 }
[314]210}
[2]211
[314]212# Check where is our PBROOT (release tag name can't be guessed the first time)
213if (not defined $ENV{'PBROOT'}) {
214 if (! -f ("$ENV{'PBDESTDIR'}/pbrc")) {
215 opendir(DIR,$ENV{'PBCONF'}) || die "Unable to open directory $ENV{'PBCONF'}: $!";
[315]216 my $maxmtime = 0;
[314]217 foreach my $d (readdir(DIR)) {
218 next if ($d =~ /^\./);
219 next if (! -d $d);
220 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
221 = stat($d);
222 # Keep the most recent
[318]223 pb_log(2,"Looking at $d: $mtime\n");
[314]224 if ($mtime > $maxmtime) {
225 $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$d";
226 $maxmtime = $mtime;
227 }
228 }
229 closedir(DIR);
[316]230 die "No directory found under $ENV{'PBCONF'}" if (not defined $ENV{'PBROOT'});
231 pb_log(0,"WARNING: no pbroot defined, using $ENV{'PBROOT'}\n");
[318]232 pb_log(0," Please use -r release if you want to use another release\n");
[314]233 } else {
234 my ($pbroot) = pb_conf_read_if("$ENV{'PBDESTDIR'}/pbrc","pbroot");
235 # That's always the environment variable that will be used
[316]236 die "Please remove inconsistent $ENV{'PBDESTDIR'}/pbrc" if ((not defined $pbroot) || (not defined $pbroot->{$ENV{'PBPROJ'}}));
[315]237 $ENV{'PBROOT'} = $pbroot->{$ENV{'PBPROJ'}};
[314]238 }
239} else {
240 # transform in full path if relative
[316]241 $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$ENV{'PBROOT'}" if ($ENV{'PBROOT'} !~ /^\//);
242 die "$ENV{'PBROOT'} is not a directory" if (not -d $ENV{'PBROOT'});
[314]243}
244
[74]245my %version = ();
[108]246my %defpkgdir = ();
247my %extpkgdir = ();
248my %filteredfiles = ();
[300]249my %supfiles = ();
[74]250
[314]251if ((-f "$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") and (not defined $pbinit)) {
[74]252 # List of pkg to build by default (mandatory)
[313]253 my ($defpkgdir) = pb_conf_get("defpkgdir");
[74]254 # List of additional pkg to build when all is called (optional)
255 # Valid version names (optional)
256 # List of files to filter (optional)
[313]257 # Project version and tag (optional)
258 my ($extpkgdir, $version, $filteredfiles, $supfiles, $pkgv, $pkgt) = pb_conf_get_if("extpkgdir","version","filteredfiles","supfiles","projver","projtag");
[315]259 pb_log(2,"DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n");
260 pb_log(2,"DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n");
261 pb_log(2,"DEBUG: version: ".Dumper($version)."\n");
262 pb_log(2,"DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n");
263 pb_log(2,"DEBUG: supfiles: ".Dumper($supfiles)."\n");
[74]264 # Global
265 %defpkgdir = %$defpkgdir;
[114]266 %extpkgdir = %$extpkgdir if (defined $extpkgdir);
[74]267 %version = %$version if (defined $version);
268 %filteredfiles = %$filteredfiles if (defined $filteredfiles);
[300]269 %supfiles = %$supfiles if (defined $supfiles);
[106]270 #
271 # Get global Version/Tag
272 #
273 if (not defined $ENV{'PBVER'}) {
[313]274 if ((defined $pkgv) && (defined $pkgv->{$ENV{'PBPROJ'}})) {
275 $ENV{'PBVER'}=$pkgv->{$ENV{'PBPROJ'}};
[106]276 } else {
[314]277 die "No projver found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
[106]278 }
[98]279 }
[314]280 die "Invalid version name $ENV{'PBVER'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not defined $version) && ($ENV{'PBVER'} =~ /$version{$ENV{'PBPROJ'}}/));
[106]281
282 if (not defined $ENV{'PBTAG'}) {
[313]283 if ((defined $pkgt) && (defined $pkgt->{$ENV{'PBPROJ'}})) {
284 $ENV{'PBTAG'}=$pkgt->{$ENV{'PBPROJ'}};
[106]285 } else {
[314]286 die "No projtag found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
[106]287 }
[98]288 }
[314]289 die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
[106]290} else {
[273]291 if (defined $pbinit) {
[316]292 my $ptr = pb_get_pkg();
[317]293 my @pkgs = @$ptr;
[316]294 @pkgs = ("pkg1") if (not @pkgs);
295
[314]296 open(CONF,"> $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") || die "Unable to create $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
[273]297 print CONF << "EOF";
298#
299# Project Builder configuration file
[313]300# For project $ENV{'PBPROJ'}
[273]301#
302# \$Id\$
303#
304
305#
[316]306# What is the project URL
[273]307#
[316]308#pbproj $ENV{'PBPROJ'} = svn://svn.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
309#pbproj $ENV{'PBPROJ'} = svn://svn+ssh.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
310#pbproj $ENV{'PBPROJ'} = cvs://cvs.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
311#pbproj $ENV{'PBPROJ'} = http://www.$ENV{'PBPROJ'}.org/src/$ENV{'PBPROJ'}-devel.tar.gz
312#pbproj $ENV{'PBPROJ'} = ftp://ftp.$ENV{'PBPROJ'}.org/src/$ENV{'PBPROJ'}-devel.tar.gz
313#pbproj $ENV{'PBPROJ'} = file:///src/$ENV{'PBPROJ'}-devel.tar.gz
[319]314#pbproj $ENV{'PBPROJ'} = dir:///src/$ENV{'PBPROJ'}-devel
[273]315
316#
317# Packager label
318#
[313]319#packager $ENV{'PBPROJ'} = "William Porte <bill\@$ENV{'PBPROJ'}.org>"
[273]320#
321
322# For delivery to a machine by SSH (potentially the FTP server)
323# Needs hostname, account and directory
324#
[313]325#sshhost $ENV{'PBPROJ'} = www.$ENV{'PBPROJ'}.org
326#sshlogin $ENV{'PBPROJ'} = bill
327#sshdir $ENV{'PBPROJ'} = /$ENV{'PBPROJ'}/ftp
328#sshport $ENV{'PBPROJ'} = 22
[273]329
330#
331# For Virtual machines management
332# Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
333# followed by '_' and by release number
334# a .vmtype extension will be added to the resulting string
335# a QEMU rhel_3 here means that the VM will be named rhel_3.qemu
336#
[313]337#vmlist $ENV{'PBPROJ'} = mandrake_10.1,mandrake_10.2,mandriva_2006.0,mandriva_2007.0,mandriva_2007.1,mandriva_2008.0,redhat_7.3,redhat_9,fedora_4,fedora_5,fedora_6,fedora_7,rhel_3,rhel_4,rhel_5,suse_10.0,suse_10.1,suse_10.2,suse_10.3,sles_9,sles_10,gentoo_nover,debian_3.1,debian_4.0,ubuntu_6.06,ubuntu_7.04,ubuntu_7.10
[273]338
339#
340# Valid values for vmtype are
341# qemu, (vmware, xen, ... TBD)
[313]342#vmtype $ENV{'PBPROJ'} = qemu
[273]343
344# Hash for VM stuff on vmtype
345#vmntp default = pool.ntp.org
346
347# We suppose we can commmunicate with the VM through SSH
[313]348#vmhost $ENV{'PBPROJ'} = localhost
349#vmlogin $ENV{'PBPROJ'} = pb
350#vmport $ENV{'PBPROJ'} = 2222
[273]351
352# Timeout to wait when VM is launched/stopped
353#vmtmout default = 120
354
355# per VMs needed paramaters
[313]356#vmopt $ENV{'PBPROJ'} = -m 384 -daemonize
357#vmpath $ENV{'PBPROJ'} = /home/qemu
358#vmsize $ENV{'PBPROJ'} = 5G
[273]359
360#
361# Global version/tag for the project
362#
[313]363#projver $ENV{'PBPROJ'} = devel
364#projtag $ENV{'PBPROJ'} = 1
[273]365
[316]366# Hash of valid version names
367#version $ENV{'PBPROJ'} = devel,stable
368
[273]369# Adapt to your needs:
370# Optional if you need to overwrite the global values above
371#
[316]372EOF
373
374 foreach my $pp (@pkgs) {
375 print CONF << "EOF";
376#pkgver $pp = stable
377#pkgtag $pp = 3
378EOF
379 }
380 foreach my $pp (@pkgs) {
381 print CONF << "EOF";
[273]382# Hash of default package/package directory
[319]383#defpkgdir $pp = dir-$pp
[316]384EOF
385 }
[273]386
[316]387 print CONF << "EOF";
[273]388# Hash of additional package/package directory
[319]389#extpkgdir minor-pkg = dir-minor-pkg
[273]390
391# List of files per pkg on which to apply filters
392# Files are mentioned relatively to pbroot/defpkgdir
393EOF
[316]394 foreach my $pp (@pkgs) {
395 print CONF << "EOF";
396#filteredfiles $pp = Makefile.PL,configure.in,install.sh,$pp.8
397#supfiles $pp = $pp.init
398EOF
399 }
[273]400 close(CONF);
[314]401 pb_mkdir_p("$ENV{'PBROOT'}/pbfilter") || die "Unable to create $ENV{'PBROOT'}/pbfilter";
402 open(CONF,"> $ENV{'PBROOT'}/pbfilter/all.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/all.pbf";
[273]403 print CONF << "EOF";
404#
405# \$Id\$
406#
407# Filter for all files
408#
409# PBSRC is replaced by the source package format
[313]410#filter PBSRC = ftp://ftp.$ENV{'PBPROJ'}.org/src/%{name}-%{version}.tar.gz
[273]411
412# PBVER is replaced by the version (\$pbver in code)
413#filter PBVER = \$pbver
414
415# PBDATE is replaced by the date (\$pbdate in code)
416#filter PBDATE = \$pbdate
417
418# PBLOG is replaced by the changelog if value is yes
419#filter PBLOG = yes
420
421# PBTAG is replaced by the tag (\$pbtag in code)
422#filter PBTAG = \$pbtag
423
424# PBREV is replaced by the revision (\$pbrev in code)
425#filter PBREV = \$pbrev
426
427# PBPKG is replaced by the package name (\$pbpkg in code)
428#filter PBPKG = \$pbpkg
429
430# PBPACKAGER is replaced by the packager name (\$pbpackager in code)
431#filter PBPACKAGER = \$pbpackager
432
433# PBDESC contains the description of the package
434#filter PBDESC = "Bla-Bla"
435
436# PBURL contains the URL of the Web site of the project
[313]437#filter PBURL = http://www.$ENV{'PBPROJ'}.org
[273]438EOF
439 close(CONF);
[314]440 open(CONF,"> $ENV{'PBROOT'}/pbfilter/rpm.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/rpm.pbf";
[273]441 print CONF << "EOF";
442#
443# \$Id\$
444#
445# Filter for rpm build
446#
447
448# PBGRP is replaced by the RPM group of apps
[288]449# Cf: http://fedoraproject.org/wiki/RPMGroups
[273]450#filter PBGRP = Applications/Archiving
451
[316]452# PBLIC is replaced by the license of the application
453# Cf: http://fedoraproject.org/wiki/Licensing
454#filter PBLIC = GPL
455
[273]456# PBDEP is replaced by the list of dependencies
457#filter PBDEP =
458
459# PBSUF is replaced by the package name (\$pbpkg in code)
460#filter PBSUF = \$pbsuf
461
462# PBOBS is replaced by the Obsolete line
463#filter PBOBS =
464
465EOF
466 close(CONF);
[314]467 open(CONF,"> $ENV{'PBROOT'}/pbfilter/deb.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/deb.pbf";
[273]468 print CONF << "EOF";
469#
470# \$Id\$
471#
472# Filter for debian build
473#
474# PBGRP is replaced by the group of apps
475#filter PBGRP = utils
476
[316]477# PBLIC is replaced by the license of the application
478# Cf:
479#filter PBLIC = GPL
480
[273]481# PBVER is replaced by the version (\$pbver in code)
482#filter PBVER = \$pbver
483
484# PBDEP is replaced by the list of dependencies
485#filter PBDEP =
486
487# PBSUG is replaced by the list of suggestions
488#filter PBSUG =
489
490# PBREC is replaced by the list of recommandations
491#filter PBREC =
492
493# PBLOG is replaced by the changelog if value is yes
494#filter PBLOG = yes
495
496# PBPKG is replaced by the package name (\$pbpkg in code)
497#filter PBPKG = \$pbpkg
498
499# PBPACKAGER is replaced by the packager name (\$pbpackager in code)
500#filter PBPACKAGER = \$pbpackager
501
502EOF
503 close(CONF);
[314]504 open(CONF,"> $ENV{'PBROOT'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/md.pbf";
[273]505 print CONF << "EOF";
[313]506# Specific group for Mandriva for $ENV{'PBPROJ'}
[316]507# Cf: http://wiki.mandriva.com/en/Development/Packaging/Groups
[273]508filter PBGRP = Archiving/Backup
[316]509
510# PBLIC is replaced by the license of the application
511# Cf: http://wiki.mandriva.com/en/Development/Packaging/Licenses
512#filter PBLIC = GPL
513
[273]514EOF
515 close(CONF);
[314]516 open(CONF,"> $ENV{'PBROOT'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/novell.pbf";
[273]517 print CONF << "EOF";
[313]518# Specific group for SuSE for $ENV{'PBPROJ'}
[316]519# Cf: http://en.opensuse.org/SUSE_Package_Conventions/RPM_Groups
[273]520filter PBGRP = Productivity/Archiving/Backup
[316]521
522# PBLIC is replaced by the license of the application
523# Cf: http://en.opensuse.org/Packaging/SUSE_Package_Conventions/RPM_Style#1.6._License_Tag
524#filter PBLIC = GPL
525
[273]526EOF
527 close(CONF);
[316]528 foreach my $pp (@pkgs) {
529 pb_mkdir_p("$ENV{'PBROOT'}/$pp/deb") || die "Unable to create $ENV{'PBROOT'}/$pp/deb";
530 open(CONF,"> $ENV{'PBROOT'}/$pp/deb/control") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/control";
531 print CONF << "EOF";
[273]532Source: PBPKG
533Section: PBGRP
534Priority: optional
535Maintainer: PBPACKAGER
536Build-Depends: debhelper (>= 4.2.20), PBDEP
537Standards-Version: 3.6.1
538
539Package: PBPKG
540Architecture: amd64 i386 ia64
541Section: PBGRP
542Priority: optional
543Depends: \${shlibs:Depends}, \${misc:Depends}, PBDEP
544Recommends: PBREC
545Suggests: PBSUG
546Description:
547 PBDESC
548 .
549 Homepage: PBURL
550
551EOF
[316]552 close(CONF);
553 open(CONF,"> $ENV{'PBROOT'}/$pp/deb/copyright") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/copyright";
554 print CONF << "EOF";
[273]555This package is debianized by PBPACKAGER
556`date`
557
558The current upstream source was downloaded from
[313]559ftp://ftp.$ENV{'PBPROJ'}.org/src/.
[273]560
561Upstream Authors: Put their name here
562
563Copyright:
564
565 This package is free software; you can redistribute it and/or modify
566 it under the terms of the GNU General Public License as published by
567 the Free Software Foundation; version 2 dated June, 1991.
568
569 This package is distributed in the hope that it will be useful,
570 but WITHOUT ANY WARRANTY; without even the implied warranty of
571 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
572 GNU General Public License for more details.
573
574 You should have received a copy of the GNU General Public License
575 along with this package; if not, write to the Free Software
576 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
577 MA 02110-1301, USA.
578
579On Debian systems, the complete text of the GNU General
580Public License can be found in /usr/share/common-licenses/GPL.
581
582EOF
[316]583 close(CONF);
584 open(CONF,"> $ENV{'PBROOT'}/$pp/deb/changelog") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/changelog";
585 print CONF << "EOF";
[273]586PBLOG
587EOF
[316]588 close(CONF);
589 open(CONF,"> $ENV{'PBROOT'}/$pp/deb/compat") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/compat";
590 print CONF << "EOF";
[273]5914
592EOF
[316]593 close(CONF);
594 open(CONF,"> $ENV{'PBROOT'}/$pp/deb/pkg1.dirs") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/$pp.dirs";
595 print CONF << "EOF";
[273]596EOF
[316]597 close(CONF);
598 open(CONF,"> $ENV{'PBROOT'}/$pp/deb/$pp.docs") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/$pp.docs";
599 print CONF << "EOF";
[273]600INSTALL
601COPYING
602AUTHORS
603NEWS
604README
605EOF
[316]606 close(CONF);
607 open(CONF,"> $ENV{'PBROOT'}/$pp/deb/rules") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/rules";
608 print CONF << 'EOF';
[273]609#!/usr/bin/make -f
610# -*- makefile -*-
611# Sample debian/rules that uses debhelper.
612# GNU copyright 1997 to 1999 by Joey Hess.
613#
614# $Id$
615#
616
617# Uncomment this to turn on verbose mode.
618#export DH_VERBOSE=1
619
620# Define package name variable for a one-stop change.
621PACKAGE_NAME = PBPKG
622
623# These are used for cross-compiling and for saving the configure script
624# from having to guess our platform (since we know it already)
625DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
626DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
627
628CFLAGS = -Wall -g
629
630ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
631 CFLAGS += -O0
632else
633 CFLAGS += -O2
634endif
635ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
636 INSTALL_PROGRAM += -s
637endif
638config.status: configure
639 dh_testdir
640
641 # Configure the package.
642 CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr
643 --mandir=\$${prefix}/share/man
644
645# Build both architecture dependent and independent
646build: build-arch build-indep
647
648# Build architecture dependent
649build-arch: build-arch-stamp
650
651build-arch-stamp: config.status
652 dh_testdir
653
654 # Compile the package.
655 $(MAKE)
656
657 touch build-stamp
658
659# Build architecture independent
660build-indep: build-indep-stamp
661
662build-indep-stamp: config.status
663 # Nothing to do, the only indep item is the manual which is available as html in original source
664 touch build-indep-stamp
665
666# Clean up
667clean:
668 dh_testdir
669 dh_testroot
670 rm -f build-arch-stamp build-indep-stamp #CONFIGURE-STAMP#
671 # Clean temporary document directory
672 rm -rf debian/doc-temp
673 # Clean up.
674 -$(MAKE) distclean
675 rm -f config.log
676ifneq "$(wildcard /usr/share/misc/config.sub)" ""
677 cp -f /usr/share/misc/config.sub config.sub
678endif
679ifneq "$(wildcard /usr/share/misc/config.guess)" ""
680 cp -f /usr/share/misc/config.guess config.guess
681endif
682
683 dh_clean
684
685# Install architecture dependent and independent
686install: install-arch install-indep
687
688# Install architecture dependent
689install-arch: build-arch
690 dh_testdir
691 dh_testroot
692 dh_clean -k -s
693 dh_installdirs -s
694
695 # Install the package files into build directory:
696 # - start with upstream make install
697 $(MAKE) install prefix=$(CURDIR)/debian/$(PACKAGE_NAME)/usr mandir=$(CURDIR)/debian/$(PACKAGE_NAME)/us
698r/share/man
699 # - copy html manual to temporary location for renaming
700 mkdir -p debian/doc-temp
701 dh_install -s
702
703# Install architecture independent
704install-indep: build-indep
705 dh_testdir
706 dh_testroot
707 dh_clean -k -i
708 dh_installdirs -i
709 dh_install -i
710
711# Must not depend on anything. This is to be called by
712# binary-arch/binary-indep
713# in another 'make' thread.
714binary-common:
715 dh_testdir
716 dh_testroot
717 dh_installchangelogs ChangeLog
718 dh_installdocs
719 dh_installman
720 dh_link
721 dh_strip
722 dh_compress
723 dh_fixperms
724 dh_installdeb
725 dh_shlibdeps
726 dh_gencontrol
727 dh_md5sums
728 dh_builddeb
729
730# Build architecture independant packages using the common target.
731binary-indep: build-indep install-indep
732 $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
733
734# Build architecture dependant packages using the common target.
735binary-arch: build-arch install-arch
736 $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
737
738# Build architecture depdendent and independent packages
739binary: binary-arch binary-indep
740.PHONY: clean binary
741
742EOF
[316]743 close(CONF);
744 pb_mkdir_p("$ENV{'PBROOT'}/$pp/rpm") || die "Unable to create $ENV{'PBROOT'}/$pp/rpm";
745 open(CONF,"> $ENV{'PBROOT'}/$pp/rpm/$pp.spec") || die "Unable to create $ENV{'PBROOT'}/$pp/rpm/$pp.spec";
746 print CONF << 'EOF';
[273]747#
748# $Id$
749#
750
751Summary: bla-bla
752Summary(fr): french bla-bla
753
754Name: PBPKG
755Version: PBVER
756Release: PBTAGPBSUF
[316]757License: PBLIC
[273]758Group: PBGRP
759Url: PBURL
760Source: PBSRC
761BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
762Requires: PBDEP
763
764%description
765PBDESC
766
767%description -l fr
768french desc
769
770%prep
771%setup -q
772
773%build
774%configure
[288]775make %{?_smp_mflags}
[273]776
777%install
778%{__rm} -rf $RPM_BUILD_ROOT
779make DESTDIR=$RPM_BUILD_ROOT install
780
781%clean
782%{__rm} -rf $RPM_BUILD_ROOT
783
784%files
785%defattr(-,root,root)
786%doc ChangeLog
787%doc INSTALL COPYING README AUTHORS NEWS
788
789%changelog
790PBLOG
791
792EOF
[316]793 close(CONF);
794 pb_mkdir_p("$ENV{'PBROOT'}/$pp/pbfilter") || die "Unable to create $ENV{'PBROOT'}/$pp/pbfilter";
[273]795
[316]796 pb_log(0,"\nDo not to forget to commit the pbconf directory in your CMS if needed\n");
797 }
[273]798 } else {
[314]799 die "Unable to open $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
[273]800 }
[98]801}
[8]802umask 0022;
[315]803return(\%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
[2]804}
[9]805
[74]806# Internal mkdir -p function
807sub pb_mkdir_p {
[29]808my @dir = @_;
809my $ret = mkpath(@dir, 0, 0755);
810return($ret);
[9]811}
812
[74]813# Internal rm -rf function
814sub pb_rm_rf {
[29]815my @dir = @_;
816my $ret = rmtree(@dir, 0, 0);
817return($ret);
[9]818}
819
[74]820# Internal system function
821sub pb_system {
[29]822
823my $cmd=shift;
[30]824my $cmt=shift || $cmd;
[29]825
[319]826pb_log(0,"$cmt... ");
[117]827#system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
[293]828system($cmd);
[29]829if ($? == -1) {
[319]830 pb_log(0,"failed to execute ($cmd) : $!\n");
[106]831 pb_display_file("$ENV{'PBTMP'}/system.log");
[29]832} elsif ($? & 127) {
[319]833 pb_log(0, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n");
[106]834 pb_display_file("$ENV{'PBTMP'}/system.log");
835} elsif ($? == 0) {
[319]836 pb_log(0,"OK\n");
[29]837} else {
[319]838 pb_log(0, "child ($cmd) exited with value ".($? >> 8)."\n");
[106]839 pb_display_file("$ENV{'PBTMP'}/system.log");
[29]840}
[30]841}
[74]842
[106]843sub pb_display_file {
844
845my $file=shift;
846
[117]847return if (not -f $file);
848open(FILE,"$file");
[106]849while (<FILE>) {
[108]850 print $_;
[106]851}
852close(FILE);
853}
854
[242]855# Function which returns a pointer on a table
856# corresponding to a set of values queried in the conf file
[88]857# and test the returned vaue as they need to exist in that case
858sub pb_conf_get {
859
860my @param = @_;
[313]861my @return = pb_conf_get_if(@param);
[88]862
[315]863die "No params found for $ENV{'PBPROJ'}" if (not @return);
[313]864
865foreach my $i (0..$#param) {
866 die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $return[$i]);
867}
868return(@return);
869}
870
871# Function which returns a pointer on a table
872# corresponding to a set of values queried in the conf file
873# Those value may be undef if they do not exist
874sub pb_conf_get_if {
875
876my @param = @_;
877
[242]878# Everything is returned via ptr1
[318]879my @ptr1 = ();
880my @ptr2 = ();
881@ptr1 = pb_conf_read_if("$ENV{'PBETC'}", @param) if (defined $ENV{'PBETC'});
882@ptr2 = pb_conf_read_if("$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb", @param) if ((defined $ENV{'PBROOT'}) and (defined $ENV{'PBPROJ'}));
[89]883
[242]884my $p1;
885my $p2;
886
[315]887pb_log(2,"DEBUG: param1: ".Dumper(@ptr1)."\n");
888pb_log(2,"DEBUG: param2: ".Dumper(@ptr2)."\n");
[262]889
[88]890foreach my $i (0..$#param) {
[262]891 $p1 = $ptr1[$i];
892 $p2 = $ptr2[$i];
[242]893 # Always try to take the param from the home dir conf file in priority
894 # in order to mask what could be defined under the CMS to allow for overloading
895 if (not defined $p2) {
896 # No ref in CMS project conf file so use the home dir one.
897 $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if (not defined $p1->{$ENV{'PBPROJ'}});
898 } else {
899 # Ref found in CMS project conf file
900 if (not defined $p1) {
901 # No ref in home dir project conf file so use the CMS one.
902 $p2->{$ENV{'PBPROJ'}} = $p2->{'default'} if (not defined $p2->{$ENV{'PBPROJ'}});
903 $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
904 } else {
905 # Both are defined - handling the overloading
906 if (not defined $p1->{'default'}) {
907 if (defined $p2->{'default'}) {
908 $p1->{'default'} = $p2->{'default'};
909 }
910 }
911
912 if (not defined $p1->{$ENV{'PBPROJ'}}) {
913 if (defined $p2->{$ENV{'PBPROJ'}}) {
914 $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
915 } else {
916 $p1->{$ENV{'PBPROJ'}} = $p1->{'default'};
917 }
918 }
919 }
920 }
[262]921 $ptr1[$i] = $p1;
[315]922 pb_log(2,"DEBUG: param ptr1: ".Dumper(@ptr1)."\n");
[88]923}
[242]924return(@ptr1);
[88]925}
926
927# Function which returns a pointer on a hash
[74]928# corresponding to a declaration (arg2) in a conf file (arg1)
[313]929# if that conf file doesn't exist returns undef
930sub pb_conf_read_if {
931
932my $conffile = shift;
933my @param = @_;
934
935open(CONF,$conffile) || return((undef));
936close(CONF);
937return(pb_conf_read($conffile,@param));
938}
939
940# Function which returns a pointer on a hash
941# corresponding to a declaration (arg2) in a conf file (arg1)
[74]942sub pb_conf_read {
943
944my $conffile = shift;
945my @param = @_;
946my $trace;
947my @ptr;
[291]948my %h;
[74]949
[291]950open(CONF,$conffile) || die "Unable to open $conffile";
951while(<CONF>) {
952 if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
[315]953 pb_log(2,"DEBUG: 1:$1 2:$2 3:$3\n");
[291]954 $h{$1}{$2}=$3;
955 }
[74]956}
[291]957close(CONF);
[74]958
959for my $param (@param) {
[291]960 push @ptr,$h{$param};
[74]961}
[315]962pb_log(2,"DEBUG: h:".Dumper(%h)." param:".Dumper(@param)." ptr:".Dumper(@ptr)."\n");
[89]963return(@ptr);
[74]964}
965
[313]966# Analyze a url passed and return protocol, account, password, server, port, path
[314]967sub pb_get_uri {
[313]968
[314]969my $uri = shift || undef;
[313]970
[318]971pb_log(2,"DEBUG: uri:$uri\n");
[314]972# A URL has the format protocol://[ac@]host[:port][path[?query][#fragment]].
973# Cf man URI
974my ($scheme, $authority, $path, $query, $fragment) =
[318]975 $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?| if (defined $uri);
976my ($account,$host,$port) = $authority =~ m|(?:([^\@]+)\@)?([^:]+)(:(?:[0-9]+))?| if (defined $authority);
977
978$scheme = "" if (not defined $scheme);
979$authority = "" if (not defined $authority);
980$path = "" if (not defined $path);
981$account = "" if (not defined $account);
982$host = "" if (not defined $host);
983$port = "" if (not defined $port);
984
[315]985pb_log(2,"DEBUG: scheme:$scheme ac:$account host:$host port:$port path:$path\n");
[314]986return($scheme, $account, $host, $port, $path);
[313]987}
988
989
990# Setup environment for CMS system for URL passed
[74]991sub pb_cms_init {
992
993my $proj = shift || undef;
994
[315]995# Use the project URI
996my ($uri) = pb_conf_get("pburl");
[74]997
[315]998# Extract values from that URI
999my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri->{$ENV{'PBPROJ'}});
1000
1001if ($scheme =~ /^svn/) {
1002 $ENV{'PBREVISION'}= pb_cms_getinfo($scheme,$uri->{$ENV{'PBPROJ'}},"Revision:");
1003 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBDEVDIR'}" ; svnversion .)`;
[74]1004 $ENV{'PBCMSLOGFILE'}="svn.log";
[315]1005} elsif (($scheme eq "file") || ($scheme eq "ftp") || ($scheme eq "http")) {
[226]1006 $ENV{'PBREVISION'}="flat";
[227]1007 $ENV{'PBCMSLOGFILE'}="flat.log";
[315]1008} elsif ($scheme eq "cvs") {
[106]1009 # Way too slow
1010 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
1011 #chomp($ENV{'PBREVISION'});
1012 $ENV{'PBREVISION'}="CVS";
[74]1013 $ENV{'PBCMSLOGFILE'}="cvs.log";
[87]1014 #
1015 # Export content if needed
1016 #
[313]1017 my ($cvsrsh) = pb_conf_get_if("cvsrsh");
[299]1018 $ENV{'CVS_RSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
[74]1019} else {
[315]1020 die "cms $scheme unknown";
[74]1021}
[315]1022
1023#
1024#if (not defined $scheme) {
1025 # We're an upstream guy
1026 # Try to make it easy for us
1027 #pb_log(2,"WARNING: Assuming a local project under $ENV{'PBDIR'}/$ENV{'PBPROJ'}:\n");
[318]1028 #pb_log(2," If not, pleaase setup a pbproj entry in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb\n");
[315]1029 #return("");
1030#}
1031
1032return($scheme,$uri->{$ENV{'PBPROJ'}});
[74]1033}
1034
[315]1035sub pb_get_date {
1036
1037return(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
1038}
1039
[106]1040sub pb_cms_export {
[315]1041
[319]1042my $uri = shift;
[108]1043my $source = shift;
[106]1044my $destdir = shift;
[108]1045my $tmp;
[115]1046my $tmp1;
[106]1047
[315]1048my @date = pb_get_date();
[319]1049# If it's not flat, then we have a real uri as source
1050my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
[315]1051
1052if ($scheme eq "svn") {
[108]1053 if (-d $source) {
1054 $tmp = $destdir;
1055 } else {
1056 $tmp = $destdir."/".basename($source);
1057 }
[116]1058 pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
[319]1059} elsif ($scheme eq "dir") {
[226]1060 if (-d $source) {
1061 $tmp = $destdir;
1062 } else {
1063 $tmp = $destdir."/".basename($source);
1064 }
1065 pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
[319]1066} elsif (($scheme eq "http") || ($scheme eq "ftp")) {
1067 my $f = basename($path);
1068 unlink "$ENV{'PBTMP'}/$f";
1069 if (-x "/usr/bin/wget") {
1070 pb_system("/usr/bin/wget -nv -O $ENV{'PBTMP'}/$f $uri","Downloading $uri with wget to $ENV{'PBTMP'}/$f\n");
1071 } elsif (-x "/usr/bin/curl") {
1072 pb_system("/usr/bin/curl $uri -o $ENV{'PBTMP'}/$f","Downloading $uri with curl to $ENV{'PBTMP'}/$f\n");
1073 } else {
1074 die "Unable to download $uri.\nNo wget/curl available, please install one of those";
1075 }
1076 pb_cms_export("file://$ENV{'PBTMP'}/$f",$source,$destdir);
1077} elsif ($scheme eq "file") {
1078 use File::MimeInfo;
1079 my $mm = mimetype($path);
1080 pb_log(2,"mimetype: $mm\n");
1081
1082 if ($mm =~ /\/x-bzip-compressed-tar$/) {
1083 # tar+bzip2
1084 } elsif ($mm =~ /\/x-lzma-compressed-tar$/) {
1085 # tar+lzma
1086 } elsif ($mm =~ /\/x-compressed-tar$/) {
1087 # tar+gzip
1088 } elsif ($mm =~ /\/x-tar$/) {
1089 # tar
1090 } elsif ($mm =~ /\/zip$/) {
1091 # zip
1092 }
1093 pb_log(0,"scheme file not implemented yet\n");
[315]1094} elsif ($scheme eq "cvs") {
[106]1095 my $dir=dirname($destdir);
1096 my $base=basename($destdir);
[115]1097 if (-d $source) {
1098 $tmp1 = $source;
1099 $tmp1 =~ s|$ENV{'PBROOT'}/||;
1100 } else {
1101 $tmp1 = dirname($source);
1102 $tmp1 =~ s|$ENV{'PBROOT'}/||;
1103 $tmp1 = $tmp1."/".basename($source);
1104 }
[106]1105 # CVS needs a relative path !
[310]1106 my ($cvsroot) = pb_conf_get("cvsroot");
[315]1107 my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
[310]1108 pb_system("cd $dir ; cvs -d $cvsroot->{$ENV{'PBPROJ'}} export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
[106]1109} else {
[315]1110 die "cms $scheme unknown";
[106]1111}
1112}
1113
[285]1114
1115sub pb_create_authors {
1116
1117my $authors=shift;
1118my $dest=shift;
[315]1119my $scheme=shift;
[285]1120
[286]1121return if ($authors eq "/dev/null");
1122open(SAUTH,$authors) || die "Unable to open $authors";
[285]1123open(DAUTH,"> $dest/AUTHORS") || die "Unable to create $dest/AUTHORS";
1124print DAUTH "Authors of the project are:\n";
1125print DAUTH "===========================\n";
[286]1126while (<SAUTH>) {
[285]1127 my ($nick,$gcos) = split(/:/);
[286]1128 chomp($gcos);
[285]1129 print DAUTH "$gcos";
[315]1130 if (defined $scheme) {
1131 print DAUTH " ($nick under $scheme)\n";
[286]1132 } else {
1133 print DAUTH "\n";
1134 }
[285]1135}
1136close(DAUTH);
[286]1137close(SAUTH);
[285]1138}
1139
[106]1140sub pb_cms_log {
[315]1141my $scheme = shift;
[106]1142my $pkgdir = shift;
[285]1143my $dest = shift;
[286]1144my $chglog = shift;
[285]1145my $authors = shift;
[106]1146
[315]1147pb_create_authors($authors,$dest,$scheme);
[285]1148
[315]1149if ($scheme eq "svn") {
[286]1150 if (! -f "$dest/ChangeLog") {
1151 if (-x "/usr/bin/svn2cl") {
[315]1152 pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
[286]1153 } else {
1154 # To be written from pbcl
1155 pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
1156 }
[285]1157 }
[315]1158} elsif ($scheme eq "flat") {
[288]1159 if (! -f "$dest/ChangeLog") {
1160 pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
1161 }
[315]1162} elsif ($scheme eq "cvs") {
[106]1163 my $tmp=basename($pkgdir);
1164 # CVS needs a relative path !
[286]1165 if (! -f "$dest/ChangeLog") {
1166 if (-x "/usr/bin/cvs2cl") {
[315]1167 pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
[286]1168 } else {
1169 # To be written from pbcl
1170 pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
1171 }
[285]1172 }
[106]1173} else {
[315]1174 die "cms $scheme unknown";
[106]1175}
1176}
1177
[204]1178sub pb_cms_getinfo {
[318]1179
[315]1180my $scheme = shift;
[314]1181my $dir = shift;
[315]1182my $info = shift || "URL:";
1183
1184my $res = "";
[204]1185my $void = "";
[106]1186
[315]1187if ($scheme =~ /^svn/) {
[314]1188 open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
[204]1189 while (<PIPE>) {
[315]1190 ($void,$res) = split(/^$info/) if (/^$info/);
[204]1191 }
[318]1192 $res =~ s/^\s*//;
[204]1193 close(PIPE);
[315]1194 chomp($res);
1195} elsif ($scheme eq "flat") {
1196} elsif ($scheme eq "cvs") {
[204]1197} else {
[315]1198 die "cms $scheme unknown";
[204]1199}
[318]1200pb_log(2,"Found CMS info: $res\n");
[315]1201return($res);
[204]1202}
1203
1204sub pb_cms_copy {
[315]1205my $scheme = shift;
[204]1206my $oldurl = shift;
1207my $newurl = shift;
1208
[315]1209if ($scheme eq "svn") {
[212]1210 pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
[315]1211} elsif ($scheme eq "flat") {
1212} elsif ($scheme eq "cvs") {
[204]1213} else {
[315]1214 die "cms $scheme unknown";
[204]1215}
1216}
1217
1218sub pb_cms_checkout {
[315]1219my $scheme = shift;
[204]1220my $url = shift;
1221my $destination = shift;
1222
[315]1223if ($scheme =~ /^svn/) {
[204]1224 pb_system("svn co $url $destination","Checking $url to $destination ");
[315]1225} elsif ($scheme eq "flat") {
1226} elsif ($scheme eq "cvs") {
[204]1227} else {
[315]1228 die "cms $scheme unknown";
[204]1229}
1230}
1231
[208]1232sub pb_cms_checkin {
[315]1233my $scheme = shift;
[208]1234my $dir = shift;
1235
[212]1236my $ver = basename($dir);
[315]1237if ($scheme eq "svn") {
[212]1238 pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
[208]1239 pb_system("svn up $dir","Updating $dir");
[315]1240} elsif ($scheme eq "flat") {
1241} elsif ($scheme eq "cvs") {
[208]1242} else {
[315]1243 die "cms $scheme unknown";
[208]1244}
1245}
1246
[204]1247sub pb_cms_isdiff {
[315]1248my $scheme = shift;
[204]1249
[315]1250if ($scheme eq "svn") {
[204]1251 open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
1252 my $l = 0;
1253 while (<PIPE>) {
1254 $l++;
1255 }
1256 return($l);
[315]1257} elsif ($scheme eq "flat") {
1258} elsif ($scheme eq "cvs") {
[204]1259} else {
[315]1260 die "cms $scheme unknown";
[204]1261}
1262}
1263
[77]1264# Get all filters to apply
1265# They're cumulative from less specific to most specific
1266# suffix is .pbf
1267
1268sub pb_get_filters {
1269
1270my @ffiles;
[235]1271my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
1272my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
[77]1273my $pbpkg = shift || die "No package specified";
[236]1274my $dtype = shift || "";
1275my $dfam = shift || "";
1276my $ddir = shift || "";
1277my $dver = shift || "";
[77]1278my $ptr; # returned value pointer on the hash of filters
[79]1279my %ptr;
[291]1280my %h;
[77]1281
[169]1282# Global filter files first, then package specificities
[314]1283if (-d "$ENV{'PBROOT'}/pbfilter") {
1284 $mfile00 = "$ENV{'PBROOT'}/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/all.pbf");
1285 $mfile0 = "$ENV{'PBROOT'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dtype.pbf");
1286 $mfile1 = "$ENV{'PBROOT'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dfam.pbf");
1287 $mfile2 = "$ENV{'PBROOT'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir.pbf");
1288 $mfile3 = "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf");
[169]1289
[231]1290 push @ffiles,$mfile00 if (defined $mfile00);
[169]1291 push @ffiles,$mfile0 if (defined $mfile0);
1292 push @ffiles,$mfile1 if (defined $mfile1);
1293 push @ffiles,$mfile2 if (defined $mfile2);
1294 push @ffiles,$mfile3 if (defined $mfile3);
1295}
1296
[314]1297if (-d "$ENV{'PBROOT'}/$pbpkg/pbfilter") {
1298 $ffile00 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf");
1299 $ffile0 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf");
1300 $ffile1 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf");
1301 $ffile2 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf");
1302 $ffile3 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
[77]1303
[231]1304 push @ffiles,$ffile00 if (defined $ffile00);
[77]1305 push @ffiles,$ffile0 if (defined $ffile0);
1306 push @ffiles,$ffile1 if (defined $ffile1);
1307 push @ffiles,$ffile2 if (defined $ffile2);
1308 push @ffiles,$ffile3 if (defined $ffile3);
1309}
1310if (@ffiles) {
[315]1311 pb_log(2,"DEBUG ffiles: ".Dumper(\@ffiles)."\n");
[79]1312
[291]1313 foreach my $f (@ffiles) {
1314 open(CONF,$f) || next;
1315 while(<CONF>) {
1316 if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
1317 $h{$1}{$2}=$3;
1318 }
[79]1319 }
[291]1320 close(CONF);
[79]1321
[291]1322 $ptr = $h{"filter"};
[315]1323 pb_log(2,"DEBUG f:".Dumper($ptr)."\n");
[291]1324 }
[77]1325} else {
1326 $ptr = { };
1327}
[79]1328%ptr = %$ptr;
1329return(\%ptr);
[77]1330}
1331
[236]1332# Function which applies filter on pb build files
[77]1333sub pb_filter_file_pb {
1334
1335my $f=shift;
1336my $ptr=shift;
1337my %filter=%$ptr;
1338my $destfile=shift;
1339my $dtype=shift;
[99]1340my $pbsuf=shift;
[297]1341my $pbproj=shift;
[80]1342my $pbpkg=shift;
1343my $pbver=shift;
1344my $pbtag=shift;
1345my $pbrev=shift;
1346my $pbdate=shift;
[108]1347my $defpkgdir = shift;
1348my $extpkgdir = shift;
[174]1349my $pbpackager = shift;
[285]1350my $chglog = shift || undef;
[77]1351
[315]1352pb_log(2,"DEBUG: From $f to $destfile\n");
[77]1353pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1354open(DEST,"> $destfile") || die "Unable to create $destfile";
1355open(FILE,"$f") || die "Unable to open $f: $!";
1356while (<FILE>) {
1357 my $line = $_;
1358 foreach my $s (keys %filter) {
1359 # Process single variables
[315]1360 pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
[77]1361 my $tmp = $filter{$s};
1362 next if (not defined $tmp);
1363 # Expand variables if any single one found
[315]1364 pb_log(2,"DEBUG tmp: $tmp\n");
[77]1365 if ($tmp =~ /\$/) {
1366 eval { $tmp =~ s/(\$\w+)/$1/eeg };
1367 # special case for ChangeLog only for pb
[259]1368 } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
[108]1369 my $p = $defpkgdir->{$pbpkg};
1370 $p = $extpkgdir->{$pbpkg} if (not defined $p);
[285]1371 pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
[254]1372 $tmp = "";
[77]1373 }
1374 $line =~ s|$s|$tmp|;
1375 }
1376 print DEST $line;
1377}
1378close(FILE);
1379close(DEST);
1380}
1381
1382# Function which applies filter on files (external call)
[315]1383sub pb_filter_file_inplace {
1384
1385my $ptr=shift;
1386my %filter=%$ptr;
1387my $destfile=shift;
1388my $pbproj=shift;
1389my $pbpkg=shift;
1390my $pbver=shift;
1391my $pbtag=shift;
1392my $pbrev=shift;
1393my $pbdate=shift;
1394my $pbpackager=shift;
1395
1396my $cp = "$ENV{'PBTMP'}/".basename($destfile);
1397copy($destfile,$cp) || die "Unable to create $cp";
1398
1399pb_filter_file($cp,$ptr,$destfile,$pbproj,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
1400unlink $cp;
1401}
1402
1403# Function which applies filter on files (external call)
[77]1404sub pb_filter_file {
1405
1406my $f=shift;
1407my $ptr=shift;
1408my %filter=%$ptr;
1409my $destfile=shift;
[298]1410my $pbproj=shift;
[80]1411my $pbpkg=shift;
1412my $pbver=shift;
1413my $pbtag=shift;
1414my $pbrev=shift;
1415my $pbdate=shift;
[174]1416my $pbpackager=shift;
[77]1417
[315]1418pb_log(2,"DEBUG: From $f to $destfile\n");
[77]1419pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1420open(DEST,"> $destfile") || die "Unable to create $destfile";
1421open(FILE,"$f") || die "Unable to open $f: $!";
1422while (<FILE>) {
1423 my $line = $_;
1424 foreach my $s (keys %filter) {
1425 # Process single variables
[315]1426 pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
[77]1427 my $tmp = $filter{$s};
1428 next if (not defined $tmp);
1429 # Expand variables if any single one found
1430 if ($tmp =~ /\$/) {
1431 eval { $tmp =~ s/(\$\w+)/$1/eeg };
1432 }
1433 $line =~ s|$s|$tmp|;
1434 }
1435 print DEST $line;
1436}
1437close(FILE);
1438close(DEST);
1439}
1440
[315]1441sub pb_log_init {
[77]1442
[315]1443$debug = shift || 0;
1444$LOG = shift || \*STDOUT;
1445
1446}
1447
1448sub pb_log {
1449
1450my $dlevel = shift;
1451my $msg = shift;
1452
[318]1453print $LOG "$msg" if ($dlevel <= $debug);
[315]1454}
1455
[316]1456#
1457# Return the list of packages we are working on
1458#
1459sub pb_get_pkg {
1460
1461my @pkgs = ();
1462my $defpkgdir = shift || undef;
1463my $extpkgdir = shift || undef;
1464
1465# Get packages list
1466if (not defined $ARGV[0]) {
1467 @pkgs = keys %$defpkgdir if (defined $defpkgdir);
1468} elsif ($ARGV[0] =~ /^all$/) {
[317]1469 @pkgs = keys %$defpkgdir if (defined $defpkgdir);
[316]1470 push(@pkgs, keys %$extpkgdir) if (defined $extpkgdir);
1471} else {
1472 @pkgs = @ARGV;
1473}
1474pb_log(0,"Packages: ".join(',',@pkgs)."\n");
1475return(\@pkgs);
1476}
1477
[2]14781;
Note: See TracBrowser for help on using the repository browser.