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