[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);
|
---|
[77] | 31 | use ProjectBuilder::Base qw (pb_conf_read 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 |
|
---|
[67] | 46 | getopts('hl: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 | }
|
---|
[59] | 79 | # Handles project name if any
|
---|
| 80 | if (defined $opts{'p'}) {
|
---|
[74] | 81 | $ENV{'PBPROJ'} = pb_env_init($opts{'p'});
|
---|
[59] | 82 | } else {
|
---|
[74] | 83 | $ENV{'PBPROJ'} = pb_env_init();
|
---|
[59] | 84 | }
|
---|
| 85 |
|
---|
[22] | 86 | print $LOG "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);
|
---|
| 87 | print $LOG "Action: $action\n" if ($debug >= 0);
|
---|
[9] | 88 |
|
---|
[83] | 89 | # Keeps those project value to store at end each time
|
---|
| 90 | my $pbprojtag = $ENV{'PBTAG'};
|
---|
| 91 | my $pbprojver = $ENV{'PBVER'};
|
---|
| 92 |
|
---|
[9] | 93 | # Act depending on action
|
---|
| 94 | if ($action =~ /^cms2build$/) {
|
---|
[77] | 95 | pb_cms2build();
|
---|
| 96 | } elsif ($action =~ /^build2pkg$/) {
|
---|
| 97 | pb_build2pkg();
|
---|
| 98 | } elsif ($action =~ /^cms2pkg$/) {
|
---|
| 99 | pb_cms2build();
|
---|
| 100 | pb_build2pkg();
|
---|
[87] | 101 | } elsif ($action =~ /^build2ftp$/) {
|
---|
| 102 | pb_build2ftp();
|
---|
| 103 | } elsif ($action =~ /^pkg2ftp$/) {
|
---|
| 104 | pb_pkg2ftp();
|
---|
[77] | 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();
|
---|
[22] | 113 | @pkgs = @$ptr;
|
---|
[74] | 114 | pb_cms_init($ENV{'PBPROJ'});
|
---|
[9] | 115 |
|
---|
[27] | 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";
|
---|
[16] | 119 | $pbver = <V>;
|
---|
| 120 | chomp($pbver);
|
---|
[9] | 121 | close(V);
|
---|
| 122 | } else {
|
---|
[16] | 123 | $pbver = $ENV{'PBVER'};
|
---|
[9] | 124 | }
|
---|
| 125 |
|
---|
[27] | 126 | if (-f "$ENV{'PBROOT'}/$pbpkg/TAG") {
|
---|
| 127 | open(T,"$ENV{'PBROOT'}/$pbpkg/TAG") || die "Unable to open $ENV{'PBROOT'}/$pbpkg/TAG";
|
---|
[16] | 128 | $pbtag = <T>;
|
---|
| 129 | chomp($pbtag);
|
---|
[9] | 130 | close(T);
|
---|
| 131 | } else {
|
---|
[16] | 132 | $pbtag = $ENV{'PBTAG'};
|
---|
[9] | 133 | }
|
---|
[16] | 134 | $pbrev = $ENV{'PBREVISION'};
|
---|
[22] | 135 | print $LOG "\n" if ($debug >= 0);
|
---|
[27] | 136 | print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);
|
---|
[9] | 137 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
[16] | 138 | # Clean up dest if necessary. The export will recreate it
|
---|
[27] | 139 | my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
|
---|
[74] | 140 | pb_rm_rf($dest) if (-d $dest);
|
---|
[9] | 141 |
|
---|
| 142 | # Export CMS tree for the concerned package to dest
|
---|
| 143 | # And generate some additional files
|
---|
| 144 | $OUTPUT_AUTOFLUSH=1;
|
---|
[29] | 145 |
|
---|
[9] | 146 | # computes in which dir we have to work
|
---|
[27] | 147 | my $dir = $defpkgdir{$pbpkg};
|
---|
| 148 | $dir = $extpkgdir{$pbpkg} if (not defined $dir);
|
---|
[74] | 149 | pb_system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null", "Exporting $ENV{'PBROOT'}/$dir");
|
---|
[9] | 150 |
|
---|
| 151 | # Creates a REVISION file
|
---|
| 152 | open(R,"> $dest/REVISION") || die "Unable to create $dest/REVISION";
|
---|
[16] | 153 | print R "$pbrev\n";
|
---|
[9] | 154 | close(R);
|
---|
| 155 |
|
---|
| 156 | # Extract cms log history and store it
|
---|
[74] | 157 | pb_system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}", "Extracting log info");
|
---|
[29] | 158 |
|
---|
[21] | 159 | my %build;
|
---|
[11] | 160 | open(D,"$ENV{'PBCONF'}/DISTROS") || die "Unable to find $ENV{'PBCONF'}/DISTROS\n";
|
---|
| 161 | while (<D>) {
|
---|
| 162 | my $d = $_;
|
---|
[55] | 163 | my ($ndir,$ver) = split(/_/,$d);
|
---|
[11] | 164 | chomp($ver);
|
---|
[74] | 165 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = pb_distro_init($ndir,$ver);
|
---|
[22] | 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);
|
---|
[13] | 168 |
|
---|
[16] | 169 | # Filter build files from the less precise up to the most with overloading
|
---|
[13] | 170 | # Filter all files found, keeping the name, and generating in dest
|
---|
[16] | 171 |
|
---|
| 172 | # Find all build files first relatively to PBROOT
|
---|
| 173 | my %bfiles;
|
---|
[27] | 174 | print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1);
|
---|
[21] | 175 | $build{"$ddir-$dver"} = "yes";
|
---|
[27] | 176 | if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") {
|
---|
| 177 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!";
|
---|
[16] | 178 | foreach my $f (readdir(BDIR)) {
|
---|
| 179 | next if ($f =~ /^\./);
|
---|
[27] | 180 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f";
|
---|
[16] | 181 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 182 | }
|
---|
[13] | 183 | closedir(BDIR);
|
---|
[27] | 184 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") {
|
---|
| 185 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!";
|
---|
[16] | 186 | foreach my $f (readdir(BDIR)) {
|
---|
| 187 | next if ($f =~ /^\./);
|
---|
[27] | 188 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f";
|
---|
[16] | 189 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 190 | }
|
---|
| 191 | closedir(BDIR);
|
---|
[27] | 192 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") {
|
---|
| 193 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!";
|
---|
[16] | 194 | foreach my $f (readdir(BDIR)) {
|
---|
| 195 | next if ($f =~ /^\./);
|
---|
[27] | 196 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f";
|
---|
[16] | 197 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 198 | }
|
---|
[13] | 199 | closedir(BDIR);
|
---|
[27] | 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: $!";
|
---|
[16] | 202 | foreach my $f (readdir(BDIR)) {
|
---|
| 203 | next if ($f =~ /^\./);
|
---|
[27] | 204 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f";
|
---|
[16] | 205 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 206 | }
|
---|
[13] | 207 | closedir(BDIR);
|
---|
| 208 | } else {
|
---|
[21] | 209 | $build{"$ddir-$dver"} = "no";
|
---|
[13] | 210 | next;
|
---|
| 211 | }
|
---|
[22] | 212 | print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
|
---|
[13] | 213 |
|
---|
[15] | 214 | # Get all filters to apply
|
---|
[77] | 215 | my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
|
---|
[15] | 216 |
|
---|
[19] | 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) {
|
---|
[80] | 221 | pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$dsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate);
|
---|
[16] | 222 | }
|
---|
[61] | 223 | if (defined $filteredfiles{$dir}) {
|
---|
| 224 | foreach my $f (split(/,/,$filteredfiles{$dir})) {
|
---|
[81] | 225 | pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$pbpkg,$pbver,$pbtag,$pbrev,$pbdate);
|
---|
[61] | 226 | }
|
---|
[19] | 227 | }
|
---|
[15] | 228 | }
|
---|
[18] | 229 | }
|
---|
[21] | 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 | }
|
---|
[22] | 237 | print $LOG "Build files generated for ".join(',',@found)."\n";
|
---|
| 238 | print $LOG "No Build files found for ".join(',',@notfound)."\n";
|
---|
[21] | 239 | }
|
---|
[18] | 240 | close(D);
|
---|
| 241 | # Prepare the dest directory for archive
|
---|
[60] | 242 | if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
|
---|
[74] | 243 | pb_system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
|
---|
[11] | 244 | }
|
---|
[29] | 245 |
|
---|
[18] | 246 | # Archive dest dir
|
---|
[69] | 247 | chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
|
---|
[25] | 248 | # Possibility to look at PBSRC to guess more the filename
|
---|
[74] | 249 | pb_system("tar cfpz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
|
---|
[31] | 250 | print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
|
---|
[83] | 251 |
|
---|
[70] | 252 | # Keep track of what is generated for default
|
---|
[83] | 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 | my %pkg = %$pkg;
|
---|
| 266 | if ((not defined $pkg{$pbpkg}) || ($pkg{$pbpkg} ne "$pbver-$pbtag")) {
|
---|
| 267 | $pkg{$pbpkg} = "$pbver-$pbtag";
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | print $LOG "DEBUG pkg: ".Dumper(\%pkg)."\n" if ($debug >= 1);
|
---|
| 271 | open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
|
---|
| 272 | foreach my $p (keys %pkg) {
|
---|
| 273 | print PKG "pbpkg $p = $pkg{$p}\n";
|
---|
| 274 | }
|
---|
| 275 | close(PKG);
|
---|
[9] | 276 | }
|
---|
[77] | 277 | }
|
---|
[22] | 278 |
|
---|
[77] | 279 | sub pb_build2pkg {
|
---|
| 280 |
|
---|
[22] | 281 | # Get list of packages to build
|
---|
[77] | 282 | my $ptr = pb_get_pkg();
|
---|
[22] | 283 | @pkgs = @$ptr;
|
---|
| 284 |
|
---|
| 285 | # Get the running distro to build on
|
---|
[74] | 286 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = pb_distro_init();
|
---|
[25] | 287 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $dsuf))."\n" if ($debug >= 1);
|
---|
[22] | 288 |
|
---|
[83] | 289 | # Get content saved in cms2build
|
---|
| 290 | my $pkg = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
| 291 | $pkg = { } if (not defined $pkg);
|
---|
| 292 | my %pkg = %$pkg;
|
---|
| 293 |
|
---|
[25] | 294 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
[27] | 295 | foreach my $pbpkg (@pkgs) {
|
---|
[83] | 296 | my $vertag = $pkg{$pbpkg};
|
---|
[77] | 297 | # get the version of the current package - maybe different
|
---|
| 298 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 299 |
|
---|
[27] | 300 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
[67] | 301 | print $LOG "Source file: $src\n" if ($debug >= 0);
|
---|
[25] | 302 |
|
---|
| 303 | if ($dtype eq "rpm") {
|
---|
| 304 | # rpm has its own standard build directory
|
---|
[28] | 305 | my $tmp=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
|
---|
| 306 | chomp($tmp);
|
---|
| 307 | $ENV{'PBBUILDDIR'}=$tmp;
|
---|
| 308 | print $LOG "Working under $ENV{'PBBUILDDIR'}\n" if ($debug >= 0);
|
---|
[25] | 309 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
[28] | 310 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
[74] | 311 | 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] | 312 | }
|
---|
[25] | 313 | }
|
---|
| 314 |
|
---|
| 315 | # We need to first extract the spec file
|
---|
[28] | 316 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
| 317 | my @specfile;
|
---|
[77] | 318 | @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
|
---|
[25] | 319 |
|
---|
[28] | 320 | print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
|
---|
[25] | 321 | # set LANGUAGE to check for correct log messages
|
---|
| 322 | $ENV{'LANGUAGE'}="C";
|
---|
[28] | 323 | #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
|
---|
| 324 | foreach my $f (@specfile) {
|
---|
| 325 | if ($f =~ /\.spec$/) {
|
---|
[74] | 326 | pb_system("rpmbuild -ba $f","Building package with $f");
|
---|
[28] | 327 | last;
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
[87] | 330 | } elsif ($dtype eq "tgz") {
|
---|
| 331 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
|
---|
| 332 | } elsif ($dtype eq "ebuild") {
|
---|
| 333 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage") if (! -d "$ENV{'PBBUILDDIR'}/portage");
|
---|
| 334 | } else {
|
---|
| 335 | }
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | sub pb_build2ftp {
|
---|
| 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 | my %pkg = %$pkg;
|
---|
| 353 |
|
---|
| 354 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
| 355 | foreach my $pbpkg (@pkgs) {
|
---|
| 356 | my $vertag = $pkg{$pbpkg};
|
---|
| 357 | # get the version of the current package - maybe different
|
---|
| 358 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 359 |
|
---|
| 360 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
| 361 | print $LOG "Source file: $src\n" if ($debug >= 0);
|
---|
| 362 |
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 | sub pb_pkg2ftp {
|
---|
| 366 |
|
---|
| 367 | # Get list of packages to build
|
---|
| 368 | my $ptr = pb_get_pkg();
|
---|
| 369 | @pkgs = @$ptr;
|
---|
| 370 |
|
---|
| 371 | # Get the running distro to build on
|
---|
| 372 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = pb_distro_init();
|
---|
| 373 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $dsuf))."\n" if ($debug >= 1);
|
---|
| 374 |
|
---|
| 375 | # Get content saved in cms2build
|
---|
| 376 | my $pkg = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
| 377 | $pkg = { } if (not defined $pkg);
|
---|
| 378 | my %pkg = %$pkg;
|
---|
| 379 |
|
---|
| 380 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
| 381 | foreach my $pbpkg (@pkgs) {
|
---|
| 382 | my $vertag = $pkg{$pbpkg};
|
---|
| 383 | # get the version of the current package - maybe different
|
---|
| 384 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 385 |
|
---|
| 386 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
| 387 | print $LOG "Source file: $src\n" if ($debug >= 0);
|
---|
| 388 |
|
---|
| 389 | if ($dtype eq "rpm") {
|
---|
| 390 | # rpm has its own standard build directory
|
---|
| 391 | my $tmp=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
|
---|
| 392 | chomp($tmp);
|
---|
| 393 | $ENV{'PBBUILDDIR'}=$tmp;
|
---|
| 394 | print $LOG "Working under $ENV{'PBBUILDDIR'}\n" if ($debug >= 0);
|
---|
| 395 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
| 396 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
| 397 | 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";
|
---|
| 398 | }
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | # We need to first extract the spec file
|
---|
| 402 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
| 403 | my @specfile;
|
---|
| 404 | @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
|
---|
| 405 |
|
---|
| 406 | print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
|
---|
| 407 | # set LANGUAGE to check for correct log messages
|
---|
| 408 | $ENV{'LANGUAGE'}="C";
|
---|
| 409 | #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
|
---|
| 410 | foreach my $f (@specfile) {
|
---|
| 411 | if ($f =~ /\.spec$/) {
|
---|
| 412 | pb_system("rpmbuild -ba $f","Building package with $f");
|
---|
| 413 | last;
|
---|
| 414 | }
|
---|
| 415 | }
|
---|
[25] | 416 | } elsif ($dtype eq "tgz") {
|
---|
[74] | 417 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
|
---|
[25] | 418 | } elsif ($dtype eq "ebuild") {
|
---|
[74] | 419 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage") if (! -d "$ENV{'PBBUILDDIR'}/portage");
|
---|
[25] | 420 | } else {
|
---|
| 421 | }
|
---|
[22] | 422 | }
|
---|
[9] | 423 | }
|
---|
[16] | 424 |
|
---|
[77] | 425 | sub pb_get_pkg {
|
---|
[16] | 426 |
|
---|
[22] | 427 | my @pkgs;
|
---|
| 428 |
|
---|
| 429 | # Get packages list
|
---|
| 430 | if (not defined $ARGV[0]) {
|
---|
| 431 | @pkgs = keys %defpkgdir;
|
---|
| 432 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
| 433 | @pkgs = keys %defpkgdir;
|
---|
| 434 | if (defined %extpkgdir) {
|
---|
| 435 | my $k = keys %extpkgdir;
|
---|
| 436 | if (defined $k) {
|
---|
| 437 | push(@pkgs, keys %extpkgdir);
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | } else {
|
---|
| 441 | @pkgs = @ARGV;
|
---|
| 442 | }
|
---|
| 443 | print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
|
---|
| 444 | return(\@pkgs);
|
---|
| 445 | }
|
---|
| 446 |
|
---|
[77] | 447 | sub pb_extract_build_files {
|
---|
[25] | 448 |
|
---|
| 449 | my $src=shift;
|
---|
| 450 | my $dir=shift;
|
---|
[26] | 451 | my $ddir=shift;
|
---|
[28] | 452 | my @files;
|
---|
[25] | 453 |
|
---|
[74] | 454 | pb_system("tar xfpz $src $dir >/dev/null","Extracting build files");
|
---|
[25] | 455 | opendir(DIR,"$dir") || die "Unable to open directory $dir";
|
---|
| 456 | foreach my $f (readdir(DIR)) {
|
---|
| 457 | next if ($f =~ /^\./);
|
---|
[26] | 458 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
[28] | 459 | print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
|
---|
| 460 | push @files,"$ddir/$f";
|
---|
[25] | 461 | }
|
---|
| 462 | closedir(DIR);
|
---|
[26] | 463 | # Not enough but still a first cleanup
|
---|
[74] | 464 | pb_rm_rf("$dir");
|
---|
[28] | 465 | return(@files);
|
---|
[25] | 466 | }
|
---|
| 467 |
|
---|
[74] | 468 | sub pb_syntax {
|
---|
[21] | 469 |
|
---|
[53] | 470 | print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
|
---|
| 471 | print "\n";
|
---|
[69] | 472 | print "Syntax: pb [-vhqt][-r pbroot][-p project] <action> [<params>...]\n";
|
---|
[21] | 473 | print "\n";
|
---|
| 474 | print "-h : This help file\n";
|
---|
| 475 | print "-q : Quiet mode\n";
|
---|
| 476 | print "-t : Test mode (not done yet)\n";
|
---|
| 477 | print "-v : Verbose mode\n";
|
---|
| 478 | print "\n";
|
---|
[69] | 479 | print "-r pbroot : Path Name of project under the CMS \n";
|
---|
| 480 | print " (or use the env variable PBROOT) \n";
|
---|
| 481 | print "\n";
|
---|
[21] | 482 | print "-p project : Name of the project you're working on\n";
|
---|
| 483 | print " (or use the env variable PBPROJ) \n";
|
---|
| 484 | print "\n";
|
---|
| 485 | print "<action> can be:\n";
|
---|
| 486 | print "\n";
|
---|
| 487 | print "\tcms2build: Create a tar file of the project under your CMS\n";
|
---|
| 488 | print "\t CMS supported are SVN and CVS\n";
|
---|
[22] | 489 | print "\t parameters are packages to build\n";
|
---|
| 490 | print "\t if not using default list\n";
|
---|
[21] | 491 | print "\n";
|
---|
| 492 | print "\tbuild2pkg: Create packages for your running distribution \n";
|
---|
[22] | 493 | print "\t first parameter is version-tag to build\n";
|
---|
| 494 | print "\t if not using default version-tag\n";
|
---|
| 495 | print "\t following parameters are packages to build\n";
|
---|
| 496 | print "\t if not using default list\n";
|
---|
[21] | 497 | print "\n";
|
---|
[77] | 498 | print "\tcms2pkg: cms2build + build2pkg\n";
|
---|
[21] | 499 | print "\n";
|
---|
| 500 | }
|
---|