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