Changeset 77 in ProjectBuilder
- Timestamp:
- Sep 3, 2007, 3:34:11 AM (17 years ago)
- Location:
- devel/pb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb
r75 r77 29 29 use ProjectBuilder::Changelog qw (pb_changelog); 30 30 use ProjectBuilder::Version qw (pb_version_init); 31 use ProjectBuilder::Base qw (pb_conf_read pb_cms_init pb_mkdir_p pb_system pb_rm_rf );31 use ProjectBuilder::Base qw (pb_conf_read pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb); 32 32 33 33 my %opts; # CLI Options … … 38 38 my $pbtag; # Global TAG variable 39 39 my $pbver; # Global VERSION variable 40 my %pbver; # per package 41 my %pbtag; # per package 40 42 my $pbrev; # Global REVISION variable 41 43 my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst()); … … 87 89 # Act depending on action 88 90 if ($action =~ /^cms2build$/) { 89 my $ptr = get_pkg(); 91 pb_cms2build(); 92 } elsif ($action =~ /^build2pkg$/) { 93 pb_build2pkg(); 94 } elsif ($action =~ /^cms2pkg$/) { 95 pb_cms2build(); 96 pb_build2pkg(); 97 } else { 98 print $LOG "'$action' is not available\n"; 99 pb_syntax(); 100 } 101 102 sub pb_cms2build { 103 104 my $ptr = pb_get_pkg(); 90 105 @pkgs = @$ptr; 91 106 pb_cms_init($ENV{'PBPROJ'}); … … 190 205 191 206 # Get all filters to apply 192 # They're cumulative from less specific to most specific 193 # suffix is .pbf 194 my @ffiles; 195 my ($ffile0, $ffile1, $ffile2, $ffile3); 196 if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") { 197 $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf"); 198 $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf"); 199 $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf"); 200 $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf"); 201 push @ffiles,$ffile0 if (defined $ffile0); 202 push @ffiles,$ffile1 if (defined $ffile1); 203 push @ffiles,$ffile2 if (defined $ffile2); 204 push @ffiles,$ffile3 if (defined $ffile3); 205 } 206 my $config = AppConfig->new({ 207 # Auto Create variables mentioned in Conf file 208 CREATE => 1, 209 DEBUG => 0, 210 GLOBAL => { 211 # Each conf item is a hash 212 ARGCOUNT => AppConfig::ARGCOUNT_HASH 213 } 214 }); 215 my $ptr; 216 if (@ffiles) { 217 print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1); 218 $config->file(@ffiles); 219 $ptr = $config->get("filter"); 220 print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1); 221 } else { 222 $ptr = { }; 223 } 207 my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver); 224 208 225 209 # Apply now all the filters on all the files concerned … … 227 211 if (defined $ptr) { 228 212 foreach my $f (values %bfiles) { 229 filter_file("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$pbpkg,$dtype,$dsuf);213 pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$pbpkg,$dtype,$dsuf); 230 214 } 231 215 if (defined $filteredfiles{$dir}) { 232 216 foreach my $f (split(/,/,$filteredfiles{$dir})) { 233 filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$pbpkg,$dtype,$dsuf);217 pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f"); 234 218 } 235 219 } … … 258 242 print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0); 259 243 # Keep track of what is generated for default 260 open(LAST,"> $pbrc{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc{$ENV{'PBPROJ'}}"; 261 print LAST "pbroot $pbver-$pbtag = $ENV{'PBROOT'}\n"; 262 close(LAST); 244 $pbver{$pbpkg} = $pbver; 245 $pbtag{$pbpkg} = $pbtag; 263 246 } 264 } elsif ($action =~ /^build2pkg$/) { 247 open(LAST,"> $pbrc{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc{$ENV{'PBPROJ'}}"; 248 foreach my $v (keys %pbver) { 249 print LAST "pbroot $v-_-$pbver{v}-$pbtag{v} = $ENV{'PBROOT'}\n"; 250 } 251 close(LAST); 252 } 253 254 sub pb_build2pkg { 255 256 # Get list of packages to build 257 my $ptr = pb_get_pkg(); 258 @pkgs = @$ptr; 259 265 260 # Check whether we have a specific version to build 266 261 my $vertag = shift @ARGV; 267 if (not defined $vertag) {268 if (-f $pbrc{$ENV{'PBPROJ'}}) {269 my $pbroot = pb_conf_read($pbrc{$ENV{'PBPROJ'}},"pbroot");270 # There is only one line normaly271 $vertag = (keys %$pbroot)[0];272 $ENV{'PBROOT'} = (values %$pbroot)[0];273 } else {274 die "Unable to open $pbrc{$ENV{'PBPROJ'}}\nYou may want to precise as parameter version-tag";275 }276 }277 ($pbver,$pbtag) = split(/-/,$vertag);278 279 # Get list of packages to build280 my $ptr = get_pkg();281 @pkgs = @$ptr;282 262 283 263 # Get the running distro to build on … … 287 267 chdir "$ENV{'PBBUILDDIR'}"; 288 268 foreach my $pbpkg (@pkgs) { 269 # get the version of the current package - maybe different 270 if (not defined $vertag) { 271 if (-f $pbrc{$ENV{'PBPROJ'}}) { 272 my $pbroot = pb_conf_read($pbrc{$ENV{'PBPROJ'}},"pbroot"); 273 # All lines should point to the same pbroot so take the first 274 $ENV{'PBROOT'} = (values %$pbroot)[0]; 275 foreach my $k (keys %$pbroot) { 276 if ($k =~ /^$pbpkg-_-/) { 277 ($ptr,$vertag) = split(/-_-/,$k); 278 last; 279 } 280 } 281 die "Unable to find $pbpkg in $pbrc{$ENV{'PBPROJ'}}\nYou may want to precise as parameter version-tag" if (not defined $vertag); 282 } else { 283 die "Unable to open $pbrc{$ENV{'PBPROJ'}}\nYou may want to precise as parameter version-tag"; 284 } 285 } 286 ($pbver,$pbtag) = split(/-/,$vertag); 287 289 288 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz"; 290 289 print $LOG "Source file: $src\n" if ($debug >= 0); … … 305 304 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES"; 306 305 my @specfile; 307 @specfile = extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");306 @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS"); 308 307 309 308 print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1); … … 324 323 } 325 324 } 326 } else { 327 print $LOG "'$action' is not available\n"; 328 pb_syntax(); 329 } 330 331 # Function which applies filter on files 332 sub filter_file { 333 334 my $f=shift; 335 my $ptr=shift; 336 my %filter=%$ptr; 337 my $destfile=shift; 338 my $pbpkg=shift; 339 my $dtype=shift; 340 my $dsuf=shift; 341 342 print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1); 343 pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile)); 344 open(DEST,"> $destfile") || die "Unable to create $destfile"; 345 open(FILE,"$f") || die "Unable to open $f: $!"; 346 while (<FILE>) { 347 my $line = $_; 348 foreach my $s (keys %filter) { 349 # Process single variables 350 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1); 351 my $tmp = $filter{$s}; 352 next if (not defined $tmp); 353 # Expand variables if any single one found 354 if ($tmp =~ /\$/) { 355 eval { $tmp =~ s/(\$\w+)/$1/eeg }; 356 # special case for ChangeLog 357 } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) { 358 my $p = $defpkgdir{$pbpkg}; 359 $p = $extpkgdir{$pbpkg} if (not defined $p); 360 pb_changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST); 361 $tmp = ""; 362 } 363 $line =~ s|$s|$tmp|; 364 } 365 print DEST $line; 366 } 367 close(FILE); 368 close(DEST); 369 } 370 371 sub get_pkg { 325 } 326 327 sub pb_get_pkg { 372 328 373 329 my @pkgs; … … 391 347 } 392 348 393 sub extract_build_files {349 sub pb_extract_build_files { 394 350 395 351 my $src=shift; … … 442 398 print "\t if not using default list\n"; 443 399 print "\n"; 444 print "\n"; 445 } 400 print "\tcms2pkg: cms2build + build2pkg\n"; 401 print "\n"; 402 } -
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.