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

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

cms_export now also supports svn+ssh

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