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