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