source: ProjectBuilder/devel/pb/bin/pb@ 310

Last change on this file since 310 was 310, checked in by Bruno Cornec, 16 years ago
  • Fixes for CVS support: remove CVSROOT
  • prepare chroot support
  • fix for debian build in case a debian dir/link already exists in the project
  • only call qemu tools if using qemu as a VM :-)
  • Property svn:executable set to *
File size: 35.8 KB
RevLine 
[5]1#!/usr/bin/perl -w
2#
3# Project Builder main application
4#
5# $Id$
6#
7# Copyright B. Cornec 2007
8# Provided under the GPL v2
9
[22]10# Syntax: see at end
[9]11
[18]12use strict 'vars';
[5]13use Getopt::Std;
[9]14use Data::Dumper;
15use English;
[16]16use File::Basename;
[26]17use File::Copy;
[13]18use Time::localtime qw(localtime);
19use POSIX qw(strftime);
[5]20
[73]21# Global variables
[17]22use lib qw (lib);
[74]23use ProjectBuilder::Distribution qw (pb_distro_init);
24use ProjectBuilder::Version qw (pb_version_init);
[204]25use ProjectBuilder::Base qw (pb_conf_read pb_conf_get pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout);
[5]26
27my %opts; # CLI Options
[9]28my $action; # action to realize
29my $test = "FALSE";
30my $option = "";
31my @pkgs;
[95]32my $pbtag; # Global Tag variable
33my $pbver; # Global Version variable
[141]34my $pbscript; # Name of the script
[77]35my %pbver; # per package
36my %pbtag; # per package
[53]37my $pbrev; # Global REVISION variable
[16]38my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
39my $pbdate = strftime("%Y-%m-%d", @date);
[112]40my $pbdatecvs = strftime("%Y-%m-%d %H:%M:%S", @date);
[108]41my $debug = 0;
[152]42my $pbaccount; # Login to use to connect to the VM
[162]43my $pbport; # Port to use to connect to the VM
[199]44my $newver; # New version to create
[262]45my $iso; # ISO iage for the VM to create
[108]46my $LOG = \*STDOUT;
[5]47
[262]48getopts('a:hi:l:m:P:p:qr:s:tvV:',\%opts);
[5]49
[75]50my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
[21]51if (defined $opts{'h'}) {
[74]52 pb_syntax();
[21]53 exit(0);
54}
55if (defined $opts{'v'}) {
56 $debug++;
57}
58if (defined $opts{'q'}) {
59 $debug=-1;
60}
[22]61if (defined $opts{'l'}) {
62 open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
63 $LOG = *LOG;
64 $debug = 0 if ($debug == -1);
65 }
[9]66# Handles test option
67if (defined $opts{'t'}) {
68 $test = "TRUE";
69 # Works only for SVN
70 $option = "-r BASE";
71}
[5]72
[67]73# Handle root of the project if defined
74if (defined $opts{'r'}) {
75 $ENV{'PBROOT'} = $opts{'r'};
76}
[91]77# Handle virtual machines if any
78if (defined $opts{'m'}) {
79 $ENV{'PBVM'} = $opts{'m'};
80}
[141]81if (defined $opts{'s'}) {
82 $pbscript = $opts{'s'};
83}
[152]84if (defined $opts{'a'}) {
85 $pbaccount = $opts{'a'};
86}
[162]87if (defined $opts{'P'}) {
88 $pbport = $opts{'P'};
89}
[199]90if (defined $opts{'V'}) {
91 $newver = $opts{'V'};
92}
[262]93if (defined $opts{'i'}) {
94 $iso = $opts{'i'};
95}
[108]96
97# Get Action
98$action = shift @ARGV;
99die pb_syntax() if (not defined $action);
100
[300]101my ($pbrc, $filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
[273]102my $pbinit = undef;
103$pbinit = 1 if ($action =~ /^newproj$/);
[108]104
[59]105# Handles project name if any
[108]106# And get global params
[59]107if (defined $opts{'p'}) {
[300]108 ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
[273]109 = pb_env_init($opts{'p'},$pbinit);
[59]110} else {
[300]111 ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
[273]112 = pb_env_init(undef,$pbinit);
[59]113}
114
[108]115print $LOG "Project: $ENV{'PBPROJ'}\n" if ($debug >= 0);
[22]116print $LOG "Action: $action\n" if ($debug >= 0);
[9]117
[91]118# Keep those project values to store them at the end each time
[83]119my $pbprojtag = $ENV{'PBTAG'};
120my $pbprojver = $ENV{'PBVER'};
121
[9]122# Act depending on action
123if ($action =~ /^cms2build$/) {
[77]124 pb_cms2build();
125} elsif ($action =~ /^build2pkg$/) {
126 pb_build2pkg();
127} elsif ($action =~ /^cms2pkg$/) {
128 pb_cms2build();
129 pb_build2pkg();
[88]130} elsif ($action =~ /^build2ssh$/) {
131 pb_build2ssh();
[220]132} elsif ($action =~ /^cms2ssh$/) {
133 pb_cms2build();
134 pb_build2ssh();
[88]135} elsif ($action =~ /^pkg2ssh$/) {
136 pb_pkg2ssh();
[91]137} elsif ($action =~ /^build2vm$/) {
138 pb_build2vm();
139} elsif ($action =~ /^cms2vm$/) {
140 pb_cms2build();
141 pb_build2vm();
[141]142} elsif ($action =~ /^launchvm$/) {
[262]143 pb_launchvm($ENV{'PBVM'},0);
[142]144} elsif ($action =~ /^script2vm$/) {
145 pb_script2vm($pbscript);
[199]146} elsif ($action =~ /^newver$/) {
147 pb_newver();
[310]148} elsif ($action =~ /^newchroot$/) {
149 pb_launchchroot($ENV{'PBCHROOT'},1);
[262]150} elsif ($action =~ /^newvm$/) {
151 pb_launchvm($ENV{'PBVM'},1);
[273]152} elsif ($action =~ /^newproj$/) {
153 # Nothing to do - already done in pb_env_init
[106]154} elsif ($action =~ /^clean$/) {
[77]155} else {
156 print $LOG "'$action' is not available\n";
157 pb_syntax();
158}
159
160sub pb_cms2build {
161
[112]162 my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
[22]163 @pkgs = @$ptr;
[112]164 my $cms=pb_cms_init($ENV{'PBPROJ'});
[9]165
[98]166 my ($pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb","pkgver","pkgtag");
[174]167
168 # declare packager for filtering
169 my ($tmp) = pb_conf_get("packager");
170 my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
171
[27]172 foreach my $pbpkg (@pkgs) {
[115]173 $ENV{'PBPKG'} = $pbpkg;
[274]174 $ENV{'PBVER'} = $pbprojver;
175 $ENV{'PBTAG'} = $pbprojtag;
[98]176 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
177 $pbver = $pkgv->{$pbpkg};
[115]178 $ENV{'PBVER'} = $pbver;
[9]179 } else {
[16]180 $pbver = $ENV{'PBVER'};
[9]181 }
[98]182 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
183 $pbtag = $pkgt->{$pbpkg};
[115]184 $ENV{'PBTAG'} = $pbtag;
[9]185 } else {
[16]186 $pbtag = $ENV{'PBTAG'};
[9]187 }
[95]188
[16]189 $pbrev = $ENV{'PBREVISION'};
[112]190 print $LOG "\n";
191 print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n";
[9]192 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
[16]193 # Clean up dest if necessary. The export will recreate it
[27]194 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
[74]195 pb_rm_rf($dest) if (-d $dest);
[9]196
197 # Export CMS tree for the concerned package to dest
198 # And generate some additional files
199 $OUTPUT_AUTOFLUSH=1;
[29]200
[9]201 # computes in which dir we have to work
[113]202 my $dir = $defpkgdir->{$pbpkg};
203 $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
[114]204 print "def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n" if ($debug >= 1);
[112]205 pb_cms_export($cms,$pbdatecvs,"$ENV{'PBROOT'}/$dir",$dest);
[9]206
[285]207 # Get project info on authors and log file
208 my $chglog = "$ENV{'PBCONF'}/$pbpkg/pbcl";
209 $chglog = "$ENV{'PBCONF'}/pbcl" if (! -f $chglog);
210 $chglog = undef if (! -f $chglog);
211
212 my $authors = "$ENV{'PBCONF'}/$pbpkg/pbauthors";
213 $authors = "$ENV{'PBCONF'}/pbauthors" if (! -f $authors);
214 $authors = "/dev/null" if (! -f $authors);
215
[9]216 # Extract cms log history and store it
[285]217 if ((defined $chglog) && (! -f "$dest/NEWS")) {
218 print $LOG "Generating NEWS file from $chglog\n";
219 copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
220 }
221 pb_cms_log($cms,"$ENV{'PBROOT'}/$dir",$dest,$chglog,$authors);
[29]222
[21]223 my %build;
[91]224
225 my ($ptr) = pb_conf_get("vmlist");
226 foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) {
227 my ($name,$ver) = split(/_/,$d);
[11]228 chomp($ver);
[99]229 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
230 print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n" if ($debug >= 1);
[22]231 print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
[13]232
[16]233 # Filter build files from the less precise up to the most with overloading
[13]234 # Filter all files found, keeping the name, and generating in dest
[16]235
236 # Find all build files first relatively to PBROOT
[300]237 # Find also all specific files referenced in the .pb conf file
[16]238 my %bfiles;
[300]239 my %pkgfiles;
[27]240 print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1);
[21]241 $build{"$ddir-$dver"} = "yes";
[27]242 if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") {
243 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!";
[16]244 foreach my $f (readdir(BDIR)) {
245 next if ($f =~ /^\./);
[27]246 $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f";
[16]247 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
[300]248 if (defined $supfiles->{$pbpkg}) {
249 $pkgfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f" if ($f =~ /$supfiles->{$pbpkg}/);
250 }
[16]251 }
[13]252 closedir(BDIR);
[27]253 } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") {
254 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!";
[16]255 foreach my $f (readdir(BDIR)) {
256 next if ($f =~ /^\./);
[27]257 $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f";
[16]258 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
[300]259 if (defined $supfiles->{$pbpkg}) {
260 $pkgfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f" if ($f =~ /$supfiles->{$pbpkg}/);
261 }
[16]262 }
263 closedir(BDIR);
[27]264 } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") {
265 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!";
[16]266 foreach my $f (readdir(BDIR)) {
267 next if ($f =~ /^\./);
[27]268 $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f";
[16]269 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
[300]270 if (defined $supfiles->{$pbpkg}) {
271 $pkgfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
272 }
[16]273 }
[13]274 closedir(BDIR);
[27]275 } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") {
276 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir-$dver: $!";
[16]277 foreach my $f (readdir(BDIR)) {
278 next if ($f =~ /^\./);
[27]279 $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f";
[16]280 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
[300]281 if (defined $supfiles->{$pbpkg}) {
282 $pkgfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f" if ($f =~ /$supfiles->{$pbpkg}/);
283 }
[16]284 }
[13]285 closedir(BDIR);
286 } else {
[21]287 $build{"$ddir-$dver"} = "no";
[13]288 next;
289 }
[22]290 print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
[13]291
[15]292 # Get all filters to apply
[77]293 my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
[15]294
[19]295 # Apply now all the filters on all the files concerned
296 # destination dir depends on the type of file
297 if (defined $ptr) {
[300]298 foreach my $f (values %bfiles,values %pkgfiles) {
[297]299 pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$defpkgdir,$extpkgdir,$pbpackager,$chglog);
[16]300 }
[15]301 }
[18]302 }
[21]303 if ($debug >= 0) {
304 my @found;
305 my @notfound;
306 foreach my $b (keys %build) {
307 push @found,$b if ($build{$b} =~ /yes/);
308 push @notfound,$b if ($build{$b} =~ /no/);
309 }
[22]310 print $LOG "Build files generated for ".join(',',@found)."\n";
311 print $LOG "No Build files found for ".join(',',@notfound)."\n";
[21]312 }
[236]313 # Get the generic filter (all.pbf) and
314 # apply those to the non-build files including those
315 # generated by pbinit if applicable
316
317 # Get only all.pbf filter
[237]318 $ptr = pb_get_filters($pbpkg);
[236]319
320 my $liste ="";
321 if (defined $filteredfiles->{$pbpkg}) {
322 foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
[298]323 pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
[238]324 $liste = "$f $liste";
[236]325 }
326 }
[239]327 print $LOG "Files ".$liste."have been filtered\n";
[236]328
[265]329 # Prepare the dest directory for archive
330 if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
[298]331 pb_filter_file("$ENV{'PBCONF'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
[266]332 chmod 0755,"$ENV{'PBTMP'}/pbinit";
333 pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBCONF'}/$pbpkg/pbinit");
[265]334 }
335
[18]336 # Archive dest dir
[69]337 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
[25]338 # Possibility to look at PBSRC to guess more the filename
[94]339 pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
[31]340 print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
[83]341
[70]342 # Keep track of what is generated for default
[113]343 open(LAST,"> $pbrc->{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc->{$ENV{'PBPROJ'}}";
[83]344 print LAST "pbroot $pbprojver-$pbprojtag = $ENV{'PBROOT'}\n";
345 close(LAST);
346
347 # Keep track of per package version
348 if (! -f "$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") {
349 open(PKG,">$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
350 print PKG "# Empty\n";
351 close(PKG);
352 }
[89]353 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[83]354 $pkg = { } if (not defined $pkg);
[88]355 if ((not defined $pkg->{$pbpkg}) || ($pkg->{$pbpkg} ne "$pbver-$pbtag")) {
356 $pkg->{$pbpkg} = "$pbver-$pbtag";
[83]357 }
358
[88]359 print $LOG "DEBUG pkg: ".Dumper($pkg)."\n" if ($debug >= 1);
[83]360 open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
[88]361 foreach my $p (keys %$pkg) {
362 print PKG "pbpkg $p = $pkg->{$p}\n";
[83]363 }
364 close(PKG);
[288]365
366 # Final cleanup
367 pb_rm_rf($dest) if (-d $dest);
[9]368 }
[77]369}
[22]370
[77]371sub pb_build2pkg {
372
[22]373 # Get list of packages to build
[112]374 my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
[22]375 @pkgs = @$ptr;
376
377 # Get the running distro to build on
[99]378 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
379 print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
[22]380
[83]381 # Get content saved in cms2build
[89]382 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[83]383 $pkg = { } if (not defined $pkg);
384
[174]385 # declare packager
386 my ($tmp) = pb_conf_get("packager");
387 my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
388
[25]389 chdir "$ENV{'PBBUILDDIR'}";
[126]390 my $made = ""; # pkgs made during build
[27]391 foreach my $pbpkg (@pkgs) {
[88]392 my $vertag = $pkg->{$pbpkg};
[77]393 # get the version of the current package - maybe different
394 ($pbver,$pbtag) = split(/-/,$vertag);
395
[27]396 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[67]397 print $LOG "Source file: $src\n" if ($debug >= 0);
[25]398
[149]399 print $LOG "Working directory: $ENV{'PBBUILDDIR'}\n" if ($debug >= 0);
[25]400 if ($dtype eq "rpm") {
401 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
[28]402 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
[96]403 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$d") || die "Please ensure that you can write into $ENV{'PBBUILDDIR'} to create $d\nchown the $ENV{'PBBUILDDIR'} directory to your uid";
[28]404 }
[25]405 }
406
[301]407 unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
[188]408 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
[25]409 # We need to first extract the spec file
[28]410 my @specfile;
[77]411 @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
[25]412
[28]413 print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
[25]414 # set LANGUAGE to check for correct log messages
415 $ENV{'LANGUAGE'}="C";
[28]416 #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
417 foreach my $f (@specfile) {
418 if ($f =~ /\.spec$/) {
[291]419 pb_system("rpmbuild --define \'packager $pbpackager\' --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}");
[28]420 last;
421 }
422 }
[136]423 $made="$made RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm";
[149]424 if (-f "/usr/bin/rpmlint") {
425 pb_system("rpmlint $made","Checking validity of rpms with rpmlint");
[150]426 }
[118]427 } elsif ($dtype eq "deb") {
[149]428 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
[274]429 pb_system("tar xfz $src","Extracting sources");
[149]430
431 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
[310]432 pb_rm_rf("debian");
[149]433 symlink "pbconf/$ddir-$dver","debian" || die "Unable to symlink to pbconf/$ddir-$dver";
[199]434 chmod 0755,"debian/rules";
[149]435 pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package");
[136]436 $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz";
[87]437 } elsif ($dtype eq "ebuild") {
[149]438 my @ebuildfile;
439 # For gentoo we need to take pb as subsystem name
[295]440 # We put every apps here under sys-apps. hope it's correct
441 # We use pb's home dir in order o have a single OVERLAY line
442 my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
443 pb_mkdir_p($tmpd) if (! -d "$tmpd");
444 pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
[149]445
[295]446 # We need to first extract the ebuild file
447 @ebuildfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$tmpd");
[149]448
449 # Prepare the build env for gentoo
450 my $found = 0;
[295]451 my $pbbd = $ENV{'HOME'};
[150]452 $pbbd =~ s|/|\\/|g;
[295]453 if (-r "/etc/make.conf") {
454 open(MAKE,"/etc/make.conf");
455 while (<MAKE>) {
456 $found = 1 if (/$pbbd\/portage/);
457 }
458 close(MAKE);
[149]459 }
460 if ($found == 0) {
[295]461 pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
[149]462 }
[295]463 #$found = 0;
464 #if (-r "/etc/portage/package.keywords") {
465 #open(KEYW,"/etc/portage/package.keywords");
466 #while (<KEYW>) {
467 #$found = 1 if (/portage\/pb/);
468 #}
469 #close(KEYW);
470 #}
471 #if ($found == 0) {
472 #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
473 #}
[149]474
475 # Build
476 foreach my $f (@ebuildfile) {
477 if ($f =~ /\.ebuild$/) {
[295]478 move($f,"$tmpd/$pbpkg-$pbver.ebuild");
479 pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package");
480 # Now move it where pb expects it
481 pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
482 move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
[149]483 }
484 }
485
[295]486 $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver.ebuild";
[118]487 } elsif ($dtype eq "slackware") {
[136]488 $made="$made build-$pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
[118]489 pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
[87]490 } else {
[118]491 die "Unknown dtype format $dtype";
[87]492 }
493 }
[118]494 # Keep track of what is generated so that we can get them back from VMs
[129]495 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
[118]496 print KEEP "$made\n";
497 close(KEEP);
[87]498}
499
[88]500sub pb_build2ssh {
[90]501 pb_send2ssh("Sources");
502}
[87]503
[90]504sub pb_pkg2ssh {
505 pb_send2ssh("Packages");
506}
507
[108]508# By default deliver to the the public site hosting the
509# ftp structure (or whatever) or a VM
[90]510sub pb_send2ssh {
511
512 my $cmt = shift;
[118]513 my $vm = shift || undef;
[142]514 my $vmexist = shift || 0; # 0 is FALSE
[200]515 my $vmpid = shift || 0; # 0 is FALSE
[108]516 my $host = shift || "sshhost";
517 my $login = shift || "sshlogin";
518 my $dir = shift || "sshdir";
519 my $port = shift || "sshport";
[203]520 my $tmout = shift || "vmtmout";
[158]521 my $cmd = "";
[90]522
[87]523 # Get list of packages to build
[112]524 my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
[87]525 @pkgs = @$ptr;
526
[136]527 # Get the running distro to consider
[118]528 my ($odir,$over) = (undef, undef);
529 if (defined $vm) {
530 ($odir,$over) = split(/_/,$vm);
531 }
532 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
[99]533 print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
[87]534
535 # Get content saved in cms2build
[89]536 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[87]537 $pkg = { } if (not defined $pkg);
538
[118]539 my $src = "";
[87]540 chdir "$ENV{'PBBUILDDIR'}";
541 foreach my $pbpkg (@pkgs) {
[88]542 my $vertag = $pkg->{$pbpkg};
[87]543 # get the version of the current package - maybe different
544 ($pbver,$pbtag) = split(/-/,$vertag);
545
[118]546 if (($cmt eq "Sources") || ($cmt eq "VMs")) {
[158]547 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[166]548 if ($cmd eq "") {
549 $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
550 } else {
551 $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
552 }
[118]553 }
554 }
555 if ($cmt eq "VMs") {
[132]556 $src="$src $ENV{'PBDESTDIR'}/pbscript $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb $ENV{'PBETC'}";
[142]557 } elsif ($cmt eq "Script") {
558 $src="$src $ENV{'PBDESTDIR'}/pbscript";
[118]559 } elsif ($cmt eq "Packages") {
560 # Get package list from file made during build2pkg
[129]561 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
[126]562 $src = <KEEP>;
[118]563 chomp($src);
564 close(KEEP);
565 if ($dtype eq "rpm") {
566 # Also make a pbscript to generate yum/urpmi bases
[108]567 # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
[118]568 } elsif ($dtype eq "deb") {
569 # Also make a pbscript to generate apt bases
570 # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
[90]571 }
[87]572 }
[132]573 # Remove potential leading spaces (cause pb with basename)
574 $src =~ s/^ *//;
[129]575 my $basesrc = "";
[131]576 foreach my $i (split(/ +/,$src)) {
577 $basesrc .= " ".basename($i);
[130]578 }
[118]579
[128]580 print $LOG "Sources handled ($cmt): $src\n" if ($debug >= 0);
[290]581 my ($sshhost,$sshlogin,$sshdir,$sshport,$vmtmout,$testver) = pb_conf_get($host,$login,$dir,$port,$tmout,"testver");
[88]582 my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
[152]583 # Overwrite account value if passed as parameter
584 $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
[108]585 my $tdir;
[136]586 my $bdir;
[142]587 if (($cmt eq "Sources") || ($cmt eq "Script")) {
[108]588 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
589 } elsif ($cmt eq "VMs") {
[136]590 $tdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/delivery";
591 $bdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/build";
592 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
593 $bdir =~ s|\$ENV.+\}/||;
[90]594 } elsif ($cmt eq "Packages") {
[108]595 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
[309]596 if ((defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} eq "true")) {
[289]597 # This is a test pkg => target dir is under test
598 $tdir .= "/test";
[291]599 }
[90]600 } else {
601 return;
[22]602 }
[239]603 my $nport = $sshport->{$ENV{'PBPROJ'}};
604 $nport = "$pbport" if (defined $pbport);
605
[136]606 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
[132]607 $tdir =~ s|\$ENV.+\}/||;
608
[203]609 my $tm = $vmtmout->{$ENV{'PBPROJ'}};
[239]610 pb_system("ssh -q -p $nport $mac \"mkdir -p $tdir ; cd $tdir ; echo \'for i in $basesrc; do if [ -f \$i ]; then rm -f \$i; fi; done\ ; $cmd' | bash\"","Preparing $tdir on $mac");
611 pb_system("cd $ENV{'PBBUILDDIR'} ; scp -p -P $nport $src $mac:$tdir 2> /dev/null","$cmt delivery in $tdir on $mac");
612 pb_system("ssh -q -p $nport $mac \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi\' | bash\"","Executing pbscript on $mac if needed");
[108]613 if ($cmt eq "VMs") {
[128]614 # Get back info on pkg produced, compute their name and get them from the VM
[239]615 pb_system("scp -p -P $nport $mac:$bdir/pbgen-$pbprojver-$pbprojtag $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $bdir on $mac");
[129]616 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
[118]617 my $src = <KEEP>;
618 chomp($src);
619 close(KEEP);
[131]620 $src =~ s/^ *//;
[136]621 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
[139]622 # Change pgben to make the next send2ssh happy
[143]623 my $made = "";
[139]624 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
[136]625 foreach my $p (split(/ +/,$src)) {
[139]626 my $j = basename($p);
[239]627 pb_system("scp -p -P $nport $mac:\'$bdir/$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $bdir from $mac");
[144]628 $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
[136]629 }
[143]630 print KEEP "$made\n";
[139]631 close(KEEP);
[239]632 pb_system("ssh -q -p $nport $mac \"rm -rf $tdir $bdir\"","VM cleanup on $mac");
[288]633 pb_send2ssh("Packages","$odir"."_"."$over");
[142]634 if (! $vmexist) {
[239]635 pb_system("ssh -q -p $nport $mac \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $vm halt (pid $vmpid)");
[142]636 }
[141]637 pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
[108]638 }
[9]639}
[16]640
[142]641sub pb_script2vm {
642 my $pbscript=shift;
[141]643
644 # Prepare the script to be executed on the VM
645 # in $ENV{'PBDESTDIR'}/pbscript
[142]646 if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
647 copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
648 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
649 }
[141]650
[142]651 my ($vm,$all) = pb_get_vm();
652
[141]653 foreach my $v (@$vm) {
[142]654 # Launch the VM
[262]655 my ($vmexist,$vmpid) = pb_launchvm($v,0);
[141]656
[274]657 # Skip that VM if it something went wrong
658 next if (($vmpid == 0) && ($vmexist ==0));
659
[142]660 # Gather all required files to send them to the VM
661 # and launch the build thourgh pbscript
[200]662 pb_send2ssh("Script","$v",$vmexist,$vmpid,"vmhost","vmlogin","pbrc","vmport","vmtmout");
[169]663
[142]664 }
665}
666
[310]667sub pb_launchchroot {
668 # Virtual env.
669 my $ve = shift;
670 my $create = shift || 0; # By default do not create a chroot
671
672 #die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
673 #die "No VM defined, unable to launch" if (not defined $ve);
674
675 # Keep only the first chroot in case many were given
676 $ve =~ s/,.*//;
677
678 # Launch the chroot
679 my ($ptr,$veopt,$veport,$vepath,$vetmout,$vesize) = pb_conf_get("vetype","veopt","veport","vepath","vetmout","vesize");
680 my $vetype = $ptr->{$ENV{'PBPROJ'}};
681 if (not defined $ENV{'PBCHROOTOPT'}) {
682 $ENV{'PBCHROOTOPT'} = "";
683 }
684 if (defined $veopt->{$ENV{'PBPROJ'}}) {
685 $ENV{'PBVMOPT'} .= " $veopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $veopt->{$ENV{'PBPROJ'}}/);
686 }
687 my $nport = $veport->{$ENV{'PBPROJ'}};
688 $nport = "$pbport" if (defined $pbport);
689
690 my $cmd;
691 my $vecmd; # has to be used for pb_check_ps
692 my $vem; # has to be used for pb_check_ps
693 if ($vetype eq "qemu") {
694 my $arch = `uname -m`;
695 chomp($arch);
696 my $qemucmd32;
697 my $qemucmd64;
698 if ($arch eq "x86_64") {
699 $qemucmd32 = "/usr/bin/qemu-system-i386";
700 $qemucmd64 = "/usr/bin/qemu";
701 } else {
702 $qemucmd32 = "/usr/bin/qemu";
703 $qemucmd64 = "/usr/bin/qemu-system-x86_64";
704 }
705 if ($ve =~ /_64/) {
706 $vecmd = "$qemucmd64 -no-kqemu";
707 } else {
708 $vecmd = "$qemucmd32";
709 }
710 $vem = "$vepath->{$ENV{'PBPROJ'}}/$ve.qemu";
711 if ($create != 0) {
712 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
713 }
714 $cmd = "$vecmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vem"
715 } elsif ($vetype eq "xen") {
716 } elsif ($vetype eq "vmware") {
717 } else {
718 die "VM of type $vetype not supported. Report to the dev team";
719 }
720 my ($tmpcmd,$void) = split(/ +/,$cmd);
721 my $veexist = pb_check_ps($tmpcmd,$vem);
722 my $vepid = 0;
723 if (! $veexist) {
724 if ($create != 0) {
725 pb_system("/usr/bin/qemu-img create -f qcow2 $vem $vesize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
726 }
727 if (! -f "$vem") {
728 print "Unable to find VM $vem\n";
729 } else {
730 pb_system("$cmd &","Launching the VM $vem");
731 pb_system("sleep $vetmout->{$ENV{'PBPROJ'}}","Waiting for VM $ve to come up");
732 $vepid = pb_check_ps($tmpcmd,$vem);
733 }
734 } else {
735 print "Found an existing VM $vem (pid $veexist)\n";
736 }
737 return($veexist,$vepid);
738}
739
[142]740sub pb_launchvm {
741 my $vm = shift;
[262]742 my $create = shift || 0; # By default do not create a VM
[142]743
[262]744 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
[142]745 die "No VM defined, unable to launch" if (not defined $vm);
746 # Keep only the first VM in case many were given
747 $vm =~ s/,.*//;
748
749 # Launch the VMs
[262]750 my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize");
[142]751 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
[262]752 if (not defined $ENV{'PBVMOPT'}) {
[142]753 $ENV{'PBVMOPT'} = "";
754 }
[262]755 if (defined $vmopt->{$ENV{'PBPROJ'}}) {
[296]756 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
[262]757 }
[239]758 my $nport = $vmport->{$ENV{'PBPROJ'}};
759 $nport = "$pbport" if (defined $pbport);
[142]760
761 my $cmd;
762 my $vmcmd; # has to be used for pb_check_ps
763 my $vmm; # has to be used for pb_check_ps
764 if ($vmtype eq "qemu") {
765 my $arch = `uname -m`;
766 chomp($arch);
767 my $qemucmd32;
768 my $qemucmd64;
769 if ($arch eq "x86_64") {
770 $qemucmd32 = "/usr/bin/qemu-system-i386";
771 $qemucmd64 = "/usr/bin/qemu";
[141]772 } else {
[142]773 $qemucmd32 = "/usr/bin/qemu";
774 $qemucmd64 = "/usr/bin/qemu-system-x86_64";
[141]775 }
[142]776 if ($vm =~ /_64/) {
777 $vmcmd = "$qemucmd64 -no-kqemu";
778 } else {
779 $vmcmd = "$qemucmd32";
780 }
781 $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$vm.qemu";
[262]782 if ($create != 0) {
783 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
[142]784 }
[239]785 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
[142]786 } elsif ($vmtype eq "xen") {
787 } elsif ($vmtype eq "vmware") {
788 } else {
789 die "VM of type $vmtype not supported. Report to the dev team";
790 }
[199]791 my ($tmpcmd,$void) = split(/ +/,$cmd);
792 my $vmexist = pb_check_ps($tmpcmd,$vmm);
[200]793 my $vmpid = 0;
[142]794 if (! $vmexist) {
[262]795 if ($create != 0) {
[310]796 if (($vmtype eq "qemu") || ($vmtype eq "xen")) {
797 pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
798 } elsif ($vmtype eq "vmware") {
799 } else {
800 }
[262]801 }
802 if (! -f "$vmm") {
[274]803 print "Unable to find VM $vmm\n";
804 } else {
805 pb_system("$cmd &","Launching the VM $vmm");
806 pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $vm to come up");
807 $vmpid = pb_check_ps($tmpcmd,$vmm);
[262]808 }
[200]809 } else {
810 print "Found an existing VM $vmm (pid $vmexist)\n";
[141]811 }
[200]812 return($vmexist,$vmpid);
[141]813}
[142]814
[105]815sub pb_build2vm {
[108]816 # Prepare the script to be executed on the VM
817 # in $ENV{'PBDESTDIR'}/pbscript
[220]818 my ($ntp) = pb_conf_get("vmntp");
819 my $vmntp = $ntp->{$ENV{'PBPROJ'}};
[118]820 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
821 print SCRIPT "#!/bin/bash\n";
[126]822 print SCRIPT "echo ... Execution needed\n";
[132]823 print SCRIPT "# This is in directory delivery\n";
[118]824 print SCRIPT "# Setup the variables required for building\n";
825 print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
[132]826 print SCRIPT "# Preparation for pb\n";
827 print SCRIPT "mkdir -p ../pbconf\n";
828 print SCRIPT "mv $ENV{'PBPROJ'}.pb ../pbconf\n";
829 print SCRIPT "mv .pbrc \$HOME\n";
830 print SCRIPT "cd ..\n";
[268]831 # Force new date to be in the future compared to the date of the tar file by adding 1 minute
[226]832 my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
[268]833 $date[1]++;
[220]834 my $upddate = strftime("%m%d%H%M%Y", @date);
835 print SCRIPT "echo Setting up date on $vmntp...\n";
[268]836 # Or use ntpdate if available
[220]837 print SCRIPT "sudo date $upddate\n";
[118]838 print SCRIPT "export PBROOT=\`pwd\`\n";
839 print SCRIPT "# Build\n";
[127]840 my $p = "";
[272]841 $p = join(' ',@ARGV) if (defined $ARGV[0]);
[132]842 print SCRIPT "echo Building packages on VM...\n";
[166]843 print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n";
[118]844 close(SCRIPT);
845 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
846
[142]847 my ($vm,$all) = pb_get_vm();
848
[106]849 # Send tar files when we do a global generation
850 pb_build2ssh() if ($all == 1);
[118]851
852 foreach my $v (@$vm) {
[142]853 # Launch the VM
[262]854 my ($vmexist,$vmpid) = pb_launchvm($v,0);
[118]855
[274]856 # Skip that VM if it something went wrong
857 next if (($vmpid == 0) && ($vmexist == 0));
858
[142]859 # Gather all required files to send them to the VM
860 # and launch the build thourgh pbscript
[200]861 pb_send2ssh("VMs","$v",$vmexist,$vmpid,"vmhost","vmlogin","pbrc","vmport","vmtmout");
[118]862 }
[105]863}
864
[262]865
[199]866sub pb_newver {
867
[204]868 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
[199]869 my $cms=pb_cms_init($ENV{'PBPROJ'});
870 if ($cms->{$ENV{'PBPROJ'}} ne "svn") {
871 die "Only SVN is supported at the moment";
872 }
873 my $res = pb_cms_isdiff($cms);
874 die "You need to have no differences before creating a new version" if ($res != 0);
875 my $cmsurl = pb_cms_getinfo($cms);
[204]876 my $newurl = dirname($cmsurl)."/$newver";
877 pb_cms_copy($cms,$cmsurl,$newurl);
[208]878 pb_cms_checkout($cms,$newurl,"$ENV{'PBROOT'}/../$newver");
879 my $oldver=basename($cmsurl);
[211]880 open(FILE,"$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb";
881 open(OUT,"> $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new";
[208]882 while(<FILE>) {
[209]883 s/projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
[211]884 print OUT $_;
[208]885 }
886 close(FILE);
[211]887 close(OUT);
888 rename("$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb");
[208]889 pb_cms_checkin($cms,"$ENV{'PBROOT'}/../$newver");
[199]890}
891
[293]892#
893# Return the list of packages we are working on
894#
[77]895sub pb_get_pkg {
[16]896
[22]897my @pkgs;
[108]898my $defpkgdir = shift;
899my $extpkgdir = shift;
[22]900
901# Get packages list
902if (not defined $ARGV[0]) {
[112]903 @pkgs = keys %$defpkgdir;
[22]904} elsif ($ARGV[0] =~ /^all$/) {
[112]905 @pkgs = keys %$defpkgdir;
906 push(@pkgs, keys %$extpkgdir);
[22]907} else {
908 @pkgs = @ARGV;
909}
910print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
911return(\@pkgs);
912}
913
[105]914#
915# Return the list of VMs we are working on
916# $all is a flag to know if we return all of them
917# or only some (if all we publish also tar files in addition to pkgs
918#
[91]919sub pb_get_vm {
920
921my @vm;
[105]922my $all = 0;
[91]923
924# Get VM list
[105]925if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
[108]926 my ($ptr) = pb_conf_get("vmlist");
[274]927 my $ptr2 = $ptr->{$ENV{'PBPROJ'}};
928 $ptr2 =~ s/,/_64,/g;
929 $ptr2 =~ s/$/_64/g;
930 $ENV{'PBVM'} = "$ptr->{$ENV{'PBPROJ'}},$ptr2";
[105]931 $all = 1;
[91]932}
[274]933print $LOG "VMs: $ENV{'PBVM'}\n";
[105]934@vm = split(/,/,$ENV{'PBVM'});
935return(\@vm,$all);
[91]936}
937
[145]938# Returns the pid of a running VM command using a specific VM file
[142]939sub pb_check_ps {
940 my $vmcmd = shift;
941 my $vmm = shift;
942 my $vmexist = 0; # FALSE by default
943
944 open(PS, "ps auxhww|") || die "Unable to call ps";
945 while (<PS>) {
946 next if (! /$vmcmd/);
947 next if (! /$vmm/);
948 my ($void1, $void2);
949 ($void1, $vmexist, $void2) = split(/ +/);
950 last;
951 }
952 return($vmexist);
953}
954
955
[77]956sub pb_extract_build_files {
[25]957
958my $src=shift;
959my $dir=shift;
[26]960my $ddir=shift;
[28]961my @files;
[25]962
[188]963if ($src =~ /tar\.gz$/) {
964 pb_system("tar xfpz $src $dir","Extracting build files");
965} elsif ($src =~ /tar\.bz2$/) {
966 pb_system("tar xfpj $src $dir","Extracting build files");
967} else {
968 die "Unknown compression algorithm for $src";
969}
[25]970opendir(DIR,"$dir") || die "Unable to open directory $dir";
971foreach my $f (readdir(DIR)) {
972 next if ($f =~ /^\./);
[26]973 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
[28]974 print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
975 push @files,"$ddir/$f";
[25]976}
977closedir(DIR);
[26]978# Not enough but still a first cleanup
[74]979pb_rm_rf("$dir");
[28]980return(@files);
[25]981}
982
[74]983sub pb_syntax {
[21]984
[53]985 print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
986 print "\n";
[288]987 print "Syntax: pb [-vhqt][-r pbroot][-p project][[-s script -a account -P port] -m \"mach-1[,...]\"][-i iso] <action> [<pkg1>...]\n";
[21]988 print "\n";
[310]989 print "-h: This help file\n";
990 print "-q: Quiet mode\n";
991 print "-t: Test mode (not done yet)\n";
992 print "-v: Verbose mode\n";
[21]993 print "\n";
[310]994 print "-m machine: Name of the Virtual Machines (VM) you want\n";
995 print " to build on (coma separated). All if none precised\n";
996 print " (or use the env variable PBVM) \n";
[69]997 print "\n";
[310]998 print "-s script: Name of the script you want\n";
999 print " to execute on the related VMs.\n";
[141]1000 print "\n";
[310]1001 print "-i iso: Name of the ISO image of the distribution you want\n";
1002 print " to install on the related VMs.\n";
[288]1003 print "\n";
[310]1004 print "-a account: Name of the account to use\n";
1005 print " to connect on the related VMs.\n";
[152]1006 print "\n";
[310]1007 print "-P port: Number of the port to use\n";
1008 print " to connect on the related VMs.\n";
[199]1009 print "\n";
[310]1010 print "-p project: Name of the project you're working on\n";
1011 print " (or use the env variable PBPROJ) \n";
[21]1012 print "\n";
[310]1013 print "-r pbroot: Path Name of project under the CMS \n";
1014 print " (or use the env variable PBROOT) \n";
[91]1015 print "\n";
[310]1016 print "-V newver: New version of the project to create\n";
1017 print " from the current one. \n";
[199]1018 print "\n";
[21]1019 print "<action> can be:\n";
1020 print "\n";
[310]1021 print "\tcms2build: Create tar files for the project under your CMS\n";
1022 print "\t CMS supported are SVN and CVS\n";
1023 print "\t parameters are packages to build\n";
1024 print "\t if not using default list\n";
[21]1025 print "\n";
[310]1026 print "\tbuild2pkg: Create packages for your running distribution \n";
[21]1027 print "\n";
[310]1028 print "\tcms2pkg: cms2build + build2pkg\n";
[169]1029 print "\n";
[310]1030 print "\tbuild2ssh: Send the tar files to a SSH host \n";
[105]1031 print "\n";
[310]1032 print "\tcms2ssh: cms2build + build2ssh\n";
[220]1033 print "\n";
[310]1034 print "\tpkg2ssh: Send the packages built to a SSH host \n";
[105]1035 print "\n";
[310]1036 print "\tbuild2vm: Create packages in VMs, launching them if needed\n";
1037 print "\t and send those packages to a SSH host once built\n";
1038 print "\t VM type supported are QEMU \n";
[136]1039 print "\n";
[310]1040 print "\tbuild2chroot: Create packages in a chroot, creating it if needed\n";
1041 print "\t and send those packages to a SSH host once built\n";
[169]1042 print "\n";
[310]1043 print "\tcms2vm: cms2build + build2vm\n";
[141]1044 print "\n";
[310]1045 print "\tlaunchvm: Launch one virtual machine\n";
[142]1046 print "\n";
[310]1047 print "\tscript2vm: Launch one virtual machine if needed \n";
1048 print "\t and executes a script on it \n";
[199]1049 print "\n";
[310]1050 print "\tnewvm: Create a new virtual machine\n";
[262]1051 print "\n";
[310]1052 print "\tnewchroot: Create a new chroot environment\n";
[273]1053 print "\n";
[310]1054 print "\tnewver: Create a new version of the project derived \n";
1055 print "\t from the current one \n";
1056 print "\n";
1057 print "\tnewproj: Create a new project and a template set of \n";
1058 print "\t configuration files under pbconf \n";
1059 print "\n";
[21]1060}
Note: See TracBrowser for help on using the repository browser.