[2] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
[74] | 3 | # Base subroutines for the Project-Builder project
|
---|
[2] | 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
| 7 |
|
---|
[18] | 8 | use strict;
|
---|
[5] | 9 | use lib qw (lib);
|
---|
[2] | 10 | use File::Basename;
|
---|
[9] | 11 | use File::Path;
|
---|
[2] | 12 | use File::Temp qw /tempdir/;
|
---|
[74] | 13 | use AppConfig qw(ARGCOUNT_HASH);
|
---|
[8] | 14 | use Data::Dumper;
|
---|
[2] | 15 |
|
---|
[49] | 16 | $ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
|
---|
[5] | 17 |
|
---|
[74] | 18 | sub pb_env_init {
|
---|
[2] | 19 |
|
---|
[5] | 20 | my $proj=shift;
|
---|
| 21 | my $ver;
|
---|
| 22 | my $tag;
|
---|
[2] | 23 |
|
---|
[8] | 24 | #
|
---|
[5] | 25 | # Check project name
|
---|
[49] | 26 | # Could be with env var PBPROJ
|
---|
| 27 | # or option -p
|
---|
| 28 | # if not define take the first in conf file
|
---|
[8] | 29 | #
|
---|
[5] | 30 | if ((defined $ENV{'PBPROJ'}) &&
|
---|
| 31 | (not (defined $proj))) {
|
---|
| 32 | $proj = $ENV{'PBPROJ'};
|
---|
| 33 | }
|
---|
[69] | 34 |
|
---|
[49] | 35 | #
|
---|
[69] | 36 | # We get the pbrc file for that project
|
---|
| 37 | # and use its content
|
---|
| 38 | #
|
---|
[89] | 39 | my ($pbrc) = pb_conf_read("$ENV{'PBETC'}","pbrc");
|
---|
[74] | 40 | print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
|
---|
[69] | 41 |
|
---|
[70] | 42 | %pbrc = %$pbrc;
|
---|
[69] | 43 | if (not defined $proj) {
|
---|
| 44 | # Take the first as the default project
|
---|
| 45 | $proj = (keys %pbrc)[0];
|
---|
| 46 | print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
|
---|
| 47 | }
|
---|
| 48 | die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
|
---|
| 49 |
|
---|
| 50 | #
|
---|
| 51 | # Set delivery directory
|
---|
| 52 | #
|
---|
[71] | 53 | my $topdir=dirname($pbrc{$proj});
|
---|
[69] | 54 | chdir $topdir || die "Unable to change directory to $topdir";
|
---|
| 55 | $ENV{'PBDESTDIR'}=$topdir."/delivery";
|
---|
| 56 |
|
---|
| 57 | #
|
---|
[67] | 58 | # Use project configuration file if needed
|
---|
[49] | 59 | #
|
---|
[67] | 60 | if (not defined $ENV{'PBROOT'}) {
|
---|
[69] | 61 | if (-f $pbrc{$proj}) {
|
---|
[89] | 62 | my ($pbroot) = pb_conf_read($pbrc{$proj},"pbroot");
|
---|
[71] | 63 | my %pbroot = %$pbroot;
|
---|
[77] | 64 | # All lines should point to the same pbroot so take the first
|
---|
[69] | 65 | $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot);
|
---|
| 66 | print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'}));
|
---|
[67] | 67 | }
|
---|
[69] | 68 | die "No pbroot defined - use env var PBROOT or -r pbroot " if (not defined $ENV{'PBROOT'});
|
---|
[49] | 69 | }
|
---|
[2] | 70 |
|
---|
[8] | 71 | #
|
---|
[49] | 72 | # Check pb conf compliance
|
---|
[8] | 73 | #
|
---|
[49] | 74 | $ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
|
---|
| 75 | die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
|
---|
[2] | 76 |
|
---|
[74] | 77 | my %version = ();
|
---|
| 78 |
|
---|
[49] | 79 | if (-f "$ENV{'PBCONF'}/$proj.pb") {
|
---|
[74] | 80 | # List of pkg to build by default (mandatory)
|
---|
| 81 | # List of additional pkg to build when all is called (optional)
|
---|
| 82 | # Valid version names (optional)
|
---|
| 83 | # List of files to filter (optional)
|
---|
[105] | 84 | my ($defpkgdir, $extpkgdir, $version, $filteredfiles, $pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$proj.pb","defpkgdir","extpkgdir","version","filteredfiles","projver","projtag");
|
---|
[74] | 85 | print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
|
---|
| 86 | print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
|
---|
| 87 | print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
|
---|
| 88 | print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
|
---|
| 89 | die "Unable to find defpkgdir in $ENV{'PBCONF'}/$proj.pb" if (not defined $defpkgdir);
|
---|
| 90 | # Global
|
---|
| 91 | %defpkgdir = %$defpkgdir;
|
---|
| 92 | # Global
|
---|
| 93 | %extpkgdir = ();
|
---|
| 94 | %extpkgdir = %$defpkgdir if (defined $defpkgdir);
|
---|
| 95 | %version = ();
|
---|
| 96 | %version = %$version if (defined $version);
|
---|
| 97 | # Global
|
---|
| 98 | %filteredfiles = ();
|
---|
| 99 | %filteredfiles = %$filteredfiles if (defined $filteredfiles);
|
---|
[106] | 100 | #
|
---|
| 101 | # Get global Version/Tag
|
---|
| 102 | #
|
---|
[38] | 103 |
|
---|
[106] | 104 | if (not defined $ENV{'PBVER'}) {
|
---|
| 105 | if ((defined $pkgv) && (defined $pkgv->{$proj})) {
|
---|
| 106 | $ENV{'PBVER'}=$pkgv->{$proj};
|
---|
| 107 | } else {
|
---|
| 108 | die "No projver found in $ENV{'PBCONF'}/$proj.pb";
|
---|
| 109 | }
|
---|
[98] | 110 | }
|
---|
[106] | 111 | die "Invalid version name $ENV{'PBVER'} in $ENV{'PBCONF'}/$proj.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not exists $version{$ENV{'PBVER'}}));
|
---|
| 112 |
|
---|
| 113 | if (not defined $ENV{'PBTAG'}) {
|
---|
| 114 | if ((defined $pkgt) && (defined $pkgt->{$proj})) {
|
---|
| 115 | $ENV{'PBTAG'}=$pkgt->{$proj};
|
---|
| 116 | } else {
|
---|
| 117 | die "No projtag found in $ENV{'PBCONF'}/$proj.pb";
|
---|
| 118 | }
|
---|
[98] | 119 | }
|
---|
[106] | 120 | die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBCONF'}/$proj.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
|
---|
| 121 | } else {
|
---|
| 122 | die "Unable to open $ENV{'PBCONF'}/$proj.pb";
|
---|
[98] | 123 | }
|
---|
| 124 |
|
---|
[8] | 125 | #
|
---|
[105] | 126 | # Set temp directory
|
---|
| 127 | #
|
---|
| 128 | if (not defined $ENV{'TMPDIR'}) {
|
---|
| 129 | $ENV{'TMPDIR'}="/tmp";
|
---|
| 130 | }
|
---|
| 131 | $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
|
---|
| 132 |
|
---|
| 133 | #
|
---|
[69] | 134 | # Removes all directory existing below the delivery dir
|
---|
| 135 | # as they are temp dir only
|
---|
[68] | 136 | # Files stay and have to be cleaned up manually
|
---|
[8] | 137 | #
|
---|
[25] | 138 | if (-d $ENV{'PBDESTDIR'}) {
|
---|
| 139 | opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
|
---|
| 140 | foreach my $d (readdir(DIR)) {
|
---|
| 141 | next if ($d =~ /^\./);
|
---|
[68] | 142 | next if (-f "$ENV{'PBDESTDIR'}/$d");
|
---|
[74] | 143 | pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
|
---|
[25] | 144 | }
|
---|
| 145 | closedir(DIR);
|
---|
| 146 | }
|
---|
| 147 | if (! -d "$ENV{'PBDESTDIR'}") {
|
---|
[74] | 148 | pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
|
---|
[25] | 149 | }
|
---|
[5] | 150 |
|
---|
[25] | 151 | #
|
---|
| 152 | # Set build directory
|
---|
| 153 | #
|
---|
[71] | 154 | $ENV{'PBBUILDDIR'}=$topdir."/build";
|
---|
[101] | 155 | if (! -d "$ENV{'PBBUILDDIR'}") {
|
---|
| 156 | pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
|
---|
| 157 | }
|
---|
[25] | 158 |
|
---|
[8] | 159 | umask 0022;
|
---|
| 160 | return($proj);
|
---|
[2] | 161 | }
|
---|
[9] | 162 |
|
---|
[74] | 163 | # Internal mkdir -p function
|
---|
| 164 | sub pb_mkdir_p {
|
---|
[29] | 165 | my @dir = @_;
|
---|
| 166 | my $ret = mkpath(@dir, 0, 0755);
|
---|
| 167 | return($ret);
|
---|
[9] | 168 | }
|
---|
| 169 |
|
---|
[74] | 170 | # Internal rm -rf function
|
---|
| 171 | sub pb_rm_rf {
|
---|
[29] | 172 | my @dir = @_;
|
---|
| 173 | my $ret = rmtree(@dir, 0, 0);
|
---|
| 174 | return($ret);
|
---|
[9] | 175 | }
|
---|
| 176 |
|
---|
[74] | 177 | # Internal system function
|
---|
| 178 | sub pb_system {
|
---|
[29] | 179 |
|
---|
| 180 | my $cmd=shift;
|
---|
[30] | 181 | my $cmt=shift || $cmd;
|
---|
[29] | 182 |
|
---|
[30] | 183 | print $LOG "$cmt... ";
|
---|
[106] | 184 | system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
|
---|
[29] | 185 | if ($? == -1) {
|
---|
[106] | 186 | print $LOG "failed to execute ($cmd) : $!\n" if ($debug >= 0);
|
---|
| 187 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
[29] | 188 | } elsif ($? & 127) {
|
---|
[106] | 189 | printf $LOG "child ($cmd) died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);
|
---|
| 190 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
| 191 | } elsif ($? == 0) {
|
---|
| 192 | print $LOG "OK\n" if ($debug >= 0);
|
---|
[29] | 193 | } else {
|
---|
[106] | 194 | printf "child ($cmd) exited with value %d\n", $? >> 8;
|
---|
| 195 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
[29] | 196 | }
|
---|
[30] | 197 | }
|
---|
[74] | 198 |
|
---|
[106] | 199 | sub pb_display_file {
|
---|
| 200 |
|
---|
| 201 | my $file=shift;
|
---|
| 202 |
|
---|
| 203 | open(FILE,"$file") || die "Unable to open $file";
|
---|
| 204 | while (<FILE>) {
|
---|
| 205 | print $LOG;
|
---|
| 206 | }
|
---|
| 207 | close(FILE);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[74] | 210 | # Function which returns a pointer on a hash
|
---|
[88] | 211 | # corresponding to a declaration (arg2) in the main conf file
|
---|
| 212 | # and test the returned vaue as they need to exist in that case
|
---|
| 213 | sub pb_conf_get {
|
---|
| 214 |
|
---|
| 215 | my @param = @_;
|
---|
| 216 |
|
---|
[89] | 217 | my @ptr = pb_conf_read("$ENV{'PBETC'}", @param);
|
---|
| 218 |
|
---|
[88] | 219 | foreach my $i (0..$#param) {
|
---|
| 220 | die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $ptr[$i]);
|
---|
| 221 | my $p = $ptr[$i];
|
---|
| 222 | $p->{$ENV{'PBPROJ'}} = $p->{'default'} if (not defined $p->{$ENV{'PBPROJ'}});
|
---|
| 223 | die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $p->{$ENV{'PBPROJ'}});
|
---|
| 224 | }
|
---|
[93] | 225 | print "DEBUG: param: ".Dumper(@ptr)."\n" if ($debug >= 1);
|
---|
[89] | 226 | return(@ptr);
|
---|
[88] | 227 | }
|
---|
| 228 |
|
---|
| 229 | # Function which returns a pointer on a hash
|
---|
[74] | 230 | # corresponding to a declaration (arg2) in a conf file (arg1)
|
---|
| 231 | sub pb_conf_read {
|
---|
| 232 |
|
---|
| 233 | my $conffile = shift;
|
---|
| 234 | my @param = @_;
|
---|
| 235 | my $trace;
|
---|
| 236 | my @ptr;
|
---|
| 237 |
|
---|
| 238 | if ($debug > 0) {
|
---|
| 239 | $trace = 1;
|
---|
| 240 | } else {
|
---|
| 241 | $trace = 0;
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 | my $config = AppConfig->new({
|
---|
| 246 | # Auto Create variables mentioned in Conf file
|
---|
| 247 | CREATE => 1,
|
---|
| 248 | DEBUG => $trace,
|
---|
| 249 | GLOBAL => {
|
---|
| 250 | # Each conf item is a hash
|
---|
| 251 | ARGCOUNT => ARGCOUNT_HASH,
|
---|
| 252 | },
|
---|
| 253 | });
|
---|
| 254 | $config->file($conffile);
|
---|
| 255 | for my $param (@param) {
|
---|
| 256 | push @ptr,$config->get($param);
|
---|
| 257 | }
|
---|
[89] | 258 | print "DEBUG: params: ".Dumper(@param)." ".Dumper(@ptr)."\n" if ($debug >= 1);
|
---|
| 259 | return(@ptr);
|
---|
[74] | 260 | }
|
---|
| 261 |
|
---|
| 262 | # Setup environment for CMS system
|
---|
| 263 | sub pb_cms_init {
|
---|
| 264 |
|
---|
| 265 | my $proj = shift || undef;
|
---|
| 266 | my $ret;
|
---|
| 267 |
|
---|
[89] | 268 | my ($cms) = pb_conf_get("cms");
|
---|
[88] | 269 | # This one is optional
|
---|
[89] | 270 | my ($cvsroot) = pb_conf_read($ENV{'PBETC'},"cvsroot");
|
---|
[74] | 271 |
|
---|
[88] | 272 | if ($cms->{$proj} eq "svn") {
|
---|
[74] | 273 | $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
|
---|
| 274 | chomp($ENV{'PBREVISION'});
|
---|
| 275 | $ENV{'PBCMSLOG'}="svn log";
|
---|
| 276 | $ENV{'PBCMSLOGFILE'}="svn.log";
|
---|
[88] | 277 | } elsif ($cms->{$proj} eq "cvs") {
|
---|
[106] | 278 | # Way too slow
|
---|
| 279 | #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
|
---|
| 280 | #chomp($ENV{'PBREVISION'});
|
---|
| 281 | $ENV{'PBREVISION'}="CVS";
|
---|
[74] | 282 | $ENV{'PBCMSLOG'}="cvs log";
|
---|
| 283 | $ENV{'PBCMSLOGFILE'}="cvs.log";
|
---|
[87] | 284 | #
|
---|
| 285 | # Export content if needed
|
---|
| 286 | #
|
---|
[88] | 287 | $ENV{'CVSROOT'} = $cvsroot->{$proj} if (defined $cvsroot->{$proj});
|
---|
[74] | 288 | } else {
|
---|
[88] | 289 | die "cms $cms->{$proj} unknown";
|
---|
[74] | 290 | }
|
---|
[106] | 291 | return($cms);
|
---|
[74] | 292 | }
|
---|
| 293 |
|
---|
[106] | 294 | sub pb_cms_export {
|
---|
| 295 | my $cms = shift;
|
---|
| 296 | my $pbdate = shift || undef;
|
---|
| 297 | my $pkgdir = shift;
|
---|
| 298 | my $destdir = shift;
|
---|
| 299 |
|
---|
| 300 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
| 301 | pb_system("svn export $pkgdir $destdir","Exporting $pkgdir from SVN");
|
---|
| 302 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 303 | my $dir=dirname($destdir);
|
---|
| 304 | my $base=basename($destdir);
|
---|
| 305 | my $tmp=basename($pkgdir);
|
---|
| 306 | # CVS needs a relative path !
|
---|
| 307 | pb_system("cd $dir ; cvs export -D $pbdate -d $base $tmp","Exporting $pkgdir from CVS");
|
---|
| 308 | } else {
|
---|
| 309 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | sub pb_cms_log {
|
---|
| 314 | my $cms = shift;
|
---|
| 315 | my $pkgdir = shift;
|
---|
| 316 | my $destfile = shift;
|
---|
| 317 |
|
---|
| 318 | if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
|
---|
| 319 | pb_system("svn log $pkgdir > $destfile","Extracting log info from SVN");
|
---|
| 320 | } elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
|
---|
| 321 | my $tmp=basename($pkgdir);
|
---|
| 322 | # CVS needs a relative path !
|
---|
| 323 | pb_system("cvs log $tmp > $destfile","Extracting log info from CVS");
|
---|
| 324 | } else {
|
---|
| 325 | die "cms $cms->{$ENV{'PBPROJ'}} unknown";
|
---|
| 326 | }
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 |
|
---|
[77] | 331 | # Get all filters to apply
|
---|
| 332 | # They're cumulative from less specific to most specific
|
---|
| 333 | # suffix is .pbf
|
---|
| 334 |
|
---|
| 335 | sub pb_get_filters {
|
---|
| 336 |
|
---|
| 337 | my @ffiles;
|
---|
| 338 | my ($ffile0, $ffile1, $ffile2, $ffile3);
|
---|
| 339 | my $pbpkg = shift || die "No package specified";
|
---|
| 340 | my $dtype = shift || die "No dtype specified";
|
---|
| 341 | my $dfam = shift || die "No dfam specified";
|
---|
| 342 | my $ddir = shift || die "No ddir specified";
|
---|
| 343 | my $dver = shift || die "No dver specified";
|
---|
| 344 | my $ptr; # returned value pointer on the hash of filters
|
---|
[79] | 345 | my %ptr;
|
---|
[77] | 346 |
|
---|
| 347 | if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
|
---|
| 348 | $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
|
---|
| 349 | $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
|
---|
| 350 | $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
|
---|
| 351 | $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
|
---|
| 352 |
|
---|
| 353 | push @ffiles,$ffile0 if (defined $ffile0);
|
---|
| 354 | push @ffiles,$ffile1 if (defined $ffile1);
|
---|
| 355 | push @ffiles,$ffile2 if (defined $ffile2);
|
---|
| 356 | push @ffiles,$ffile3 if (defined $ffile3);
|
---|
| 357 | }
|
---|
| 358 | if (@ffiles) {
|
---|
| 359 | print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
|
---|
[79] | 360 |
|
---|
| 361 | my $config = AppConfig->new({
|
---|
| 362 | # Auto Create variables mentioned in Conf file
|
---|
| 363 | CREATE => 1,
|
---|
| 364 | DEBUG => 0,
|
---|
| 365 | GLOBAL => {
|
---|
| 366 | # Each conf item is a hash
|
---|
| 367 | ARGCOUNT => AppConfig::ARGCOUNT_HASH
|
---|
| 368 | }
|
---|
| 369 | });
|
---|
| 370 |
|
---|
[77] | 371 | $config->file(@ffiles);
|
---|
| 372 | $ptr = $config->get("filter");
|
---|
| 373 | print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
|
---|
| 374 | } else {
|
---|
| 375 | $ptr = { };
|
---|
| 376 | }
|
---|
[79] | 377 | %ptr = %$ptr;
|
---|
| 378 | return(\%ptr);
|
---|
[77] | 379 | }
|
---|
| 380 |
|
---|
| 381 | # Function which applies filter on files (only for pb)
|
---|
| 382 | sub pb_filter_file_pb {
|
---|
| 383 |
|
---|
| 384 | my $f=shift;
|
---|
| 385 | my $ptr=shift;
|
---|
| 386 | my %filter=%$ptr;
|
---|
| 387 | my $destfile=shift;
|
---|
| 388 | my $dtype=shift;
|
---|
[99] | 389 | my $pbsuf=shift;
|
---|
[80] | 390 | my $pbpkg=shift;
|
---|
| 391 | my $pbver=shift;
|
---|
| 392 | my $pbtag=shift;
|
---|
| 393 | my $pbrev=shift;
|
---|
| 394 | my $pbdate=shift;
|
---|
[77] | 395 |
|
---|
| 396 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
| 397 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 398 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 399 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 400 | while (<FILE>) {
|
---|
| 401 | my $line = $_;
|
---|
| 402 | foreach my $s (keys %filter) {
|
---|
| 403 | # Process single variables
|
---|
[79] | 404 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug >= 1);
|
---|
[77] | 405 | my $tmp = $filter{$s};
|
---|
| 406 | next if (not defined $tmp);
|
---|
| 407 | # Expand variables if any single one found
|
---|
[79] | 408 | print $LOG "DEBUG tmp: $tmp\n" if ($debug >= 1);
|
---|
[77] | 409 | if ($tmp =~ /\$/) {
|
---|
| 410 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 411 | # special case for ChangeLog only for pb
|
---|
| 412 | } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
|
---|
| 413 | $tmp = "";
|
---|
[82] | 414 | my $p = $defpkgdir{$pbpkg};
|
---|
| 415 | $p = $extpkgdir{$pbpkg} if (not defined $p);
|
---|
[99] | 416 | pb_changelog($dtype, $pbpkg, $pbtag, $pbsuf, $p, \*DEST);
|
---|
[77] | 417 | }
|
---|
| 418 | $line =~ s|$s|$tmp|;
|
---|
| 419 | }
|
---|
| 420 | print DEST $line;
|
---|
| 421 | }
|
---|
| 422 | close(FILE);
|
---|
| 423 | close(DEST);
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | # Function which applies filter on files (external call)
|
---|
| 427 | sub pb_filter_file {
|
---|
| 428 |
|
---|
| 429 | my $f=shift;
|
---|
| 430 | my $ptr=shift;
|
---|
| 431 | my %filter=%$ptr;
|
---|
| 432 | my $destfile=shift;
|
---|
[99] | 433 | my $pbsuf=shift;
|
---|
[80] | 434 | my $pbpkg=shift;
|
---|
| 435 | my $pbver=shift;
|
---|
| 436 | my $pbtag=shift;
|
---|
| 437 | my $pbrev=shift;
|
---|
| 438 | my $pbdate=shift;
|
---|
[77] | 439 |
|
---|
| 440 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
| 441 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 442 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 443 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 444 | while (<FILE>) {
|
---|
| 445 | my $line = $_;
|
---|
| 446 | foreach my $s (keys %filter) {
|
---|
| 447 | # Process single variables
|
---|
| 448 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
|
---|
| 449 | my $tmp = $filter{$s};
|
---|
| 450 | next if (not defined $tmp);
|
---|
| 451 | # Expand variables if any single one found
|
---|
| 452 | if ($tmp =~ /\$/) {
|
---|
| 453 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 454 | }
|
---|
| 455 | $line =~ s|$s|$tmp|;
|
---|
| 456 | }
|
---|
| 457 | print DEST $line;
|
---|
| 458 | }
|
---|
| 459 | close(FILE);
|
---|
| 460 | close(DEST);
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 |
|
---|
[2] | 464 | 1;
|
---|