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