Changes in / [20:30] in ProjectBuilder


Ignore:
Location:
/devel
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • /devel/pb/bin/pb.pl

    r20 r30  
    88# Provided under the GPL v2
    99
    10 # Syntax: pb [-p project] <action> [<params>...]
     10# Syntax: see at end
    1111
    1212use strict 'vars';
    13 use Switch;
    1413use Getopt::Std;
    1514use Data::Dumper;
     
    1716use AppConfig qw(:argcount :expand);
    1817use File::Basename;
    19 use Archive::Tar;
     18use File::Copy;
    2019use Time::localtime qw(localtime);
    2120use POSIX qw(strftime);
    2221
    23 use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles);
     22use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles $debug $LOG);
    2423%extpkgdir = ();
    2524%filteredfiles = ();
     25$debug = 0;                 # Debug level
     26$LOG = *STDOUT;             # Where to log
    2627use lib qw (lib);
    2728use common qw (env_init);
     
    4243my $pbdate = strftime("%Y-%m-%d", @date);
    4344
    44 getopts('p:t',\%opts);
    45 
     45getopts('hl:p:qtv',\%opts);
     46
     47if (defined $opts{'h'}) {
     48    syntax();
     49    exit(0);
     50}
     51if (defined $opts{'v'}) {
     52    $debug++;
     53}
     54if (defined $opts{'q'}) {
     55    $debug=-1;
     56}
     57if (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    }
    4662# Handles project name if any
    4763if (defined $opts{'p'}) {
     
    5975# Get Action
    6076$action = shift @ARGV;
    61 die "Syntax: pb [-p project] <action> [<params>...]" if (not defined $action);
    62 
    63 print "Project $ENV{'PBPROJ'}\n";
    64 #print "Action: $action - ARGV:".Dumper(\@ARGV);
     77die syntax() if (not defined $action);
     78
     79print $LOG "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);
     80print $LOG "Action: $action\n" if ($debug >= 0);
    6581
    6682# Act depending on action
    6783if ($action =~ /^cms2build$/) {
    68     print "Action: cms2build\n";
    69     # Get packages list
    70     if (not defined $ARGV[0]) {
    71         @pkgs = keys %defpkgdir;
    72     } elsif ($ARGV[0] =~ /^all$/) {
    73         @pkgs = keys %defpkgdir;
    74         if (defined %extpkgdir) {
    75             my $k = keys %extpkgdir;
    76             if (defined $k) {
    77                 push(@pkgs, keys %extpkgdir);
    78             }
    79         }
    80     } else {
    81         @pkgs = @ARGV;
    82     }
    83     print "Packages:\n";
    84     print Dumper(@pkgs);
     84    my $ptr = get_pkg();
     85    @pkgs = @$ptr;
    8586    cms_init();
    8687
    87     foreach my $pkg (@pkgs) {
    88 
    89         if (-f "$ENV{'PBROOT'}/$pkg/VERSION") {
    90             open(V,"$ENV{'PBROOT'}/$pkg/VERSION") || die "Unable to open $ENV{'PBROOT'}/$pkg/VERSION";
     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";
    9191            $pbver = <V>;
    9292            chomp($pbver);
     
    9696        }
    9797
    98         if (-f "$ENV{'PBROOT'}/$pkg/TAG") {
    99             open(T,"$ENV{'PBROOT'}/$pkg/TAG") || die "Unable to open $ENV{'PBROOT'}/$pkg/TAG";
     98        if (-f "$ENV{'PBROOT'}/$pbpkg/TAG") {
     99            open(T,"$ENV{'PBROOT'}/$pbpkg/TAG") || die "Unable to open $ENV{'PBROOT'}/$pbpkg/TAG";
    100100            $pbtag = <T>;
    101101            chomp($pbtag);
     
    105105        }
    106106        $pbrev = $ENV{'PBREVISION'};
    107         print "Management of $pkg $pbver-$pbtag (rev $pbrev)\n";
     107        print $LOG "\n" if ($debug >= 0);
     108        print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);
    108109        die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
    109110        # Clean up dest if necessary. The export will recreate it
    110         my $dest = "$ENV{'PBDESTDIR'}/$pkg-$pbver";
     111        my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
    111112        pbrm_rf($dest) if (-d $dest);
    112113
     
    114115        # And generate some additional files
    115116        $OUTPUT_AUTOFLUSH=1;
    116         print "$ENV{'PBCMSEXP'} of $pkg...";
     117
    117118        # computes in which dir we have to work
    118         my $dir = $defpkgdir{$pkg};
    119         $dir = $extpkgdir{$pkg} if (not defined $dir);
    120         system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null");
    121         if ($? == -1) {
    122             print "failed to execute: $!\n";
    123         } elsif ($? & 127) {
    124             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
    125         } else {
    126             print " Done under $dest\n";
    127         }
     119        my $dir = $defpkgdir{$pbpkg};
     120        $dir = $extpkgdir{$pbpkg} if (not defined $dir);
     121        pbsystem("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null", "Exporting $ENV{'PBROOT'}/$dir");
    128122
    129123        # Creates a REVISION file
     
    133127
    134128        # Extract cms log history and store it
    135         system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}");
    136         print "$ENV{'PBCMSLOG'} of $pkg...";
    137         if ($? == -1) {
    138             print "failed to execute: $!\n";
    139         } elsif ($? & 127) {
    140             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
    141         } else {
    142             print " OK\n";
    143         }
     129        pbsystem("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}", "Extracting log info");
     130
     131        my %build;
    144132        open(D,"$ENV{'PBCONF'}/DISTROS") || die "Unable to find $ENV{'PBCONF'}/DISTROS\n";
    145133        while (<D>) {
     
    147135            my ($dir,$ver) = split(/_/,$d);
    148136            chomp($ver);
    149             print "Generating build files for $dir ($ver)\n";
    150137            my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver);
    151             #print Dumper($ddir, $dver, $dfam, $dtype, $dsuf);
    152             #print "Filtering DDD => $pbdate, TTT => $pbtag, RRR => $pbtag$dsuf, VVV => $pbver\n";
     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);
    153140
    154141            # Filter build files from the less precise up to the most with overloading
     
    157144            # Find all build files first relatively to PBROOT
    158145            my %bfiles;
    159             #print "dir: $ENV{'PBCONF'}/$pkg\n";
    160             if (-d "$ENV{'PBCONF'}/$pkg/$dtype") {
    161                 opendir(BDIR,"$ENV{'PBCONF'}/$pkg/$dtype" || die "Unable to open dir $ENV{'PBCONF'}/$pkg/$dtype: $!");
     146            print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1);
     147            $build{"$ddir-$dver"} = "yes";
     148            if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") {
     149                opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!";
    162150                foreach my $f (readdir(BDIR)) {
    163151                    next if ($f =~ /^\./);
    164                     $bfiles{$f} = "$ENV{'PBCONF'}/$pkg/$dtype/$f";
     152                    $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f";
    165153                    $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
    166154                }
    167155                closedir(BDIR);
    168             } elsif (-d "$ENV{'PBCONF'}/$pkg/$dfam") {
    169                 opendir(BDIR,"$ENV{'PBCONF'}/$pkg/$dfam" || die "Unable to open dir $ENV{'PBCONF'}/$pkg/$dfam: $!");
     156            } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") {
     157                opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!";
    170158                foreach my $f (readdir(BDIR)) {
    171159                    next if ($f =~ /^\./);
    172                     $bfiles{$f} = "$ENV{'PBCONF'}/$pkg/$dfam/$f";
     160                    $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f";
    173161                    $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
    174162                }
    175163                closedir(BDIR);
    176             } elsif (-d "$ENV{'PBCONF'}/$pkg/$ddir") {
    177                 opendir(BDIR,"$ENV{'PBCONF'}/$pkg/$ddir" || die "Unable to open dir $ENV{'PBCONF'}/$pkg/$ddir: $!");
     164            } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") {
     165                opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!";
    178166                foreach my $f (readdir(BDIR)) {
    179167                    next if ($f =~ /^\./);
    180                     $bfiles{$f} = "$ENV{'PBCONF'}/$pkg/$ddir/$f";
     168                    $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f";
    181169                    $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
    182170                }
    183171                closedir(BDIR);
    184             } elsif (-d "$ENV{'PBCONF'}/$pkg/$ddir-$dver") {
    185                 opendir(BDIR,"$ENV{'PBCONF'}/$pkg/$ddir-$dver" || die "Unable to open dir $ENV{'PBCONF'}/$pkg/$ddir-$dver: $!");
     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: $!";
    186174                foreach my $f (readdir(BDIR)) {
    187175                    next if ($f =~ /^\./);
    188                     $bfiles{$f} = "$ENV{'PBCONF'}/$pkg/$ddir-$dver/$f";
     176                    $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f";
    189177                    $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
    190178                }
    191179                closedir(BDIR);
    192180            } else {
    193                 print "No Build Files found for $ddir-$dver\n";
     181                $build{"$ddir-$dver"} = "no";
    194182                next;
    195183            }
    196             print "bfiles: ".Dumper(\%bfiles)."\n";
     184            print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
    197185
    198186            # Get all filters to apply
     
    201189            my @ffiles;
    202190            my ($ffile0, $ffile1, $ffile2, $ffile3);
    203             if (-d "$ENV{'PBCONF'}/$pkg/pbfilter") {
    204                 $ffile0 = "$ENV{'PBCONF'}/$pkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pkg/pbfilter/$dtype.pbf");
    205                 $ffile1 = "$ENV{'PBCONF'}/$pkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pkg/pbfilter/$dfam.pbf");
    206                 $ffile2 = "$ENV{'PBCONF'}/$pkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pkg/pbfilter/$ddir.pbf");
    207                 $ffile3 = "$ENV{'PBCONF'}/$pkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pkg/pbfilter/$ddir-$dver.pbf");
     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");
    208196                push @ffiles,$ffile0 if (defined $ffile0);
    209197                push @ffiles,$ffile1 if (defined $ffile1);
     
    222210            my $ptr;
    223211            if (@ffiles) {
    224                 print "ffiles: ".Dumper(\@ffiles)."\n";
     212                print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
    225213                $config->file(@ffiles);
    226214                $ptr = $config->get("filter");
    227                 print "f:".Dumper($ptr)."\n";
     215                print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
    228216            } else {
    229217                $ptr = { };
     
    235223            if (defined $ptr) {
    236224                foreach my $f (values %bfiles) {
    237                     filter_file($f,$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$pkg,$dtype,$dsuf);
     225                    filter_file($f,$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$pbpkg,$dtype,$dsuf);
    238226                }
    239227                foreach my $f (keys %filteredfiles) {
    240                     filter_file($f,$ptr,"$dest/$f",$pkg,$dtype,$dsuf);
    241                 }
    242             }
     228                    filter_file($f,$ptr,"$dest/$f",$pbpkg,$dtype,$dsuf);
     229                }
     230            }
     231        }
     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            }
     239            print $LOG "Build files generated for ".join(',',@found)."\n";
     240            print $LOG "No Build files found for ".join(',',@notfound)."\n";
    243241        }
    244242        close(D);
    245243        # Prepare the dest directory for archive
    246         if (-x "$ENV{'PBCONF'}/$pkg/pbpkginit") {
    247             system("cd $dest ; $ENV{'PBCONF'}/$pkg/pbinit");
    248             if ($? == -1) {
    249                 print "failed to execute: $!\n";
    250             } elsif ($? & 127) {
    251                 printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
    252             } else {
    253                 print " $dest\n";
    254             }
    255         }
     244        if (-x "$ENV{'PBCONF'}/$pbpkg/pbpkginit") {
     245            pbsystem("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
     246        }
     247
    256248        # Archive dest dir
    257         chdir "$dest/..";
    258         print "Creating $pkg tar files (gzip... ";
    259         system("tar cfphz $pkg-$pbver.tar.gz $pkg-$pbver");
     249        chdir "$ENV{'PBDESTDIR'}";
     250        # Possibility to look at PBSRC to guess more the filename
     251        pbsystem("tar cfphz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
    260252        if ($? == -1) {
    261             print "failed to execute: $!\n";
     253            print $LOG "failed to execute: $!\n" if ($debug >= 0);
    262254        } elsif ($? & 127) {
    263             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
     255            printf $LOG "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
    264256        } else {
    265             print " OK)\n";
    266             print "Under $dest/../$pkg-$pbver.tar.gz\n";
     257            print $LOG " OK)\n" if ($debug >= 0);
     258            print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
     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);
     263        }
     264    }
     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
     281    my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init();
     282    print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $dsuf))."\n" if ($debug >= 1);
     283
     284    chdir "$ENV{'PBBUILDDIR'}";
     285    foreach my $pbpkg (@pkgs) {
     286        my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
     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
     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);
     295            foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
     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                }
     299            }
     300
     301            # We need to first extract the spec file
     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");
     305
     306            print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
     307            # set LANGUAGE to check for correct log messages
     308            $ENV{'LANGUAGE'}="C";
     309            #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
     310            foreach my $f (@specfile) {
     311                if ($f =~ /\.spec$/) {
     312                    pbsystem("rpmbuild -ba $f","Building package with $f");
     313                    last;
     314                }
     315            }
     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 {
    267321        }
    268322    }
    269323} else {
    270     print "'$action' is not available\n";
    271     print "Available actions are:\n";
    272     print "    cms2build\n";
     324    print $LOG "'$action' is not available\n";
     325    syntax();
    273326}
    274327
     
    280333my %filter=%$ptr;
    281334my $destfile=shift;
    282 my $pkg=shift;
     335my $pbpkg=shift;
    283336my $dtype=shift;
    284337my $dsuf=shift;
    285338
    286 print "From $f to $destfile\n";
     339print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
    287340pbmkdir_p(dirname($destfile)) if (! -d dirname($destfile));
    288341open(DEST,"> $destfile") || die "Unable to create $destfile";
     
    292345    foreach my $s (keys %filter) {
    293346        # Process single variables
    294         #print "debug: $filter{$s}\n";
     347        print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
    295348        my $tmp = $filter{$s};
    296349        next if (not defined $tmp);
     
    300353        # special case for ChangeLog
    301354        } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
    302             my $p = $defpkgdir{$pkg};
    303             $p = $extpkgdir{$pkg} if (not defined $p);
    304             changelog($dtype, $pkg, $pbtag, $dsuf, $p, \*DEST);
     355            my $p = $defpkgdir{$pbpkg};
     356            $p = $extpkgdir{$pbpkg} if (not defined $p);
     357            changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST);
    305358            $tmp = "";
    306359        }
     
    312365close(DEST);
    313366}
     367
     368sub get_pkg {
     369
     370my @pkgs;
     371
     372# Get packages list
     373if (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}
     386print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
     387return(\@pkgs);
     388}
     389
     390sub extract_build_files {
     391
     392my $src=shift;
     393my $dir=shift;
     394my $ddir=shift;
     395my @files;
     396
     397pbsystem("tar xfz $src $dir >/dev/null","Extracting build files");
     398opendir(DIR,"$dir") || die "Unable to open directory $dir";
     399foreach my $f (readdir(DIR)) {
     400    next if ($f =~ /^\./);
     401    move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
     402    print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
     403    push @files,"$ddir/$f";
     404}
     405closedir(DIR);
     406# Not enough but still a first cleanup
     407pbrm_rf("$dir");
     408return(@files);
     409}
     410
     411sub 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";
     427    print "\t           parameters are packages to build\n";
     428    print "\t           if not using default list\n";
     429    print "\n";
     430    print "\tbuild2pkg: Create packages for your running distribution  \n";
     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";
     435    print "\n";
     436    print "\n";
     437}
  • /devel/pb/lib/changelog.pm

    r20 r30  
    3434my $chglog = "$ENV{'PBROOT'}/$path/ChangeLog";
    3535if (! -f $chglog) {
    36     print "Unable to find the ChangeLog file ($chglog) for $pkg\n";
     36    print "Unable to find the ChangeLog file ($chglog) for $pkg\n" if ($debug >= 0);
    3737    return("\n");
    3838}
  • /devel/pb/lib/common.pm

    r20 r30  
    8989# Set delivery directory
    9090#
    91 $ENV{'PBTOPDIR'}="$ENV{'PBROOT'}/../delivery";
     91chdir "$ENV{'PBROOT'}/..";
     92my $path = `pwd`;
     93chomp($path);
     94$ENV{'PBTOPDIR'}=$path."/delivery";
    9295$ENV{'PBDESTDIR'}="$ENV{'PBTOPDIR'}/$ENV{'PBVER'}-$ENV{'PBTAG'}";
    93 pbrm_rf($ENV{'PBDESTDIR'}) if (-d "$ENV{'PBDESTDIR'}");
    94 pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
     96if (-d $ENV{'PBDESTDIR'}) {
     97    opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
     98    foreach my $d (readdir(DIR)) {
     99        next if ($d =~ /^\./);
     100        pbrm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
     101    }
     102    closedir(DIR);
     103}
     104if (! -d "$ENV{'PBDESTDIR'}") {
     105    pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
     106}
     107
     108#
     109# Set build directory
     110#
     111$ENV{'PBBUILDDIR'}=$path."/build";
     112pbrm_rf($ENV{'PBBUILDDIR'}) if (-d "$ENV{'PBBUILDDIR'}");
     113pbmkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
    95114
    96115umask 0022;
     
    99118
    100119sub pbmkdir_p {
    101     my @dir = @_;
    102     my $ret = mkpath(@dir, 0, 0755);
    103     return($ret);
     120my @dir = @_;
     121my $ret = mkpath(@dir, 0, 0755);
     122return($ret);
    104123}
    105124
    106125sub pbrm_rf {
    107     my @dir = @_;
    108     my $ret = rmtree(@dir, 0, 0);
    109     return($ret);
     126my @dir = @_;
     127my $ret = rmtree(@dir, 0, 0);
     128return($ret);
    110129}
    111130
     131sub pbsystem {
     132
     133my $cmd=shift;
     134my $cmt=shift || $cmd;
     135
     136print $LOG "$cmt... ";
     137system("$cmd");
     138if ($? == -1) {
     139    print $LOG "failed to execute: $!\n" if ($debug >= 0);
     140} elsif ($? & 127) {
     141    printf $LOG "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     142} else {
     143    print $LOG "OK\n" if ($debug >= 0);
     144}
     145}
    1121461;
  • /devel/pb/lib/distro.pm

    r20 r30  
    1010sub distro_init {
    1111
    12 my $ddir = shift;
    13 my $dver = shift;
     12my $ddir = shift || undef;
     13my $dver = shift || undef;
    1414my $dfam = "unknown";
    1515my $dtype = "unknown";
     
    1717
    1818# If we don't know which distribution we're on, then guess it
    19 ($ddir, $dver) = distro_get() if ((not defined $ddir) || (not defined $dver));
     19($ddir,$dver) = get_distro() if ((not defined $ddir) || (not defined $dver));
    2020
    2121# There shold be unicity of names between ddir dfam and dtype
     
    8282}
    8383
    84 sub distro_get {
     84sub get_distro {
     85
     86# Cf: http://linuxmafia.com/faq/Admin/release-files.html
     87# Ideas taken from
     88# http://search.cpan.org/~kerberus/Linux-Distribution-0.14/lib/Linux/Distribution.pm
     89
     90my $base="/etc";
     91
     92# List of files that unambiguously indicates what distro we have
     93my %single_rel_files = (
     94# Tested
     95    'gentoo'            =>  'gentoo-release',       # >= 1.6
     96    'debian'            =>  'debian_version',       # >= 3.1
     97    'slackware'         =>  'slackware-version',    # >= 10.2
     98    'mandriva'          =>  'mandriva-release',     # >=2006.0
     99    'fedora'            =>  'fedora-release',       # >= 4
     100    'sles'              =>  'sles-release',         # ???
     101# Untested
     102    'knoppix'           =>  'knoppix_version',      #
     103    'yellowdog'         =>  'yellowdog-release',    #
     104    'esmith'            =>  'e-smith-release',      #
     105    'turbolinux'        =>  'turbolinux-release',   #
     106    'blackcat'          =>  'blackcat-release',     #
     107    'aurox'             =>  'aurox-release',        #
     108    'annvix'            =>  'annvix-release',       #
     109    'cobalt'            =>  'cobalt-release',       #
     110    'redflag'           =>  'redflag-release',      #
     111    'ark'               =>  'ark-release',          #
     112    'pld'               =>  'pld-release',          #
     113    'nld'               =>  'nld-release',          #
     114    'lfs'               =>  'lfs-release',          #
     115    'mk'                =>  'mk-release',           #
     116    'conectiva'         =>  'conectiva-release',    #
     117    'immunix'           =>  'immunix-release',      #
     118    'tinysofa'          =>  'tinysofa-release',     #
     119    'trustix'           =>  'trustix-release',      #
     120    'adamantix'         =>  'adamantix_version',    #
     121    'yoper'             =>  'yoper-release',        #
     122    'arch'              =>  'arch-release',         #
     123    'libranet'          =>  'libranet_version',     #
     124    'valinux'           =>  'va-release',           #
     125    'yellowdog'         =>  'yellowdog-release',    #
     126    'ultrapenguin'      =>  'ultrapenguin-release', #
     127    );
     128
     129# List of files that ambiguously indicates what distro we have
     130my %ambiguous_rel_files = (
     131    'mandrake'          =>  'mandrake-release',     # >= 10.1
     132    'suse'              =>  'SuSE-release',         # >= 10.0
     133    'redhat'            =>  'redhat-release',       # >= 7.3
     134    'lsb'               =>  'lsb-release',          # ???
     135    );
     136
     137# Should have the same keys as the previous one.
     138# If ambiguity, which other distributions should be checked
     139my %distro_similar = (
     140    'mandrake'          => ['mandrake'],
     141    'suse'              => ['suse', 'sles'],
     142    'redhat'            => ['redhat', 'rhel', 'centos', 'mandrake'],
     143    'lsb'               => ['ubuntu', 'debian', 'lsb'],
     144    );
     145
     146my %distro_match = (
     147# Tested
     148    'gentoo'                => '.* version (.+)',
     149    'debian'                => '([^/]+)[/]*.*',
     150    'slackware'             => 'S[^ ]* (.+)$',
     151# There should be no ambiguity between potential ambiguous distro
     152    'mandrake'              => 'Mandr[^ ]* release (.+) \(',
     153    'mandriva'              => 'Mandr[^ ]* [^ ]* release (.+) \(',
     154    'fedora'                => 'Fedora .*release (\d+) \(',
     155    'rhel'                  => 'Red Hat Enterprise Linux .*release (.+) \(',
     156    'centos'                => '.*CentOS .*release (.+) ',
     157    'redhat'                => 'Red Hat Linux release (.+) \(',
     158    'sles'                  => '.* Enterprise .*\nVERSION = (.+)',
     159    'suse'                  => '.* [^Enterpis] .*\nVERSION = (.+)',
     160    'lsb'                   => '.*[^Ubunt].*\nDISTRIB_RELEASE=(.+)',
     161    'ubuntu'                => '.*Ubuntu.*\nDISTRIB_RELEASE=(.+)',
     162# Not tested
     163    'arch'                  => '.* ([0-9.]+) .*',
     164    'redflag'               => 'Red Flag (?:Desktop|Linux) (?:release |\()(.*?)(?: \(.+)?\)',
     165);
     166
     167my $release;
     168my $distro;
     169
     170# Begin to test presence of non-amiguous files
     171# that way we reduce the choice
     172my ($d,$r);
     173while (($d,$r) = each %single_rel_files) {
     174    if (-f "$base/$r" && !-l "$base/$r") {
     175        my $tmp=get_content("$base/$r");
     176        # Found the only possibility.
     177        # Try to get version and return
     178        if (defined ($distro_match{$d})) {
     179            ($release) = $tmp =~ m/$distro_match{$d}/m;
     180        } else {
     181            print STDERR "Unable to find $d version in $r\n";
     182            print STDERR "Please report to the maintainer bruno_at_project-builder.org\n";
     183            $release = "unknown";
     184        }
     185        return($d,$release);
     186    }
     187}
     188
     189while (($d,$r) = each %ambiguous_rel_files) {
     190    if (-f "$base/$r" && !-l "$base/$r"){
     191        # Found one possibility.
     192        # Get all distros concerned by that file
     193        my $tmp=get_content("$base/$r");
     194        my $found = 0;
     195        my $ptr = $distro_similar{$d};
     196        print $LOG "amb: ".Dumper($ptr)."\n" if ($debug >= 1);
     197        $release = "unknown";
     198        foreach my $dd (@$ptr) {
     199            print $LOG "check $dd\n" if ($debug >= 1);
     200            # Try to check pattern
     201            if (defined $distro_match{$dd}) {
     202                print $LOG "cmp: $distro_match{$dd} - vs - $tmp\n" if ($debug >= 1);
     203                ($release) = $tmp =~ m/$distro_match{$dd}/m;
     204                if ((defined $release) && ($release ne "unknown")) {
     205                    $distro = $dd;
     206                    $found = 1;
     207                    last;
     208                }
     209            }
     210        }
     211        if ($found == 0) {
     212            print STDERR "Unable to find $d version in $r\n";
     213            print STDERR "Please report to the maintainer bruno_at_project-builder.org\n";
     214            $release = "unknown";
     215        } else {
     216            return($distro,$release);
     217        }
     218    }
     219}
     220return("unknown","unknown");
     221}
     222
     223sub get_content {
     224
     225my $file=shift;
     226
     227my $bkp = $/;
     228undef $/;
     229open(R,$file) || die "Unable to open $file: $!";
     230my $content=<R>;
     231close(R);
     232chomp($content);
     233$/ = $bkp;
     234return($content);
    85235}
    862361;
  • /devel/pb/lib/pb.pm

    r20 r30  
    1414my $conffile = shift;
    1515my $ptr;
     16my $trace;
     17
     18if ($debug > 0) {
     19    $trace = 1;
     20} else {
     21    $trace = 0;
     22}
    1623
    1724my $config = AppConfig->new({
    1825                            # Auto Create variables mentioned in Conf file
    1926                            CREATE => 1,
    20                             DEBUG => 1,
     27                            DEBUG => $trace,
    2128                            GLOBAL => {
    2229                                # Each conf item is a hash
     
    3441$ptr = $config->get("confparam") || die "Unable to find confparam in $conffile";
    3542%confparam = %$ptr;
    36 print "confparam: ".Dumper($ptr)."\n";
     43print "DEBUG: confparam: ".Dumper($ptr)."\n" if ($debug >= 1);
    3744
    3845# List of pkg to build by default (mandatory)
    3946$ptr = $config->get("defpkgdir") || die "Unable to find defpkgdir in $conffile";
    4047%defpkgdir = %$ptr;
    41 print "defpkgdir: ".Dumper($ptr)."\n";
     48print "DEBUG: defpkgdir: ".Dumper($ptr)."\n" if ($debug >= 1);
    4249
    4350# List of additional pkg to build when all is called (optional)
    4451$ptr = $config->get("extpkgdir");
    45 print "extpkgdir1: ".Dumper($ptr)."\n";
     52print "DEBUG: extpkgdir1: ".Dumper($ptr)."\n" if ($debug >= 1);
    4653if (not defined $ptr) {
    4754    %extpkgdir = ();
     
    4956    %extpkgdir = %$ptr;
    5057}
    51 print "extpkgdir: ".Dumper(\%extpkgdir)."\n";
     58print "DEBUG: extpkgdir: ".Dumper(\%extpkgdir)."\n" if ($debug >= 1);
    5259
    5360# Valid version names (optional)
     
    5865    %version = %$ptr;
    5966}
    60 print "version: ".Dumper(\%version)."\n";
     67print "DEBUG: version: ".Dumper(\%version)."\n" if ($debug >= 1);
    6168
    6269# List of files to filter (optional)
     
    6774    %filteredfiles = %$ptr;
    6875}
    69 print "filteredfiles: ".Dumper(\%filteredfiles)."\n";
     76print "DEBUG: filteredfiles: ".Dumper(\%filteredfiles)."\n" if ($debug >= 1);
    7077
    7178}
  • /devel/pbconf/pb.pb

    r20 r30  
    1818
    1919# Hash of default package/package directory
    20 defpkgdir projectbuilder = pb
    21 defpkgdir projectbuilder-doc = pb-doc
     20defpkgdir project-builder = pb
    2221
    2322# Hash of additional package/package directory
    24 #extpkgdir pkg1 = dir1
     23extpkgdir project-builder-doc = pb-doc
    2524
    2625# Hash of valid version names
  • /devel/pbconf/projectbuilder/pbfilter/rh.pbf

    r20 r30  
    2727# PBREV is replaced by the revision ($pbrev in code)
    2828filter PBREV = $pbrev
     29
     30# PBPKG is replaced by the package name ($pbpkg in code)
     31filter PBPKG = $pbpkg
  • /devel/pbconf/projectbuilder/rpm/pb.spec

    r20 r30  
    66Summary(fr):    Project Builder ou pb est un programme pour produire des paquets pour diverses distributions
    77
    8 Name:       pb
     8Name:       PBPKG
    99Version:    PBVER
    1010Release:    PBTAG
     
    1414Source:     PBSRC
    1515BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
    16 BuildRequires: 
     16BuildArch:  noarch
    1717Requires:   perl >= 5.8.8, PBDEP
    1818
Note: See TracChangeset for help on using the changeset viewer.