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