Changeset 77 in ProjectBuilder for devel/pb/lib/ProjectBuilder/Base.pm
- Timestamp:
- Sep 3, 2007, 3:34:11 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/lib/ProjectBuilder/Base.pm
r74 r77 62 62 my $pbroot = pb_conf_read($pbrc{$proj},"pbroot"); 63 63 my %pbroot = %$pbroot; 64 # There is normaly only one line in it64 # All lines should point to the same pbroot so take the first 65 65 $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot); 66 66 print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'})); … … 300 300 } 301 301 302 # Get all filters to apply 303 # They're cumulative from less specific to most specific 304 # suffix is .pbf 305 306 sub pb_get_filters { 307 308 my @ffiles; 309 my ($ffile0, $ffile1, $ffile2, $ffile3); 310 my $pbpkg = shift || die "No package specified"; 311 my $dtype = shift || die "No dtype specified"; 312 my $dfam = shift || die "No dfam specified"; 313 my $ddir = shift || die "No ddir specified"; 314 my $dver = shift || die "No dver specified"; 315 my $ptr; # returned value pointer on the hash of filters 316 317 if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") { 318 $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf"); 319 $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf"); 320 $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf"); 321 $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf"); 322 323 push @ffiles,$ffile0 if (defined $ffile0); 324 push @ffiles,$ffile1 if (defined $ffile1); 325 push @ffiles,$ffile2 if (defined $ffile2); 326 push @ffiles,$ffile3 if (defined $ffile3); 327 } 328 my $config = AppConfig->new({ 329 # Auto Create variables mentioned in Conf file 330 CREATE => 1, 331 DEBUG => 0, 332 GLOBAL => { 333 # Each conf item is a hash 334 ARGCOUNT => AppConfig::ARGCOUNT_HASH 335 } 336 }); 337 338 if (@ffiles) { 339 print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1); 340 $config->file(@ffiles); 341 $ptr = $config->get("filter"); 342 print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1); 343 } else { 344 $ptr = { }; 345 } 346 return($ptr); 347 } 348 349 # Function which applies filter on files (only for pb) 350 sub pb_filter_file_pb { 351 352 my $f=shift; 353 my $ptr=shift; 354 my %filter=%$ptr; 355 my $destfile=shift; 356 my $pbpkg=shift; 357 my $dtype=shift; 358 my $dsuf=shift; 359 360 print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1); 361 pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile)); 362 open(DEST,"> $destfile") || die "Unable to create $destfile"; 363 open(FILE,"$f") || die "Unable to open $f: $!"; 364 while (<FILE>) { 365 my $line = $_; 366 foreach my $s (keys %filter) { 367 # Process single variables 368 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1); 369 my $tmp = $filter{$s}; 370 next if (not defined $tmp); 371 # Expand variables if any single one found 372 if ($tmp =~ /\$/) { 373 eval { $tmp =~ s/(\$\w+)/$1/eeg }; 374 # special case for ChangeLog only for pb 375 } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) { 376 $tmp = ""; 377 my $p = $defpkgdir{$pbpkg}; 378 $p = $extpkgdir{$pbpkg} if (not defined $p); 379 pb_changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST); 380 } 381 $line =~ s|$s|$tmp|; 382 } 383 print DEST $line; 384 } 385 close(FILE); 386 close(DEST); 387 } 388 389 # Function which applies filter on files (external call) 390 sub pb_filter_file { 391 392 my $f=shift; 393 my $ptr=shift; 394 my %filter=%$ptr; 395 my $destfile=shift; 396 397 print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1); 398 pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile)); 399 open(DEST,"> $destfile") || die "Unable to create $destfile"; 400 open(FILE,"$f") || die "Unable to open $f: $!"; 401 while (<FILE>) { 402 my $line = $_; 403 foreach my $s (keys %filter) { 404 # Process single variables 405 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1); 406 my $tmp = $filter{$s}; 407 next if (not defined $tmp); 408 # Expand variables if any single one found 409 if ($tmp =~ /\$/) { 410 eval { $tmp =~ s/(\$\w+)/$1/eeg }; 411 } 412 $line =~ s|$s|$tmp|; 413 } 414 print DEST $line; 415 } 416 close(FILE); 417 close(DEST); 418 } 419 420 302 421 1;
Note:
See TracChangeset
for help on using the changeset viewer.