Changeset 22 in ProjectBuilder for devel/pb/bin
- Timestamp:
- Jul 31, 2007, 1:11:01 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb.pl
r21 r22 8 8 # Provided under the GPL v2 9 9 10 # Syntax: pb [-p project] <action> [<params>...]10 # Syntax: see at end 11 11 12 12 use strict 'vars'; 13 use Switch;14 13 use Getopt::Std; 15 14 use Data::Dumper; … … 17 16 use AppConfig qw(:argcount :expand); 18 17 use File::Basename; 19 use Archive::Tar;20 18 use Time::localtime qw(localtime); 21 19 use POSIX qw(strftime); 22 20 23 use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles $debug );21 use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles $debug $LOG); 24 22 %extpkgdir = (); 25 23 %filteredfiles = (); 26 24 $debug = 0; # Debug level 25 $LOG = *STDOUT; # Where to log 27 26 use lib qw (lib); 28 27 use common qw (env_init); … … 43 42 my $pbdate = strftime("%Y-%m-%d", @date); 44 43 45 getopts('h p:qtv',\%opts);44 getopts('hl:p:qtv',\%opts); 46 45 47 46 if (defined $opts{'h'}) { … … 55 54 $debug=-1; 56 55 } 56 if (defined $opts{'l'}) { 57 open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!"; 58 $LOG = *LOG; 59 $debug = 0 if ($debug == -1); 60 } 57 61 # Handles project name if any 58 62 if (defined $opts{'p'}) { … … 72 76 die syntax() if (not defined $action); 73 77 74 print "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);75 print "Action: $action\n" if ($debug >= 0);78 print $LOG "Project $ENV{'PBPROJ'}\n" if ($debug >= 0); 79 print $LOG "Action: $action\n" if ($debug >= 0); 76 80 77 81 # Act depending on action 78 82 if ($action =~ /^cms2build$/) { 79 # Get packages list 80 if (not defined $ARGV[0]) { 81 @pkgs = keys %defpkgdir; 82 } elsif ($ARGV[0] =~ /^all$/) { 83 @pkgs = keys %defpkgdir; 84 if (defined %extpkgdir) { 85 my $k = keys %extpkgdir; 86 if (defined $k) { 87 push(@pkgs, keys %extpkgdir); 88 } 89 } 90 } else { 91 @pkgs = @ARGV; 92 } 93 print "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0); 83 my $ptr = get_pkg(); 84 @pkgs = @$ptr; 94 85 cms_init(); 95 86 96 87 foreach my $pkg (@pkgs) { 97 98 88 if (-f "$ENV{'PBROOT'}/$pkg/VERSION") { 99 89 open(V,"$ENV{'PBROOT'}/$pkg/VERSION") || die "Unable to open $ENV{'PBROOT'}/$pkg/VERSION"; … … 114 104 } 115 105 $pbrev = $ENV{'PBREVISION'}; 116 print "\n" if ($debug >= 0);117 print "Management of $pkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);106 print $LOG "\n" if ($debug >= 0); 107 print $LOG "Management of $pkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0); 118 108 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'}); 119 109 # Clean up dest if necessary. The export will recreate it … … 124 114 # And generate some additional files 125 115 $OUTPUT_AUTOFLUSH=1; 126 print "$ENV{'PBCMSEXP'} of $pkg..." if ($debug >= 0);116 print $LOG "$ENV{'PBCMSEXP'} of $pkg..." if ($debug >= 0); 127 117 # computes in which dir we have to work 128 118 my $dir = $defpkgdir{$pkg}; … … 130 120 system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null"); 131 121 if ($? == -1) { 132 print "failed to execute: $!\n" if ($debug >= 0);122 print $LOG "failed to execute: $!\n" if ($debug >= 0); 133 123 } elsif ($? & 127) { 134 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);135 } else { 136 print " OK\n" if ($debug >= 0);124 printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0); 125 } else { 126 print $LOG " OK\n" if ($debug >= 0); 137 127 } 138 128 … … 144 134 # Extract cms log history and store it 145 135 system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}"); 146 print "$ENV{'PBCMSLOG'} of $pkg..." if ($debug >= 0);136 print $LOG "$ENV{'PBCMSLOG'} of $pkg..." if ($debug >= 0); 147 137 if ($? == -1) { 148 print "failed to execute: $!\n" if ($debug >= 0);138 print $LOG "failed to execute: $!\n" if ($debug >= 0); 149 139 } elsif ($? & 127) { 150 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);151 } else { 152 print " OK\n" if ($debug >= 0);140 printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0); 141 } else { 142 print $LOG " OK\n" if ($debug >= 0); 153 143 } 154 144 my %build; … … 159 149 chomp($ver); 160 150 my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver); 161 print "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1);162 print "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);151 print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1); 152 print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1); 163 153 164 154 # Filter build files from the less precise up to the most with overloading … … 167 157 # Find all build files first relatively to PBROOT 168 158 my %bfiles; 169 print "DEBUG dir: $ENV{'PBCONF'}/$pkg\n" if ($debug >= 1);159 print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pkg\n" if ($debug >= 1); 170 160 $build{"$ddir-$dver"} = "yes"; 171 161 if (-d "$ENV{'PBCONF'}/$pkg/$dtype") { … … 205 195 next; 206 196 } 207 print "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);197 print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1); 208 198 209 199 # Get all filters to apply … … 233 223 my $ptr; 234 224 if (@ffiles) { 235 print "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);225 print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1); 236 226 $config->file(@ffiles); 237 227 $ptr = $config->get("filter"); 238 print "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);228 print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1); 239 229 } else { 240 230 $ptr = { }; … … 260 250 push @notfound,$b if ($build{$b} =~ /no/); 261 251 } 262 print "Build files generated for ".join(',',@found)."\n";263 print "No Build files found for ".join(',',@notfound)."\n";252 print $LOG "Build files generated for ".join(',',@found)."\n"; 253 print $LOG "No Build files found for ".join(',',@notfound)."\n"; 264 254 } 265 255 close(D); 266 256 # Prepare the dest directory for archive 267 257 if (-x "$ENV{'PBCONF'}/$pkg/pbpkginit") { 258 print $LOG " Executing $ENV{'PBCONF'}/$pkg/pbinit...\n" if ($debug >= 0); 268 259 system("cd $dest ; $ENV{'PBCONF'}/$pkg/pbinit"); 269 260 if ($? == -1) { 270 print "failed to execute: $!\n" if ($debug >= 0);261 print $LOG "failed to execute: $!\n" if ($debug >= 0); 271 262 } elsif ($? & 127) { 272 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);263 printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0); 273 264 } else { 274 print " $dest\n" if ($debug >= 0);265 print $LOG " OK\n" if ($debug >= 0); 275 266 } 276 267 } 277 268 # Archive dest dir 278 chdir "$ dest/..";279 print "Creating $pkg tar files (gzip... " if ($debug >= 0);269 chdir "$ENV{'PBDESTDIR'}"; 270 print $LOG "Creating $pkg tar files (gzip... " if ($debug >= 0); 280 271 system("tar cfphz $pkg-$pbver.tar.gz $pkg-$pbver"); 281 272 if ($? == -1) { 282 print "failed to execute: $!\n" if ($debug >= 0);273 print $LOG "failed to execute: $!\n" if ($debug >= 0); 283 274 } elsif ($? & 127) { 284 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0); 285 } else { 286 print " OK)\n" if ($debug >= 0); 287 print "Under $dest/../$pkg-$pbver.tar.gz\n" if ($debug >= 0); 288 } 275 printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0); 276 } else { 277 print $LOG " OK)\n" if ($debug >= 0); 278 print $LOG "Under $ENV{'PBDESTDIR'}/$pkg-$pbver.tar.gz\n" if ($debug >= 0); 279 # Keep track of what is generated for build2pkg default 280 open(LAST,"> $ENV{'PBDESTDIR'}/LAST") || die "Unable to create $ENV{'PBDESTDIR'}/LAST"; 281 print LAST "$pbver-$pbtag\n"; 282 close(LAST); 283 } 284 } 285 } elsif ($action =~ /^build2pkg$/) { 286 # Check whether we have a specific version to build 287 my $vertag = shift @ARGV; 288 if (not defined $vertag) { 289 open(LAST,"$ENV{'PBDESTDIR'}/LAST") || die "Unable to open $ENV{'PBDESTDIR'}/LAST\nYou may want to precise as parameter version-tag"; 290 $vertag = <LAST>; 291 chomp($vertag); 292 close(LAST); 293 } 294 ($pbver,$pbtag) = split(/-/,$vertag); 295 296 # Get list of packages to build 297 my $ptr = get_pkg(); 298 @pkgs = @$ptr; 299 300 # Get the running distro to build on 301 302 foreach my $pkg (@pkgs) { 289 303 } 290 304 } else { 291 print "'$action' is not available\n";305 print $LOG "'$action' is not available\n"; 292 306 syntax(); 293 307 } … … 304 318 my $dsuf=shift; 305 319 306 print "DEBUG: From $f to $destfile\n" if ($debug >= 1);320 print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1); 307 321 pbmkdir_p(dirname($destfile)) if (! -d dirname($destfile)); 308 322 open(DEST,"> $destfile") || die "Unable to create $destfile"; … … 312 326 foreach my $s (keys %filter) { 313 327 # Process single variables 314 print "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);328 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1); 315 329 my $tmp = $filter{$s}; 316 330 next if (not defined $tmp); … … 333 347 } 334 348 349 sub get_pkg { 350 351 my @pkgs; 352 353 # Get packages list 354 if (not defined $ARGV[0]) { 355 @pkgs = keys %defpkgdir; 356 } elsif ($ARGV[0] =~ /^all$/) { 357 @pkgs = keys %defpkgdir; 358 if (defined %extpkgdir) { 359 my $k = keys %extpkgdir; 360 if (defined $k) { 361 push(@pkgs, keys %extpkgdir); 362 } 363 } 364 } else { 365 @pkgs = @ARGV; 366 } 367 print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0); 368 return(\@pkgs); 369 } 370 335 371 sub syntax { 336 372 … … 349 385 print "\tcms2build: Create a tar file of the project under your CMS\n"; 350 386 print "\t CMS supported are SVN and CVS\n"; 387 print "\t parameters are packages to build\n"; 388 print "\t if not using default list\n"; 351 389 print "\n"; 352 390 print "\tbuild2pkg: Create packages for your running distribution \n"; 353 print "\n"; 354 print "\n"; 355 } 391 print "\t first parameter is version-tag to build\n"; 392 print "\t if not using default version-tag\n"; 393 print "\t following parameters are packages to build\n"; 394 print "\t if not using default list\n"; 395 print "\n"; 396 print "\n"; 397 }
Note:
See TracChangeset
for help on using the changeset viewer.