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