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