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

Last change on this file since 111 was 111, checked in by Bruno Cornec, 17 years ago

Fix ssh port handling which was wrong + space for test

  • Property svn:executable set to *
File size: 17.6 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 AppConfig qw(:argcount :expand);
17use File::Basename;
[26]18use File::Copy;
[13]19use Time::localtime qw(localtime);
20use POSIX qw(strftime);
[5]21
[73]22# Global variables
[17]23use lib qw (lib);
[74]24use ProjectBuilder::Distribution qw (pb_distro_init);
25use ProjectBuilder::Changelog qw (pb_changelog);
26use ProjectBuilder::Version qw (pb_version_init);
[106]27use 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);
[5]28
29my %opts; # CLI Options
[9]30my $action; # action to realize
31my $test = "FALSE";
32my $option = "";
33my @pkgs;
[95]34my $pbtag; # Global Tag variable
35my $pbver; # Global Version variable
[77]36my %pbver; # per package
37my %pbtag; # per package
[53]38my $pbrev; # Global REVISION variable
[16]39my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
40my $pbdate = strftime("%Y-%m-%d", @date);
[108]41my $debug = 0;
42my $LOG = \*STDOUT;
[5]43
[91]44getopts('hl:m:p:qr:tv',\%opts);
[5]45
[75]46my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
[21]47if (defined $opts{'h'}) {
[74]48 pb_syntax();
[21]49 exit(0);
50}
51if (defined $opts{'v'}) {
52 $debug++;
53}
54if (defined $opts{'q'}) {
55 $debug=-1;
56}
[22]57if (defined $opts{'l'}) {
58 open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
59 $LOG = *LOG;
60 $debug = 0 if ($debug == -1);
61 }
[9]62# Handles test option
63if (defined $opts{'t'}) {
64 $test = "TRUE";
65 # Works only for SVN
66 $option = "-r BASE";
67}
[5]68
[67]69# Handle root of the project if defined
70if (defined $opts{'r'}) {
71 $ENV{'PBROOT'} = $opts{'r'};
72}
[91]73# Handle virtual machines if any
74if (defined $opts{'m'}) {
75 $ENV{'PBVM'} = $opts{'m'};
76}
[108]77
78# Get Action
79$action = shift @ARGV;
80die pb_syntax() if (not defined $action);
81
82my ($pbrc, $filteredfiles, $defpkgdir, $extpkgdir);
83
[59]84# Handles project name if any
[108]85# And get global params
[59]86if (defined $opts{'p'}) {
[107]87 ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir)
88 = pb_env_init($opts{'p'});
[59]89} else {
[107]90 ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir)
91 = pb_env_init();
[59]92}
[108]93my %pbrc = %$pbrc;
94my %filteredfiles = %$filteredfiles;
95my %defpkgdir = %$defpkgdir;
96my %extpkgdir = %$extpkgdir;
[59]97
[108]98print $LOG "Project: $ENV{'PBPROJ'}\n" if ($debug >= 0);
[22]99print $LOG "Action: $action\n" if ($debug >= 0);
[9]100
[91]101# Keep those project values to store them at the end each time
[83]102my $pbprojtag = $ENV{'PBTAG'};
103my $pbprojver = $ENV{'PBVER'};
104
[9]105# Act depending on action
106if ($action =~ /^cms2build$/) {
[77]107 pb_cms2build();
108} elsif ($action =~ /^build2pkg$/) {
109 pb_build2pkg();
110} elsif ($action =~ /^cms2pkg$/) {
111 pb_cms2build();
112 pb_build2pkg();
[88]113} elsif ($action =~ /^build2ssh$/) {
114 pb_build2ssh();
115} elsif ($action =~ /^pkg2ssh$/) {
116 pb_pkg2ssh();
[91]117} elsif ($action =~ /^build2vm$/) {
118 pb_build2vm();
119} elsif ($action =~ /^cms2vm$/) {
120 pb_cms2build();
121 pb_build2vm();
[105]122} elsif ($action =~ /^cms2ssh$/) {
123 pb_cms2build();
124 pb_build2vm();
125 pb_build2ssh();
126 pb_pkg2ssh();
[106]127} elsif ($action =~ /^clean$/) {
[77]128} else {
129 print $LOG "'$action' is not available\n";
130 pb_syntax();
131}
132
133sub pb_cms2build {
134
[108]135 my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
[22]136 @pkgs = @$ptr;
[106]137 my $cms=pb_cms_init($ENV{'PBPROJ'},$pbdate);
[9]138
[98]139 my ($pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb","pkgver","pkgtag");
[27]140 foreach my $pbpkg (@pkgs) {
[98]141 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
142 $pbver = $pkgv->{$pbpkg};
[9]143 } else {
[16]144 $pbver = $ENV{'PBVER'};
[9]145 }
[98]146 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
147 $pbtag = $pkgt->{$pbpkg};
[9]148 } else {
[16]149 $pbtag = $ENV{'PBTAG'};
[9]150 }
[95]151
[16]152 $pbrev = $ENV{'PBREVISION'};
[22]153 print $LOG "\n" if ($debug >= 0);
[27]154 print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);
[9]155 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
[16]156 # Clean up dest if necessary. The export will recreate it
[27]157 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
[74]158 pb_rm_rf($dest) if (-d $dest);
[9]159
160 # Export CMS tree for the concerned package to dest
161 # And generate some additional files
162 $OUTPUT_AUTOFLUSH=1;
[29]163
[9]164 # computes in which dir we have to work
[27]165 my $dir = $defpkgdir{$pbpkg};
166 $dir = $extpkgdir{$pbpkg} if (not defined $dir);
[106]167 pb_cms_export($cms,$pbdate,"$ENV{'PBROOT'}/$dir",$dest);
[9]168
169 # Extract cms log history and store it
[106]170 pb_cms_log($cms,"$ENV{'PBROOT'}/$dir","$dest/$ENV{'PBCMSLOGFILE'}");
[29]171
[21]172 my %build;
[91]173
174 my ($ptr) = pb_conf_get("vmlist");
175 foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) {
176 my ($name,$ver) = split(/_/,$d);
[11]177 chomp($ver);
[99]178 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
179 print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n" if ($debug >= 1);
[22]180 print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
[13]181
[16]182 # Filter build files from the less precise up to the most with overloading
[13]183 # Filter all files found, keeping the name, and generating in dest
[16]184
185 # Find all build files first relatively to PBROOT
186 my %bfiles;
[27]187 print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1);
[21]188 $build{"$ddir-$dver"} = "yes";
[27]189 if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") {
190 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!";
[16]191 foreach my $f (readdir(BDIR)) {
192 next if ($f =~ /^\./);
[27]193 $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f";
[16]194 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
195 }
[13]196 closedir(BDIR);
[27]197 } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") {
198 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!";
[16]199 foreach my $f (readdir(BDIR)) {
200 next if ($f =~ /^\./);
[27]201 $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f";
[16]202 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
203 }
204 closedir(BDIR);
[27]205 } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") {
206 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!";
[16]207 foreach my $f (readdir(BDIR)) {
208 next if ($f =~ /^\./);
[27]209 $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f";
[16]210 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
211 }
[13]212 closedir(BDIR);
[27]213 } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") {
214 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir-$dver: $!";
[16]215 foreach my $f (readdir(BDIR)) {
216 next if ($f =~ /^\./);
[27]217 $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f";
[16]218 $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
219 }
[13]220 closedir(BDIR);
221 } else {
[21]222 $build{"$ddir-$dver"} = "no";
[13]223 next;
224 }
[22]225 print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
[13]226
[15]227 # Get all filters to apply
[77]228 my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
[15]229
[19]230 # Apply now all the filters on all the files concerned
231 # destination dir depends on the type of file
232 if (defined $ptr) {
233 foreach my $f (values %bfiles) {
[108]234 pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,\%defpkgdir,\%extpkgdir);
[16]235 }
[92]236 if (defined $filteredfiles{$pbpkg}) {
237 foreach my $f (split(/,/,$filteredfiles{$pbpkg})) {
[99]238 pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate);
[61]239 }
[19]240 }
[15]241 }
[18]242 }
[21]243 if ($debug >= 0) {
244 my @found;
245 my @notfound;
246 foreach my $b (keys %build) {
247 push @found,$b if ($build{$b} =~ /yes/);
248 push @notfound,$b if ($build{$b} =~ /no/);
249 }
[22]250 print $LOG "Build files generated for ".join(',',@found)."\n";
251 print $LOG "No Build files found for ".join(',',@notfound)."\n";
[21]252 }
[18]253 # Prepare the dest directory for archive
[60]254 if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
[108]255 #pb_system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
256 print $LOG "Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit\n";
257 system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit");
[11]258 }
[29]259
[18]260 # Archive dest dir
[69]261 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
[25]262 # Possibility to look at PBSRC to guess more the filename
[94]263 pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
[31]264 print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
[83]265
[70]266 # Keep track of what is generated for default
[83]267 open(LAST,"> $pbrc{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc{$ENV{'PBPROJ'}}";
268 print LAST "pbroot $pbprojver-$pbprojtag = $ENV{'PBROOT'}\n";
269 close(LAST);
270
271 # Keep track of per package version
272 if (! -f "$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") {
273 open(PKG,">$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
274 print PKG "# Empty\n";
275 close(PKG);
276 }
[89]277 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[83]278 $pkg = { } if (not defined $pkg);
[88]279 if ((not defined $pkg->{$pbpkg}) || ($pkg->{$pbpkg} ne "$pbver-$pbtag")) {
280 $pkg->{$pbpkg} = "$pbver-$pbtag";
[83]281 }
282
[88]283 print $LOG "DEBUG pkg: ".Dumper($pkg)."\n" if ($debug >= 1);
[83]284 open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
[88]285 foreach my $p (keys %$pkg) {
286 print PKG "pbpkg $p = $pkg->{$p}\n";
[83]287 }
288 close(PKG);
[9]289 }
[77]290}
[22]291
[77]292sub pb_build2pkg {
293
[22]294 # Get list of packages to build
[108]295 my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
[22]296 @pkgs = @$ptr;
297
298 # Get the running distro to build on
[99]299 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
300 print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
[22]301
[83]302 # Get content saved in cms2build
[89]303 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[83]304 $pkg = { } if (not defined $pkg);
305
[25]306 chdir "$ENV{'PBBUILDDIR'}";
[27]307 foreach my $pbpkg (@pkgs) {
[88]308 my $vertag = $pkg->{$pbpkg};
[77]309 # get the version of the current package - maybe different
310 ($pbver,$pbtag) = split(/-/,$vertag);
311
[27]312 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[67]313 print $LOG "Source file: $src\n" if ($debug >= 0);
[25]314
315 if ($dtype eq "rpm") {
[28]316 print $LOG "Working under $ENV{'PBBUILDDIR'}\n" if ($debug >= 0);
[25]317 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
[28]318 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
[96]319 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]320 }
[25]321 }
322
323 # We need to first extract the spec file
[28]324 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
325 my @specfile;
[77]326 @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
[25]327
[28]328 print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
[25]329 # set LANGUAGE to check for correct log messages
330 $ENV{'LANGUAGE'}="C";
[28]331 #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
332 foreach my $f (@specfile) {
333 if ($f =~ /\.spec$/) {
[97]334 pb_system("rpmbuild --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}");
[28]335 last;
336 }
337 }
[87]338 } elsif ($dtype eq "tgz") {
339 pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
340 } elsif ($dtype eq "ebuild") {
341 pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage") if (! -d "$ENV{'PBBUILDDIR'}/portage");
342 } else {
343 }
344 }
345}
346
[88]347sub pb_build2ssh {
[90]348 pb_send2ssh("Sources");
349}
[87]350
[90]351sub pb_pkg2ssh {
352 pb_send2ssh("Packages");
353}
354
[108]355# By default deliver to the the public site hosting the
356# ftp structure (or whatever) or a VM
[90]357sub pb_send2ssh {
358
359 my $cmt = shift;
[108]360 my $host = shift || "sshhost";
361 my $login = shift || "sshlogin";
362 my $dir = shift || "sshdir";
363 my $port = shift || "sshport";
[90]364
[88]365 my @src;
366
[87]367 # Get list of packages to build
[108]368 my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
[87]369 @pkgs = @$ptr;
370
371 # Get the running distro to build on
[99]372 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
373 print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
[87]374
375 # Get content saved in cms2build
[89]376 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[87]377 $pkg = { } if (not defined $pkg);
378
379 chdir "$ENV{'PBBUILDDIR'}";
[90]380 my $src;
[87]381 foreach my $pbpkg (@pkgs) {
[88]382 my $vertag = $pkg->{$pbpkg};
[87]383 # get the version of the current package - maybe different
384 ($pbver,$pbtag) = split(/-/,$vertag);
385
[90]386 if ($cmt eq "Sources") {
387 $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[108]388 } elsif ($cmt eq "VMs") {
389 $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/pbscript $ENV{'PBETC'}";
[90]390 } elsif ($cmt eq "Packages") {
391 if ($dtype eq "rpm") {
[99]392 $src="$ENV{'PBBUILDDIR'}/RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm $ENV{'PBBUILDDIR'}/SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm"
[90]393 } elsif ($dtype eq "deb") {
[91]394 my $tmp = "$ENV{'PBBUILDDIR'}/$pbpkg";
395 $src="$tmp"."_*.deb $tmp"."_*.dsc $tmp"."_*.tar.gz"
[90]396 } elsif ($dtype eq "ebuild") {
[96]397 $src="$ENV{'PBBUILDDIR'}/portage/*/$pbpkg/$pbpkg-$pbver.ebuild"
[90]398 } elsif ($dtype eq "slackware") {
[96]399 $src="$ENV{'PBBUILDDIR'}/build-$pbpkg/$pbpkg-$pbver-*-$pbtag.tgz"
[90]400 } else {
401 die "Unknown dtype format $dtype";
402 }
[108]403 # Also make a pbscript to generate yum/urpmi/apt bases
404 # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
[90]405 }
406 print $LOG "$cmt: $src\n" if ($debug >= 0);
[88]407 push @src, $src;
[87]408 }
[108]409 my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
[88]410 my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
[108]411 my $tdir;
[90]412 if ($cmt eq "Sources") {
[108]413 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
414 } elsif ($cmt eq "VMs") {
415 $tdir = "$sshdir->{$ENV{'PBPROJ'}}";
[90]416 } elsif ($cmt eq "Packages") {
[108]417 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
[90]418 } else {
419 return;
[22]420 }
[111]421 $port = $sshport->{$ENV{'PBPROJ'}};
[90]422 $src = join(' ',@src);
[111]423 pb_system("ssh -q -p $port $mac \"mkdir -p $tdir ; cd $tdir ; rm -f $src\"","Preparing $tdir on $mac");
424 pb_system("scp -p -P $port $src $mac:$tdir","$cmt delivery in $tdir on $mac");
425 pb_system("ssh -q -p $port $mac \"cd $tdir ; if [ -f pbscript ]; then chmod 755 ./pbscript ; ./pbscript\"","Executing pbscript on $mac");
[108]426 if ($cmt eq "VMs") {
[111]427 pb_system("scp -p -P $port $mac:$tdir/.... ...","Package recovery in $tdir from $mac");
[108]428 }
[9]429}
[16]430
[105]431sub pb_build2vm {
432 my ($vm,$all) = pb_get_vm();
[106]433
[108]434 # Prepare the script to be executed on the VM
435 # in $ENV{'PBDESTDIR'}/pbscript
436 # Launch the VM
437 # Gather all required files to send them to the VM
438 pb_send2ssh("VMs","vmhost","vmlogin","vmdir","vmport");
439
[106]440 # Send tar files when we do a global generation
441 pb_build2ssh() if ($all == 1);
[105]442}
443
[77]444sub pb_get_pkg {
[16]445
[22]446my @pkgs;
[108]447my $defpkgdir = shift;
448my $extpkgdir = shift;
[22]449
[108]450my %defpkgdir = %$defpkgdir;
451my %extpkgdir = %$extpkgdir;
452
[22]453# Get packages list
454if (not defined $ARGV[0]) {
455 @pkgs = keys %defpkgdir;
456} elsif ($ARGV[0] =~ /^all$/) {
457 @pkgs = keys %defpkgdir;
[108]458 push(@pkgs, keys %extpkgdir);
[22]459} else {
460 @pkgs = @ARGV;
461}
462print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
463return(\@pkgs);
464}
465
[105]466#
467# Return the list of VMs we are working on
468# $all is a flag to know if we return all of them
469# or only some (if all we publish also tar files in addition to pkgs
470#
[91]471sub pb_get_vm {
472
473my @vm;
[105]474my $all = 0;
[91]475
476# Get VM list
[105]477if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
[108]478 my ($ptr) = pb_conf_get("vmlist");
[105]479 $ENV{'PBVM'} = $ptr->{$ENV{'PBPROJ'}};
480 $all = 1;
[91]481}
[105]482@vm = split(/,/,$ENV{'PBVM'});
[108]483print $LOG "VMs: ".join(',',@vm)."\n";
[105]484return(\@vm,$all);
[91]485}
486
[77]487sub pb_extract_build_files {
[25]488
489my $src=shift;
490my $dir=shift;
[26]491my $ddir=shift;
[28]492my @files;
[25]493
[106]494pb_system("tar xfpz $src $dir","Extracting build files");
[25]495opendir(DIR,"$dir") || die "Unable to open directory $dir";
496foreach my $f (readdir(DIR)) {
497 next if ($f =~ /^\./);
[26]498 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
[28]499 print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
500 push @files,"$ddir/$f";
[25]501}
502closedir(DIR);
[26]503# Not enough but still a first cleanup
[74]504pb_rm_rf("$dir");
[28]505return(@files);
[25]506}
507
[74]508sub pb_syntax {
[21]509
[53]510 print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
511 print "\n";
[105]512 print "Syntax: pb [-vhqt][-r pbroot][-p project][-m \"mach-1[,...]\"] <action> [<pkg1>...]\n";
[21]513 print "\n";
514 print "-h : This help file\n";
515 print "-q : Quiet mode\n";
516 print "-t : Test mode (not done yet)\n";
517 print "-v : Verbose mode\n";
518 print "\n";
[91]519 print "-m machine : Name of the virtual Machines you want\n";
520 print " to build on (space separated) \n";
521 print " (or use the env variable PBVM) \n";
[69]522 print "\n";
[21]523 print "-p project : Name of the project you're working on\n";
524 print " (or use the env variable PBPROJ) \n";
525 print "\n";
[91]526 print "-r pbroot : Path Name of project under the CMS \n";
527 print " (or use the env variable PBROOT) \n";
528 print "\n";
[105]529 print "<params> can be the name of packages\n";
[21]530 print "<action> can be:\n";
531 print "\n";
[105]532 print "\tcms2build: Create tar files for the project under your CMS\n";
[21]533 print "\t CMS supported are SVN and CVS\n";
[22]534 print "\t parameters are packages to build\n";
535 print "\t if not using default list\n";
[21]536 print "\n";
537 print "\tbuild2pkg: Create packages for your running distribution \n";
[22]538 print "\t first parameter is version-tag to build\n";
539 print "\t if not using default version-tag\n";
540 print "\t following parameters are packages to build\n";
541 print "\t if not using default list\n";
[21]542 print "\n";
[105]543 print "\tbuild2ssh: Send the tar files to a SSH host \n";
544 print "\n";
545 print "\tpkg2ssh: Send the packages built to a SSH host \n";
546 print "\n";
[77]547 print "\tcms2pkg: cms2build + build2pkg\n";
[21]548 print "\n";
549}
Note: See TracBrowser for help on using the repository browser.