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