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