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