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