[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 |
|
---|
[22] | 22 | use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles $debug $LOG);
|
---|
[19] | 23 | %extpkgdir = ();
|
---|
| 24 | %filteredfiles = ();
|
---|
[21] | 25 | $debug = 0; # Debug level
|
---|
[22] | 26 | $LOG = *STDOUT; # Where to log
|
---|
[17] | 27 | use lib qw (lib);
|
---|
[9] | 28 | use common qw (env_init);
|
---|
[18] | 29 | use pb qw (pb_init);
|
---|
[11] | 30 | use distro qw (distro_init);
|
---|
[5] | 31 | use cms;
|
---|
[17] | 32 | use changelog qw (changelog);
|
---|
[5] | 33 |
|
---|
| 34 | my %opts; # CLI Options
|
---|
[9] | 35 | my $action; # action to realize
|
---|
| 36 | my $test = "FALSE";
|
---|
| 37 | my $option = "";
|
---|
| 38 | my @pkgs;
|
---|
[16] | 39 | my $pbtag; # Global TAG variable
|
---|
| 40 | my $pbver; # Global VERSION variable
|
---|
| 41 | my $pbrev; # GLOBAL REVISION variable
|
---|
| 42 | my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
|
---|
| 43 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
[5] | 44 |
|
---|
[22] | 45 | getopts('hl:p:qtv',\%opts);
|
---|
[5] | 46 |
|
---|
[21] | 47 | if (defined $opts{'h'}) {
|
---|
| 48 | syntax();
|
---|
| 49 | exit(0);
|
---|
| 50 | }
|
---|
| 51 | if (defined $opts{'v'}) {
|
---|
| 52 | $debug++;
|
---|
| 53 | }
|
---|
| 54 | if (defined $opts{'q'}) {
|
---|
| 55 | $debug=-1;
|
---|
| 56 | }
|
---|
[22] | 57 | if (defined $opts{'l'}) {
|
---|
| 58 | open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
|
---|
| 59 | $LOG = *LOG;
|
---|
| 60 | $debug = 0 if ($debug == -1);
|
---|
| 61 | }
|
---|
[5] | 62 | # Handles project name if any
|
---|
| 63 | if (defined $opts{'p'}) {
|
---|
[9] | 64 | $ENV{'PBPROJ'} = env_init($opts{'p'});
|
---|
[5] | 65 | } else {
|
---|
[9] | 66 | $ENV{'PBPROJ'} = env_init();
|
---|
[5] | 67 | }
|
---|
[9] | 68 | # Handles test option
|
---|
| 69 | if (defined $opts{'t'}) {
|
---|
| 70 | $test = "TRUE";
|
---|
| 71 | # Works only for SVN
|
---|
| 72 | $option = "-r BASE";
|
---|
| 73 | }
|
---|
[5] | 74 |
|
---|
[9] | 75 | # Get Action
|
---|
| 76 | $action = shift @ARGV;
|
---|
[21] | 77 | die syntax() if (not defined $action);
|
---|
[6] | 78 |
|
---|
[22] | 79 | print $LOG "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);
|
---|
| 80 | print $LOG "Action: $action\n" if ($debug >= 0);
|
---|
[9] | 81 |
|
---|
| 82 | # Act depending on action
|
---|
| 83 | if ($action =~ /^cms2build$/) {
|
---|
[22] | 84 | my $ptr = get_pkg();
|
---|
| 85 | @pkgs = @$ptr;
|
---|
[9] | 86 | cms_init();
|
---|
| 87 |
|
---|
[27] | 88 | foreach my $pbpkg (@pkgs) {
|
---|
| 89 | if (-f "$ENV{'PBROOT'}/$pbpkg/VERSION") {
|
---|
| 90 | open(V,"$ENV{'PBROOT'}/$pbpkg/VERSION") || die "Unable to open $ENV{'PBROOT'}/$pbpkg/VERSION";
|
---|
[16] | 91 | $pbver = <V>;
|
---|
| 92 | chomp($pbver);
|
---|
[9] | 93 | close(V);
|
---|
| 94 | } else {
|
---|
[16] | 95 | $pbver = $ENV{'PBVER'};
|
---|
[9] | 96 | }
|
---|
| 97 |
|
---|
[27] | 98 | if (-f "$ENV{'PBROOT'}/$pbpkg/TAG") {
|
---|
| 99 | open(T,"$ENV{'PBROOT'}/$pbpkg/TAG") || die "Unable to open $ENV{'PBROOT'}/$pbpkg/TAG";
|
---|
[16] | 100 | $pbtag = <T>;
|
---|
| 101 | chomp($pbtag);
|
---|
[9] | 102 | close(T);
|
---|
| 103 | } else {
|
---|
[16] | 104 | $pbtag = $ENV{'PBTAG'};
|
---|
[9] | 105 | }
|
---|
[16] | 106 | $pbrev = $ENV{'PBREVISION'};
|
---|
[22] | 107 | print $LOG "\n" if ($debug >= 0);
|
---|
[27] | 108 | print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);
|
---|
[9] | 109 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
[16] | 110 | # Clean up dest if necessary. The export will recreate it
|
---|
[27] | 111 | my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
|
---|
[9] | 112 | pbrm_rf($dest) if (-d $dest);
|
---|
| 113 |
|
---|
| 114 | # Export CMS tree for the concerned package to dest
|
---|
| 115 | # And generate some additional files
|
---|
| 116 | $OUTPUT_AUTOFLUSH=1;
|
---|
[29] | 117 |
|
---|
[9] | 118 | # computes in which dir we have to work
|
---|
[27] | 119 | my $dir = $defpkgdir{$pbpkg};
|
---|
| 120 | $dir = $extpkgdir{$pbpkg} if (not defined $dir);
|
---|
[29] | 121 | pbsystem("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null", "Exporting $ENV{'PBROOT'}/$dir... ");
|
---|
[9] | 122 |
|
---|
| 123 | # Creates a REVISION file
|
---|
| 124 | open(R,"> $dest/REVISION") || die "Unable to create $dest/REVISION";
|
---|
[16] | 125 | print R "$pbrev\n";
|
---|
[9] | 126 | close(R);
|
---|
| 127 |
|
---|
| 128 | # Extract cms log history and store it
|
---|
[29] | 129 | pbsystem("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}", "Extracting log info... ");
|
---|
| 130 |
|
---|
[21] | 131 | my %build;
|
---|
[11] | 132 | open(D,"$ENV{'PBCONF'}/DISTROS") || die "Unable to find $ENV{'PBCONF'}/DISTROS\n";
|
---|
| 133 | while (<D>) {
|
---|
| 134 | my $d = $_;
|
---|
| 135 | my ($dir,$ver) = split(/_/,$d);
|
---|
| 136 | chomp($ver);
|
---|
| 137 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver);
|
---|
[22] | 138 | print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1);
|
---|
| 139 | print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
|
---|
[13] | 140 |
|
---|
[16] | 141 | # Filter build files from the less precise up to the most with overloading
|
---|
[13] | 142 | # Filter all files found, keeping the name, and generating in dest
|
---|
[16] | 143 |
|
---|
| 144 | # Find all build files first relatively to PBROOT
|
---|
| 145 | my %bfiles;
|
---|
[27] | 146 | print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1);
|
---|
[21] | 147 | $build{"$ddir-$dver"} = "yes";
|
---|
[27] | 148 | if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") {
|
---|
| 149 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!";
|
---|
[16] | 150 | foreach my $f (readdir(BDIR)) {
|
---|
| 151 | next if ($f =~ /^\./);
|
---|
[27] | 152 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f";
|
---|
[16] | 153 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 154 | }
|
---|
[13] | 155 | closedir(BDIR);
|
---|
[27] | 156 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") {
|
---|
| 157 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!";
|
---|
[16] | 158 | foreach my $f (readdir(BDIR)) {
|
---|
| 159 | next if ($f =~ /^\./);
|
---|
[27] | 160 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f";
|
---|
[16] | 161 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 162 | }
|
---|
| 163 | closedir(BDIR);
|
---|
[27] | 164 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") {
|
---|
| 165 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!";
|
---|
[16] | 166 | foreach my $f (readdir(BDIR)) {
|
---|
| 167 | next if ($f =~ /^\./);
|
---|
[27] | 168 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f";
|
---|
[16] | 169 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 170 | }
|
---|
[13] | 171 | closedir(BDIR);
|
---|
[27] | 172 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") {
|
---|
| 173 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir-$dver: $!";
|
---|
[16] | 174 | foreach my $f (readdir(BDIR)) {
|
---|
| 175 | next if ($f =~ /^\./);
|
---|
[27] | 176 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f";
|
---|
[16] | 177 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 178 | }
|
---|
[13] | 179 | closedir(BDIR);
|
---|
| 180 | } else {
|
---|
[21] | 181 | $build{"$ddir-$dver"} = "no";
|
---|
[13] | 182 | next;
|
---|
| 183 | }
|
---|
[22] | 184 | print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
|
---|
[13] | 185 |
|
---|
[15] | 186 | # Get all filters to apply
|
---|
| 187 | # They're cumulative from less specific to most specific
|
---|
| 188 | # suffix is .pbf
|
---|
[16] | 189 | my @ffiles;
|
---|
| 190 | my ($ffile0, $ffile1, $ffile2, $ffile3);
|
---|
[27] | 191 | if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
|
---|
| 192 | $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
|
---|
| 193 | $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
|
---|
| 194 | $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
|
---|
| 195 | $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
|
---|
[16] | 196 | push @ffiles,$ffile0 if (defined $ffile0);
|
---|
| 197 | push @ffiles,$ffile1 if (defined $ffile1);
|
---|
| 198 | push @ffiles,$ffile2 if (defined $ffile2);
|
---|
| 199 | push @ffiles,$ffile3 if (defined $ffile3);
|
---|
| 200 | }
|
---|
| 201 | my $config = AppConfig->new({
|
---|
| 202 | # Auto Create variables mentioned in Conf file
|
---|
| 203 | CREATE => 1,
|
---|
| 204 | DEBUG => 0,
|
---|
| 205 | GLOBAL => {
|
---|
| 206 | # Each conf item is a hash
|
---|
| 207 | ARGCOUNT => AppConfig::ARGCOUNT_HASH
|
---|
| 208 | }
|
---|
| 209 | });
|
---|
[19] | 210 | my $ptr;
|
---|
[16] | 211 | if (@ffiles) {
|
---|
[22] | 212 | print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
|
---|
[16] | 213 | $config->file(@ffiles);
|
---|
[19] | 214 | $ptr = $config->get("filter");
|
---|
[22] | 215 | print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
|
---|
[19] | 216 | } else {
|
---|
| 217 | $ptr = { };
|
---|
| 218 | }
|
---|
[15] | 219 |
|
---|
[19] | 220 | # Apply now all the filters on all the files concerned
|
---|
| 221 | # All files are relative to PBROOT
|
---|
| 222 | # destination dir depends on the type of file
|
---|
| 223 | if (defined $ptr) {
|
---|
| 224 | foreach my $f (values %bfiles) {
|
---|
[27] | 225 | filter_file($f,$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$pbpkg,$dtype,$dsuf);
|
---|
[16] | 226 | }
|
---|
[19] | 227 | foreach my $f (keys %filteredfiles) {
|
---|
[27] | 228 | filter_file($f,$ptr,"$dest/$f",$pbpkg,$dtype,$dsuf);
|
---|
[19] | 229 | }
|
---|
[15] | 230 | }
|
---|
[18] | 231 | }
|
---|
[21] | 232 | if ($debug >= 0) {
|
---|
| 233 | my @found;
|
---|
| 234 | my @notfound;
|
---|
| 235 | foreach my $b (keys %build) {
|
---|
| 236 | push @found,$b if ($build{$b} =~ /yes/);
|
---|
| 237 | push @notfound,$b if ($build{$b} =~ /no/);
|
---|
| 238 | }
|
---|
[22] | 239 | print $LOG "Build files generated for ".join(',',@found)."\n";
|
---|
| 240 | print $LOG "No Build files found for ".join(',',@notfound)."\n";
|
---|
[21] | 241 | }
|
---|
[18] | 242 | close(D);
|
---|
| 243 | # Prepare the dest directory for archive
|
---|
[27] | 244 | if (-x "$ENV{'PBCONF'}/$pbpkg/pbpkginit") {
|
---|
[29] | 245 | pbsystem("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
|
---|
[11] | 246 | }
|
---|
[29] | 247 |
|
---|
[18] | 248 | # Archive dest dir
|
---|
[22] | 249 | chdir "$ENV{'PBDESTDIR'}";
|
---|
[25] | 250 | # Possibility to look at PBSRC to guess more the filename
|
---|
[29] | 251 | pbsystem("tar cfphz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files (gzip... ");
|
---|
[18] | 252 | if ($? == -1) {
|
---|
[22] | 253 | print $LOG "failed to execute: $!\n" if ($debug >= 0);
|
---|
[18] | 254 | } elsif ($? & 127) {
|
---|
[22] | 255 | printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);
|
---|
[18] | 256 | } else {
|
---|
[22] | 257 | print $LOG " OK)\n" if ($debug >= 0);
|
---|
[27] | 258 | print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
|
---|
[22] | 259 | # Keep track of what is generated for build2pkg default
|
---|
| 260 | open(LAST,"> $ENV{'PBDESTDIR'}/LAST") || die "Unable to create $ENV{'PBDESTDIR'}/LAST";
|
---|
| 261 | print LAST "$pbver-$pbtag\n";
|
---|
| 262 | close(LAST);
|
---|
[18] | 263 | }
|
---|
[9] | 264 | }
|
---|
[22] | 265 | } elsif ($action =~ /^build2pkg$/) {
|
---|
| 266 | # Check whether we have a specific version to build
|
---|
| 267 | my $vertag = shift @ARGV;
|
---|
| 268 | if (not defined $vertag) {
|
---|
| 269 | open(LAST,"$ENV{'PBDESTDIR'}/LAST") || die "Unable to open $ENV{'PBDESTDIR'}/LAST\nYou may want to precise as parameter version-tag";
|
---|
| 270 | $vertag = <LAST>;
|
---|
| 271 | chomp($vertag);
|
---|
| 272 | close(LAST);
|
---|
| 273 | }
|
---|
| 274 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 275 |
|
---|
| 276 | # Get list of packages to build
|
---|
| 277 | my $ptr = get_pkg();
|
---|
| 278 | @pkgs = @$ptr;
|
---|
| 279 |
|
---|
| 280 | # Get the running distro to build on
|
---|
[23] | 281 | my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init();
|
---|
[25] | 282 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $dsuf))."\n" if ($debug >= 1);
|
---|
[22] | 283 |
|
---|
[25] | 284 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
[27] | 285 | foreach my $pbpkg (@pkgs) {
|
---|
| 286 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
[25] | 287 | print $LOG "Handling source file $src\n" if ($debug >= 0);
|
---|
| 288 |
|
---|
| 289 | if ($dtype eq "rpm") {
|
---|
| 290 | # rpm has its own standard build directory
|
---|
[28] | 291 | my $tmp=`rpmquery --eval '%{_topdir}' 2> /dev/null`;
|
---|
| 292 | chomp($tmp);
|
---|
| 293 | $ENV{'PBBUILDDIR'}=$tmp;
|
---|
| 294 | print $LOG "Working under $ENV{'PBBUILDDIR'}\n" if ($debug >= 0);
|
---|
[25] | 295 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
[28] | 296 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
| 297 | pbmkdir_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";
|
---|
| 298 | }
|
---|
[25] | 299 | }
|
---|
| 300 |
|
---|
| 301 | # We need to first extract the spec file
|
---|
[28] | 302 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
| 303 | my @specfile;
|
---|
| 304 | @specfile = extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
|
---|
[25] | 305 |
|
---|
[28] | 306 | print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
|
---|
[25] | 307 | # set LANGUAGE to check for correct log messages
|
---|
| 308 | $ENV{'LANGUAGE'}="C";
|
---|
[28] | 309 | #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
|
---|
| 310 | foreach my $f (@specfile) {
|
---|
| 311 | if ($f =~ /\.spec$/) {
|
---|
[29] | 312 | pbsystem("rpmbuild -ba $f","Building package with $f... ");
|
---|
[28] | 313 | last;
|
---|
| 314 | }
|
---|
| 315 | }
|
---|
[25] | 316 | } elsif ($dtype eq "tgz") {
|
---|
| 317 | pbmkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
|
---|
| 318 | } elsif ($dtype eq "ebuild") {
|
---|
| 319 | pbmkdir_p("$ENV{'PBBUILDDIR'}/portage") if (! -d "$ENV{'PBBUILDDIR'}/portage");
|
---|
| 320 | } else {
|
---|
| 321 | }
|
---|
[22] | 322 | }
|
---|
[9] | 323 | } else {
|
---|
[22] | 324 | print $LOG "'$action' is not available\n";
|
---|
[21] | 325 | syntax();
|
---|
[9] | 326 | }
|
---|
[16] | 327 |
|
---|
[17] | 328 | # Function which applies filter on files
|
---|
[16] | 329 | sub filter_file {
|
---|
| 330 |
|
---|
| 331 | my $f=shift;
|
---|
| 332 | my $ptr=shift;
|
---|
| 333 | my %filter=%$ptr;
|
---|
| 334 | my $destfile=shift;
|
---|
[27] | 335 | my $pbpkg=shift;
|
---|
[17] | 336 | my $dtype=shift;
|
---|
| 337 | my $dsuf=shift;
|
---|
[16] | 338 |
|
---|
[22] | 339 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
[16] | 340 | pbmkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 341 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 342 | open(FILE,"$ENV{'PBROOT'}/$f") || die "Unable to open $f: $!";
|
---|
| 343 | while (<FILE>) {
|
---|
| 344 | my $line = $_;
|
---|
| 345 | foreach my $s (keys %filter) {
|
---|
| 346 | # Process single variables
|
---|
[22] | 347 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
|
---|
[16] | 348 | my $tmp = $filter{$s};
|
---|
| 349 | next if (not defined $tmp);
|
---|
| 350 | # Expand variables if any single one found
|
---|
| 351 | if ($tmp =~ /\$/) {
|
---|
| 352 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
[17] | 353 | # special case for ChangeLog
|
---|
[20] | 354 | } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
|
---|
[27] | 355 | my $p = $defpkgdir{$pbpkg};
|
---|
| 356 | $p = $extpkgdir{$pbpkg} if (not defined $p);
|
---|
| 357 | changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST);
|
---|
[20] | 358 | $tmp = "";
|
---|
[16] | 359 | }
|
---|
| 360 | $line =~ s|$s|$tmp|;
|
---|
| 361 | }
|
---|
| 362 | print DEST $line;
|
---|
[17] | 363 | }
|
---|
[16] | 364 | close(FILE);
|
---|
| 365 | close(DEST);
|
---|
| 366 | }
|
---|
[21] | 367 |
|
---|
[22] | 368 | sub get_pkg {
|
---|
| 369 |
|
---|
| 370 | my @pkgs;
|
---|
| 371 |
|
---|
| 372 | # Get packages list
|
---|
| 373 | if (not defined $ARGV[0]) {
|
---|
| 374 | @pkgs = keys %defpkgdir;
|
---|
| 375 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
| 376 | @pkgs = keys %defpkgdir;
|
---|
| 377 | if (defined %extpkgdir) {
|
---|
| 378 | my $k = keys %extpkgdir;
|
---|
| 379 | if (defined $k) {
|
---|
| 380 | push(@pkgs, keys %extpkgdir);
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 | } else {
|
---|
| 384 | @pkgs = @ARGV;
|
---|
| 385 | }
|
---|
| 386 | print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
|
---|
| 387 | return(\@pkgs);
|
---|
| 388 | }
|
---|
| 389 |
|
---|
[25] | 390 | sub extract_build_files {
|
---|
| 391 |
|
---|
| 392 | my $src=shift;
|
---|
| 393 | my $dir=shift;
|
---|
[26] | 394 | my $ddir=shift;
|
---|
[28] | 395 | my @files;
|
---|
[25] | 396 |
|
---|
[29] | 397 | pbsystem("tar xfz $src $dir >/dev/null","Extracting build files... ");
|
---|
[25] | 398 | opendir(DIR,"$dir") || die "Unable to open directory $dir";
|
---|
| 399 | foreach my $f (readdir(DIR)) {
|
---|
| 400 | next if ($f =~ /^\./);
|
---|
[26] | 401 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
[28] | 402 | print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
|
---|
| 403 | push @files,"$ddir/$f";
|
---|
[25] | 404 | }
|
---|
| 405 | closedir(DIR);
|
---|
[26] | 406 | # Not enough but still a first cleanup
|
---|
[25] | 407 | pbrm_rf("$dir");
|
---|
[28] | 408 | return(@files);
|
---|
[25] | 409 | }
|
---|
| 410 |
|
---|
[21] | 411 | sub syntax {
|
---|
| 412 |
|
---|
| 413 | print "Syntax: pb [-vhqt][-p project] <action> [<params>...]\n";
|
---|
| 414 | print "\n";
|
---|
| 415 | print "-h : This help file\n";
|
---|
| 416 | print "-q : Quiet mode\n";
|
---|
| 417 | print "-t : Test mode (not done yet)\n";
|
---|
| 418 | print "-v : Verbose mode\n";
|
---|
| 419 | print "\n";
|
---|
| 420 | print "-p project : Name of the project you're working on\n";
|
---|
| 421 | print " (or use the env variable PBPROJ) \n";
|
---|
| 422 | print "\n";
|
---|
| 423 | print "<action> can be:\n";
|
---|
| 424 | print "\n";
|
---|
| 425 | print "\tcms2build: Create a tar file of the project under your CMS\n";
|
---|
| 426 | print "\t CMS supported are SVN and CVS\n";
|
---|
[22] | 427 | print "\t parameters are packages to build\n";
|
---|
| 428 | print "\t if not using default list\n";
|
---|
[21] | 429 | print "\n";
|
---|
| 430 | print "\tbuild2pkg: Create packages for your running distribution \n";
|
---|
[22] | 431 | print "\t first parameter is version-tag to build\n";
|
---|
| 432 | print "\t if not using default version-tag\n";
|
---|
| 433 | print "\t following parameters are packages to build\n";
|
---|
| 434 | print "\t if not using default list\n";
|
---|
[21] | 435 | print "\n";
|
---|
| 436 | print "\n";
|
---|
| 437 | }
|
---|