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