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