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