[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;
|
---|
[16] | 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 |
|
---|
[27] | 125 | foreach my $pbpkg (@pkgs) {
|
---|
| 126 | if (-f "$ENV{'PBROOT'}/$pbpkg/VERSION") {
|
---|
| 127 | open(V,"$ENV{'PBROOT'}/$pbpkg/VERSION") || die "Unable to open $ENV{'PBROOT'}/$pbpkg/VERSION";
|
---|
[16] | 128 | $pbver = <V>;
|
---|
| 129 | chomp($pbver);
|
---|
[9] | 130 | close(V);
|
---|
| 131 | } else {
|
---|
[16] | 132 | $pbver = $ENV{'PBVER'};
|
---|
[9] | 133 | }
|
---|
| 134 |
|
---|
[27] | 135 | if (-f "$ENV{'PBROOT'}/$pbpkg/TAG") {
|
---|
| 136 | open(T,"$ENV{'PBROOT'}/$pbpkg/TAG") || die "Unable to open $ENV{'PBROOT'}/$pbpkg/TAG";
|
---|
[16] | 137 | $pbtag = <T>;
|
---|
| 138 | chomp($pbtag);
|
---|
[9] | 139 | close(T);
|
---|
| 140 | } else {
|
---|
[16] | 141 | $pbtag = $ENV{'PBTAG'};
|
---|
[9] | 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);
|
---|
[91] | 174 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = pb_distro_init($name,$ver);
|
---|
[22] | 175 | print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1);
|
---|
| 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) {
|
---|
[80] | 230 | pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$dsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate);
|
---|
[16] | 231 | }
|
---|
[92] | 232 | if (defined $filteredfiles{$pbpkg}) {
|
---|
| 233 | foreach my $f (split(/,/,$filteredfiles{$pbpkg})) {
|
---|
[81] | 234 | pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$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
|
---|
[74] | 293 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = pb_distro_init();
|
---|
[25] | 294 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $dsuf))."\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") {
|
---|
| 310 | # rpm has its own standard build directory
|
---|
[28] | 311 | my $tmp=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
|
---|
| 312 | chomp($tmp);
|
---|
| 313 | $ENV{'PBBUILDDIR'}=$tmp;
|
---|
| 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") {
|
---|
[74] | 317 | 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] | 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$/) {
|
---|
[74] | 332 | pb_system("rpmbuild -ba $f","Building package with $f");
|
---|
[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 |
|
---|
| 353 | sub pb_send2ssh {
|
---|
| 354 |
|
---|
| 355 | my $cmt = shift;
|
---|
| 356 |
|
---|
[88] | 357 | my @src;
|
---|
| 358 |
|
---|
[87] | 359 | # Get list of packages to build
|
---|
| 360 | my $ptr = pb_get_pkg();
|
---|
| 361 | @pkgs = @$ptr;
|
---|
| 362 |
|
---|
| 363 | # Get the running distro to build on
|
---|
| 364 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = pb_distro_init();
|
---|
| 365 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $dsuf))."\n" if ($debug >= 1);
|
---|
| 366 |
|
---|
| 367 | # Get content saved in cms2build
|
---|
[89] | 368 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
[87] | 369 | $pkg = { } if (not defined $pkg);
|
---|
| 370 |
|
---|
| 371 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
[90] | 372 | my $src;
|
---|
[87] | 373 | foreach my $pbpkg (@pkgs) {
|
---|
[88] | 374 | my $vertag = $pkg->{$pbpkg};
|
---|
[87] | 375 | # get the version of the current package - maybe different
|
---|
| 376 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 377 |
|
---|
[90] | 378 | if ($cmt eq "Sources") {
|
---|
| 379 | $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
| 380 | } elsif ($cmt eq "Packages") {
|
---|
| 381 | if ($dtype eq "rpm") {
|
---|
| 382 | $src="$ENV{'PBBUILDDIR'}/RPMS/*/$pbpkg$pbver-$pbtag$dsuf.*.rpm $ENV{'PBBUILDDIR'}/SRPMS/$pbpkg$pbver-$pbtag$dsuf.src.rpm"
|
---|
| 383 | } elsif ($dtype eq "deb") {
|
---|
[91] | 384 | my $tmp = "$ENV{'PBBUILDDIR'}/$pbpkg";
|
---|
| 385 | $src="$tmp"."_*.deb $tmp"."_*.dsc $tmp"."_*.tar.gz"
|
---|
[90] | 386 | } elsif ($dtype eq "ebuild") {
|
---|
| 387 | $src="$ENV{'PBBUILDDIR'}/portage/*/$pbpkg/$pbpkg$pbver.ebuild"
|
---|
| 388 | } elsif ($dtype eq "slackware") {
|
---|
| 389 | $src="$ENV{'PBBUILDDIR'}/build-$pbpkg/$pbpkg$pbver-*-$pbtag.tgz"
|
---|
| 390 | } else {
|
---|
| 391 | die "Unknown dtype format $dtype";
|
---|
| 392 | }
|
---|
| 393 | }
|
---|
| 394 | print $LOG "$cmt: $src\n" if ($debug >= 0);
|
---|
[88] | 395 | push @src, $src;
|
---|
[87] | 396 | }
|
---|
[89] | 397 | my ($pt) = pb_conf_get("sshhost", "sshlogin", "sshdir");
|
---|
[88] | 398 | my ($sshhost,$sshlogin,$sshdir) = @$pt;
|
---|
| 399 | my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
|
---|
[90] | 400 | my $dir;
|
---|
| 401 | if ($cmt eq "Sources") {
|
---|
| 402 | $dir = "$sshdir->{$ENV{'PBPROJ'}}/src";
|
---|
| 403 | } elsif ($cmt eq "Packages") {
|
---|
| 404 | $dir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
|
---|
| 405 | } else {
|
---|
| 406 | return;
|
---|
[22] | 407 | }
|
---|
[90] | 408 | $src = join(' ',@src);
|
---|
| 409 | pb_system("ssh -q $mac \"mkdir -p $dir ; cd $dir ; rm -f $src\"","Preparing $dir on $mac");
|
---|
| 410 | pb_system("scp -p $src $mac:$dir","$cmt delivery in $dir on $mac");
|
---|
[9] | 411 | }
|
---|
[16] | 412 |
|
---|
[77] | 413 | sub pb_get_pkg {
|
---|
[16] | 414 |
|
---|
[22] | 415 | my @pkgs;
|
---|
| 416 |
|
---|
| 417 | # Get packages list
|
---|
| 418 | if (not defined $ARGV[0]) {
|
---|
| 419 | @pkgs = keys %defpkgdir;
|
---|
| 420 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
| 421 | @pkgs = keys %defpkgdir;
|
---|
| 422 | if (defined %extpkgdir) {
|
---|
| 423 | my $k = keys %extpkgdir;
|
---|
| 424 | if (defined $k) {
|
---|
| 425 | push(@pkgs, keys %extpkgdir);
|
---|
| 426 | }
|
---|
| 427 | }
|
---|
| 428 | } else {
|
---|
| 429 | @pkgs = @ARGV;
|
---|
| 430 | }
|
---|
| 431 | print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
|
---|
| 432 | return(\@pkgs);
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[91] | 435 | sub pb_get_vm {
|
---|
| 436 |
|
---|
| 437 | my @vm;
|
---|
| 438 |
|
---|
| 439 | # Get VM list
|
---|
| 440 | if (not defined $ENV{'PBVM'}) {
|
---|
| 441 | @vm = keys %defpkgdir;
|
---|
| 442 | } elsif ($ENV{'PBVM'} =~ /^all$/) {
|
---|
| 443 | @vm = keys %defpkgdir;
|
---|
| 444 | if (defined %extpkgdir) {
|
---|
| 445 | my $k = keys %extpkgdir;
|
---|
| 446 | if (defined $k) {
|
---|
| 447 | push(@vm, keys %extpkgdir);
|
---|
| 448 | }
|
---|
| 449 | }
|
---|
| 450 | } else {
|
---|
| 451 | @vm = $ENV{'PBVM'};
|
---|
| 452 | }
|
---|
| 453 | print $LOG "VMs: ".join(',',@vm)."\n" if ($debug >= 0);
|
---|
| 454 | return(\@vm);
|
---|
| 455 | }
|
---|
| 456 |
|
---|
[77] | 457 | sub pb_extract_build_files {
|
---|
[25] | 458 |
|
---|
| 459 | my $src=shift;
|
---|
| 460 | my $dir=shift;
|
---|
[26] | 461 | my $ddir=shift;
|
---|
[28] | 462 | my @files;
|
---|
[25] | 463 |
|
---|
[74] | 464 | pb_system("tar xfpz $src $dir >/dev/null","Extracting build files");
|
---|
[25] | 465 | opendir(DIR,"$dir") || die "Unable to open directory $dir";
|
---|
| 466 | foreach my $f (readdir(DIR)) {
|
---|
| 467 | next if ($f =~ /^\./);
|
---|
[26] | 468 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
[28] | 469 | print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
|
---|
| 470 | push @files,"$ddir/$f";
|
---|
[25] | 471 | }
|
---|
| 472 | closedir(DIR);
|
---|
[26] | 473 | # Not enough but still a first cleanup
|
---|
[74] | 474 | pb_rm_rf("$dir");
|
---|
[28] | 475 | return(@files);
|
---|
[25] | 476 | }
|
---|
| 477 |
|
---|
[74] | 478 | sub pb_syntax {
|
---|
[21] | 479 |
|
---|
[53] | 480 | print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
|
---|
| 481 | print "\n";
|
---|
[91] | 482 | print "Syntax: pb [-vhqt][-r pbroot][-p project][-m \"mach-1...\"] <action> [<pkg1>...]\n";
|
---|
[21] | 483 | print "\n";
|
---|
| 484 | print "-h : This help file\n";
|
---|
| 485 | print "-q : Quiet mode\n";
|
---|
| 486 | print "-t : Test mode (not done yet)\n";
|
---|
| 487 | print "-v : Verbose mode\n";
|
---|
| 488 | print "\n";
|
---|
[91] | 489 | print "-m machine : Name of the virtual Machines you want\n";
|
---|
| 490 | print " to build on (space separated) \n";
|
---|
| 491 | print " (or use the env variable PBVM) \n";
|
---|
[69] | 492 | print "\n";
|
---|
[21] | 493 | print "-p project : Name of the project you're working on\n";
|
---|
| 494 | print " (or use the env variable PBPROJ) \n";
|
---|
| 495 | print "\n";
|
---|
[91] | 496 | print "-r pbroot : Path Name of project under the CMS \n";
|
---|
| 497 | print " (or use the env variable PBROOT) \n";
|
---|
| 498 | print "\n";
|
---|
[21] | 499 | print "<action> can be:\n";
|
---|
| 500 | print "\n";
|
---|
| 501 | print "\tcms2build: Create a tar file of the project under your CMS\n";
|
---|
| 502 | print "\t CMS supported are SVN and CVS\n";
|
---|
[22] | 503 | print "\t parameters are packages to build\n";
|
---|
| 504 | print "\t if not using default list\n";
|
---|
[21] | 505 | print "\n";
|
---|
| 506 | print "\tbuild2pkg: Create packages for your running distribution \n";
|
---|
[22] | 507 | print "\t first parameter is version-tag to build\n";
|
---|
| 508 | print "\t if not using default version-tag\n";
|
---|
| 509 | print "\t following parameters are packages to build\n";
|
---|
| 510 | print "\t if not using default list\n";
|
---|
[21] | 511 | print "\n";
|
---|
[77] | 512 | print "\tcms2pkg: cms2build + build2pkg\n";
|
---|
[21] | 513 | print "\n";
|
---|
| 514 | }
|
---|