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

Last change on this file since 227 was 227, checked in by Bruno Cornec, 17 years ago

Flat mode now working for collectl

File size: 16.1 KB
RevLine 
[2]1#!/usr/bin/perl -w
2#
[74]3# Base subroutines for the Project-Builder project
[2]4#
5# $Id$
6#
7
[18]8use strict;
[5]9use lib qw (lib);
[2]10use File::Basename;
[9]11use File::Path;
[2]12use File::Temp qw /tempdir/;
[74]13use AppConfig qw(ARGCOUNT_HASH);
[8]14use Data::Dumper;
[2]15
[199]16use ProjectBuilder::Changelog qw (pb_changelog);
17
[49]18$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
[5]19
[74]20sub pb_env_init {
[2]21
[5]22my $proj=shift;
23my $ver;
24my $tag;
[2]25
[107]26# For the moment not dynamic
27my $debug = 0; # Debug level
28my $LOG = *STDOUT; # Where to log
29
[8]30#
[5]31# Check project name
[49]32# Could be with env var PBPROJ
33# or option -p
34# if not define take the first in conf file
[8]35#
[5]36if ((defined $ENV{'PBPROJ'}) &&
37 (not (defined $proj))) {
38 $proj = $ENV{'PBPROJ'};
39}
[69]40
[49]41#
[69]42# We get the pbrc file for that project
43# and use its content
44#
[89]45my ($pbrc) = pb_conf_read("$ENV{'PBETC'}","pbrc");
[74]46print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
[69]47
[108]48my %pbrc = %$pbrc;
[69]49if (not defined $proj) {
50 # Take the first as the default project
51 $proj = (keys %pbrc)[0];
52 print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
53}
54die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
55
56#
57# Set delivery directory
58#
[71]59my $topdir=dirname($pbrc{$proj});
[108]60# Expand potential env variable in it
61eval { $topdir =~ s/(\$ENV.+\})/$1/eeg };
[69]62chdir $topdir || die "Unable to change directory to $topdir";
[108]63$pbrc{$proj} = $topdir."/pbrc";
[69]64$ENV{'PBDESTDIR'}=$topdir."/delivery";
65
66#
[67]67# Use project configuration file if needed
[49]68#
[67]69if (not defined $ENV{'PBROOT'}) {
[69]70 if (-f $pbrc{$proj}) {
[89]71 my ($pbroot) = pb_conf_read($pbrc{$proj},"pbroot");
[71]72 my %pbroot = %$pbroot;
[77]73 # All lines should point to the same pbroot so take the first
[69]74 $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot);
75 print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'}));
[67]76 }
[69]77 die "No pbroot defined - use env var PBROOT or -r pbroot " if (not defined $ENV{'PBROOT'});
[49]78}
[2]79
[8]80#
[49]81# Check pb conf compliance
[8]82#
[49]83$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
84die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
[2]85
[74]86my %version = ();
[108]87my %defpkgdir = ();
88my %extpkgdir = ();
89my %filteredfiles = ();
[74]90
[49]91if (-f "$ENV{'PBCONF'}/$proj.pb") {
[74]92 # List of pkg to build by default (mandatory)
93 # List of additional pkg to build when all is called (optional)
94 # Valid version names (optional)
95 # List of files to filter (optional)
[105]96 my ($defpkgdir, $extpkgdir, $version, $filteredfiles, $pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$proj.pb","defpkgdir","extpkgdir","version","filteredfiles","projver","projtag");
[74]97 print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
98 print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
99 print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
100 print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
101 die "Unable to find defpkgdir in $ENV{'PBCONF'}/$proj.pb" if (not defined $defpkgdir);
102 # Global
103 %defpkgdir = %$defpkgdir;
104 # Global
[114]105 %extpkgdir = %$extpkgdir if (defined $extpkgdir);
[74]106 %version = %$version if (defined $version);
107 # Global
108 %filteredfiles = %$filteredfiles if (defined $filteredfiles);
[106]109 #
110 # Get global Version/Tag
111 #
[38]112
[106]113 if (not defined $ENV{'PBVER'}) {
114 if ((defined $pkgv) && (defined $pkgv->{$proj})) {
115 $ENV{'PBVER'}=$pkgv->{$proj};
116 } else {
117 die "No projver found in $ENV{'PBCONF'}/$proj.pb";
118 }
[98]119 }
[106]120 die "Invalid version name $ENV{'PBVER'} in $ENV{'PBCONF'}/$proj.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not exists $version{$ENV{'PBVER'}}));
121
122 if (not defined $ENV{'PBTAG'}) {
123 if ((defined $pkgt) && (defined $pkgt->{$proj})) {
124 $ENV{'PBTAG'}=$pkgt->{$proj};
125 } else {
126 die "No projtag found in $ENV{'PBCONF'}/$proj.pb";
127 }
[98]128 }
[106]129 die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBCONF'}/$proj.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
130} else {
131 die "Unable to open $ENV{'PBCONF'}/$proj.pb";
[98]132}
133
[8]134#
[105]135# Set temp directory
136#
137if (not defined $ENV{'TMPDIR'}) {
138 $ENV{'TMPDIR'}="/tmp";
139}
140$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
141
142#
[69]143# Removes all directory existing below the delivery dir
144# as they are temp dir only
[68]145# Files stay and have to be cleaned up manually
[8]146#
[25]147if (-d $ENV{'PBDESTDIR'}) {
148 opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
149 foreach my $d (readdir(DIR)) {
150 next if ($d =~ /^\./);
[68]151 next if (-f "$ENV{'PBDESTDIR'}/$d");
[74]152 pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
[25]153 }
154 closedir(DIR);
155}
156if (! -d "$ENV{'PBDESTDIR'}") {
[74]157 pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
[25]158}
[5]159
[25]160#
161# Set build directory
162#
[71]163$ENV{'PBBUILDDIR'}=$topdir."/build";
[101]164if (! -d "$ENV{'PBBUILDDIR'}") {
165 pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
166}
[25]167
[8]168umask 0022;
[107]169return($proj,$debug,$LOG,\%pbrc, \%filteredfiles, \%defpkgdir, \%extpkgdir);
[2]170}
[9]171
[74]172# Internal mkdir -p function
173sub pb_mkdir_p {
[29]174my @dir = @_;
175my $ret = mkpath(@dir, 0, 0755);
176return($ret);
[9]177}
178
[74]179# Internal rm -rf function
180sub pb_rm_rf {
[29]181my @dir = @_;
182my $ret = rmtree(@dir, 0, 0);
183return($ret);
[9]184}
185
[74]186# Internal system function
187sub pb_system {
[29]188
189my $cmd=shift;
[30]190my $cmt=shift || $cmd;
[29]191
[108]192print "$cmt... ";
[117]193#system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
194system("$cmd");
[29]195if ($? == -1) {
[108]196 print "failed to execute ($cmd) : $!\n";
[106]197 pb_display_file("$ENV{'PBTMP'}/system.log");
[29]198} elsif ($? & 127) {
[108]199 printf "child ($cmd) died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
[106]200 pb_display_file("$ENV{'PBTMP'}/system.log");
201} elsif ($? == 0) {
[108]202 print "OK\n";
[29]203} else {
[106]204 printf "child ($cmd) exited with value %d\n", $? >> 8;
205 pb_display_file("$ENV{'PBTMP'}/system.log");
[29]206}
[30]207}
[74]208
[106]209sub pb_display_file {
210
211my $file=shift;
212
[117]213return if (not -f $file);
214open(FILE,"$file");
[106]215while (<FILE>) {
[108]216 print $_;
[106]217}
218close(FILE);
219}
220
[74]221# Function which returns a pointer on a hash
[88]222# corresponding to a declaration (arg2) in the main conf file
223# and test the returned vaue as they need to exist in that case
224sub pb_conf_get {
225
226my @param = @_;
227
[89]228my @ptr = pb_conf_read("$ENV{'PBETC'}", @param);
229
[88]230foreach my $i (0..$#param) {
231 die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $ptr[$i]);
232 my $p = $ptr[$i];
233 $p->{$ENV{'PBPROJ'}} = $p->{'default'} if (not defined $p->{$ENV{'PBPROJ'}});
234 die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $p->{$ENV{'PBPROJ'}});
235}
[108]236#print "DEBUG: param: ".Dumper(@ptr)."\n" if ($debug >= 1);
[89]237return(@ptr);
[88]238}
239
240# Function which returns a pointer on a hash
[74]241# corresponding to a declaration (arg2) in a conf file (arg1)
242sub pb_conf_read {
243
244my $conffile = shift;
245my @param = @_;
246my $trace;
247my @ptr;
248
[108]249my $debug = 0;
250
[74]251if ($debug > 0) {
252 $trace = 1;
253} else {
254 $trace = 0;
255}
256
257
258my $config = AppConfig->new({
259 # Auto Create variables mentioned in Conf file
260 CREATE => 1,
261 DEBUG => $trace,
262 GLOBAL => {
263 # Each conf item is a hash
264 ARGCOUNT => ARGCOUNT_HASH,
265 },
266 });
267$config->file($conffile);
268for my $param (@param) {
269 push @ptr,$config->get($param);
270}
[89]271print "DEBUG: params: ".Dumper(@param)." ".Dumper(@ptr)."\n" if ($debug >= 1);
272return(@ptr);
[74]273}
274
275# Setup environment for CMS system
276sub pb_cms_init {
277
278my $proj = shift || undef;
279my $ret;
280
[89]281my ($cms) = pb_conf_get("cms");
[88]282# This one is optional
[112]283my ($cvsroot,$cvsrsh) = pb_conf_read($ENV{'PBETC'},"cvsroot","cvsrsh");
[74]284
[88]285if ($cms->{$proj} eq "svn") {
[74]286 $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
287 chomp($ENV{'PBREVISION'});
288 $ENV{'PBCMSLOG'}="svn log";
289 $ENV{'PBCMSLOGFILE'}="svn.log";
[226]290} elsif ($cms->{$proj} eq "flat") {
291 $ENV{'PBREVISION'}="flat";
292 $ENV{'PBCMSLOG'}="/bin/true";
[227]293 $ENV{'PBCMSLOGFILE'}="flat.log";
[88]294} elsif ($cms->{$proj} eq "cvs") {
[106]295 # Way too slow
296 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
297 #chomp($ENV{'PBREVISION'});
298 $ENV{'PBREVISION'}="CVS";
[74]299 $ENV{'PBCMSLOG'}="cvs log";
300 $ENV{'PBCMSLOGFILE'}="cvs.log";
[87]301 #
302 # Export content if needed
303 #
[88]304 $ENV{'CVSROOT'} = $cvsroot->{$proj} if (defined $cvsroot->{$proj});
[112]305 $ENV{'CVSRSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
[74]306} else {
[88]307 die "cms $cms->{$proj} unknown";
[74]308}
[106]309return($cms);
[74]310}
311
[106]312sub pb_cms_export {
313my $cms = shift;
314my $pbdate = shift || undef;
[108]315my $source = shift;
[106]316my $destdir = shift;
[108]317my $tmp;
[115]318my $tmp1;
[106]319
320if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
[108]321 if (-d $source) {
322 $tmp = $destdir;
323 } else {
324 $tmp = $destdir."/".basename($source);
325 }
[116]326 pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
[226]327} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
328 if (-d $source) {
329 $tmp = $destdir;
330 } else {
331 $tmp = $destdir."/".basename($source);
332 }
333 pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
[106]334} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
335 my $dir=dirname($destdir);
336 my $base=basename($destdir);
[115]337 if (-d $source) {
338 $tmp1 = $source;
339 $tmp1 =~ s|$ENV{'PBROOT'}/||;
340 } else {
341 $tmp1 = dirname($source);
342 $tmp1 =~ s|$ENV{'PBROOT'}/||;
343 $tmp1 = $tmp1."/".basename($source);
344 }
[106]345 # CVS needs a relative path !
[115]346 pb_system("cd $dir ; cvs export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
[106]347} else {
348 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
349}
350}
351
352sub pb_cms_log {
353my $cms = shift;
354my $pkgdir = shift;
355my $destfile = shift;
356
357if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
[112]358 pb_system("svn log -v $pkgdir > $destfile","Extracting log info from SVN");
[226]359} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
360 # Nothing to do
[106]361} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
362 my $tmp=basename($pkgdir);
363 # CVS needs a relative path !
364 pb_system("cvs log $tmp > $destfile","Extracting log info from CVS");
365} else {
366 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
367}
368}
369
[204]370sub pb_cms_getinfo {
371my $cms = shift;
372my $url = "";
373my $void = "";
[106]374
[204]375if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
376 open(PIPE,"LANGUAGE=C svn info $ENV{'PBROOT'} |") || die "Unable to get svn info from $ENV{'PBROOT'}";
377 while (<PIPE>) {
[206]378 ($void,$url) = split(/^URL:/) if (/^URL:/);
[204]379 }
380 close(PIPE);
[205]381 chomp($url);
[226]382} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
[204]383} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
384} else {
385 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
386}
387return($url);
388}
389
390sub pb_cms_copy {
391my $cms = shift;
392my $oldurl = shift;
393my $newurl = shift;
394
395if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
[212]396 pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
[226]397} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
[204]398} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
399} else {
400 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
401}
402}
403
404sub pb_cms_checkout {
405my $cms = shift;
406my $url = shift;
407my $destination = shift;
408
409if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
410 pb_system("svn co $url $destination","Checking $url to $destination ");
[226]411} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
[204]412} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
413} else {
414 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
415}
416}
417
[208]418sub pb_cms_checkin {
419my $cms = shift;
420my $dir = shift;
421
[212]422my $ver = basename($dir);
[208]423if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
[212]424 pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
[208]425 pb_system("svn up $dir","Updating $dir");
[226]426} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
[208]427} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
428} else {
429 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
430}
431}
432
[204]433sub pb_cms_isdiff {
434my $cms = shift;
435
436if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
437 open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
438 my $l = 0;
439 while (<PIPE>) {
440 $l++;
441 }
442 return($l);
[226]443} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
[204]444} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
445} else {
446 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
447}
448}
449
[77]450# Get all filters to apply
451# They're cumulative from less specific to most specific
452# suffix is .pbf
453
454sub pb_get_filters {
455
[108]456# For the moment not dynamic
457my $debug = 0; # Debug level
458my $LOG = *STDOUT; # Where to log
459
[77]460my @ffiles;
461my ($ffile0, $ffile1, $ffile2, $ffile3);
[169]462my ($mfile0, $mfile1, $mfile2, $mfile3);
[77]463my $pbpkg = shift || die "No package specified";
464my $dtype = shift || die "No dtype specified";
465my $dfam = shift || die "No dfam specified";
466my $ddir = shift || die "No ddir specified";
467my $dver = shift || die "No dver specified";
468my $ptr; # returned value pointer on the hash of filters
[79]469my %ptr;
[77]470
[169]471# Global filter files first, then package specificities
472if (-d "$ENV{'PBCONF'}/pbfilter") {
473 $mfile0 = "$ENV{'PBCONF'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$dtype.pbf");
474 $mfile1 = "$ENV{'PBCONF'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$dfam.pbf");
475 $mfile2 = "$ENV{'PBCONF'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$ddir.pbf");
476 $mfile3 = "$ENV{'PBCONF'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$ddir-$dver.pbf");
477
478 push @ffiles,$mfile0 if (defined $mfile0);
479 push @ffiles,$mfile1 if (defined $mfile1);
480 push @ffiles,$mfile2 if (defined $mfile2);
481 push @ffiles,$mfile3 if (defined $mfile3);
482}
483
[77]484if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
485 $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
486 $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
487 $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
488 $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
489
490 push @ffiles,$ffile0 if (defined $ffile0);
491 push @ffiles,$ffile1 if (defined $ffile1);
492 push @ffiles,$ffile2 if (defined $ffile2);
493 push @ffiles,$ffile3 if (defined $ffile3);
494}
495if (@ffiles) {
496 print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
[79]497
498 my $config = AppConfig->new({
499 # Auto Create variables mentioned in Conf file
500 CREATE => 1,
501 DEBUG => 0,
502 GLOBAL => {
503 # Each conf item is a hash
504 ARGCOUNT => AppConfig::ARGCOUNT_HASH
505 }
506 });
507
[77]508 $config->file(@ffiles);
509 $ptr = $config->get("filter");
510 print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
511} else {
512 $ptr = { };
513}
[79]514%ptr = %$ptr;
515return(\%ptr);
[77]516}
517
518# Function which applies filter on files (only for pb)
519sub pb_filter_file_pb {
520
521my $f=shift;
522my $ptr=shift;
523my %filter=%$ptr;
524my $destfile=shift;
525my $dtype=shift;
[99]526my $pbsuf=shift;
[80]527my $pbpkg=shift;
528my $pbver=shift;
529my $pbtag=shift;
530my $pbrev=shift;
531my $pbdate=shift;
[108]532my $defpkgdir = shift;
533my $extpkgdir = shift;
[174]534my $pbpackager = shift;
[77]535
[108]536# For the moment not dynamic
537my $debug = 0; # Debug level
538my $LOG = *STDOUT; # Where to log
539
[77]540print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
541pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
542open(DEST,"> $destfile") || die "Unable to create $destfile";
543open(FILE,"$f") || die "Unable to open $f: $!";
544while (<FILE>) {
545 my $line = $_;
546 foreach my $s (keys %filter) {
547 # Process single variables
[79]548 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug >= 1);
[77]549 my $tmp = $filter{$s};
550 next if (not defined $tmp);
551 # Expand variables if any single one found
[79]552 print $LOG "DEBUG tmp: $tmp\n" if ($debug >= 1);
[77]553 if ($tmp =~ /\$/) {
554 eval { $tmp =~ s/(\$\w+)/$1/eeg };
555 # special case for ChangeLog only for pb
556 } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
557 $tmp = "";
[108]558 my $p = $defpkgdir->{$pbpkg};
559 $p = $extpkgdir->{$pbpkg} if (not defined $p);
[99]560 pb_changelog($dtype, $pbpkg, $pbtag, $pbsuf, $p, \*DEST);
[77]561 }
562 $line =~ s|$s|$tmp|;
563 }
564 print DEST $line;
565}
566close(FILE);
567close(DEST);
568}
569
570# Function which applies filter on files (external call)
571sub pb_filter_file {
572
573my $f=shift;
574my $ptr=shift;
575my %filter=%$ptr;
576my $destfile=shift;
[99]577my $pbsuf=shift;
[80]578my $pbpkg=shift;
579my $pbver=shift;
580my $pbtag=shift;
581my $pbrev=shift;
582my $pbdate=shift;
[174]583my $pbpackager=shift;
[77]584
[108]585# For the moment not dynamic
586my $debug = 0; # Debug level
587my $LOG = *STDOUT; # Where to log
588
[77]589print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
590pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
591open(DEST,"> $destfile") || die "Unable to create $destfile";
592open(FILE,"$f") || die "Unable to open $f: $!";
593while (<FILE>) {
594 my $line = $_;
595 foreach my $s (keys %filter) {
596 # Process single variables
597 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
598 my $tmp = $filter{$s};
599 next if (not defined $tmp);
600 # Expand variables if any single one found
601 if ($tmp =~ /\$/) {
602 eval { $tmp =~ s/(\$\w+)/$1/eeg };
603 }
604 $line =~ s|$s|$tmp|;
605 }
606 print DEST $line;
607}
608close(FILE);
609close(DEST);
610}
611
612
[2]6131;
Note: See TracBrowser for help on using the repository browser.