Changeset 22


Ignore:
Timestamp:
Jul 31, 2007, 1:11:01 PM (12 years ago)
Author:
bruno
Message:

Begin to work on pkg2build
Cope the module Linux::Distribution in the project as it's not packages for my distro
Will make delivery much easier.

Location:
devel/pb
Files:
1 added
3 edited

Legend:

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

    r21 r22  
    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;
    2018use Time::localtime qw(localtime);
    2119use POSIX qw(strftime);
    2220
    23 use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles $debug);
     21use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles $debug $LOG);
    2422%extpkgdir = ();
    2523%filteredfiles = ();
    2624$debug = 0;                 # Debug level
     25$LOG = *STDOUT;             # Where to log
    2726use lib qw (lib);
    2827use common qw (env_init);
     
    4342my $pbdate = strftime("%Y-%m-%d", @date);
    4443
    45 getopts('hp:qtv',\%opts);
     44getopts('hl:p:qtv',\%opts);
    4645
    4746if (defined $opts{'h'}) {
     
    5554    $debug=-1;
    5655}
     56if (defined $opts{'l'}) {
     57    open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
     58    $LOG = *LOG;
     59    $debug = 0  if ($debug == -1);
     60    }
    5761# Handles project name if any
    5862if (defined $opts{'p'}) {
     
    7276die syntax() if (not defined $action);
    7377
    74 print "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);
    75 print "Action: $action\n" if ($debug >= 0);
     78print $LOG "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);
     79print $LOG "Action: $action\n" if ($debug >= 0);
    7680
    7781# Act depending on action
    7882if ($action =~ /^cms2build$/) {
    79     # Get packages list
    80     if (not defined $ARGV[0]) {
    81         @pkgs = keys %defpkgdir;
    82     } elsif ($ARGV[0] =~ /^all$/) {
    83         @pkgs = keys %defpkgdir;
    84         if (defined %extpkgdir) {
    85             my $k = keys %extpkgdir;
    86             if (defined $k) {
    87                 push(@pkgs, keys %extpkgdir);
    88             }
    89         }
    90     } else {
    91         @pkgs = @ARGV;
    92     }
    93     print "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
     83    my $ptr = get_pkg();
     84    @pkgs = @$ptr;
    9485    cms_init();
    9586
    9687    foreach my $pkg (@pkgs) {
    97 
    9888        if (-f "$ENV{'PBROOT'}/$pkg/VERSION") {
    9989            open(V,"$ENV{'PBROOT'}/$pkg/VERSION") || die "Unable to open $ENV{'PBROOT'}/$pkg/VERSION";
     
    114104        }
    115105        $pbrev = $ENV{'PBREVISION'};
    116         print "\n" if ($debug >= 0);
    117         print "Management of $pkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);
     106        print $LOG "\n" if ($debug >= 0);
     107        print $LOG "Management of $pkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);
    118108        die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
    119109        # Clean up dest if necessary. The export will recreate it
     
    124114        # And generate some additional files
    125115        $OUTPUT_AUTOFLUSH=1;
    126         print "$ENV{'PBCMSEXP'} of $pkg..." if ($debug >= 0);
     116        print $LOG "$ENV{'PBCMSEXP'} of $pkg..." if ($debug >= 0);
    127117        # computes in which dir we have to work
    128118        my $dir = $defpkgdir{$pkg};
     
    130120        system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null");
    131121        if ($? == -1) {
    132             print "failed to execute: $!\n" if ($debug >= 0);
     122            print $LOG "failed to execute: $!\n" if ($debug >= 0);
    133123        } elsif ($? & 127) {
    134             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
    135         } else {
    136             print " OK\n" if ($debug >= 0);
     124            printf $LOG "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     125        } else {
     126            print $LOG " OK\n" if ($debug >= 0);
    137127        }
    138128
     
    144134        # Extract cms log history and store it
    145135        system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}");
    146         print "$ENV{'PBCMSLOG'} of $pkg..." if ($debug >= 0);
     136        print $LOG "$ENV{'PBCMSLOG'} of $pkg..." if ($debug >= 0);
    147137        if ($? == -1) {
    148             print "failed to execute: $!\n" if ($debug >= 0);
     138            print $LOG "failed to execute: $!\n" if ($debug >= 0);
    149139        } elsif ($? & 127) {
    150             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
    151         } else {
    152             print " OK\n" if ($debug >= 0);
     140            printf $LOG "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     141        } else {
     142            print $LOG " OK\n" if ($debug >= 0);
    153143        }
    154144        my %build;
     
    159149            chomp($ver);
    160150            my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver);
    161             print "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1);
    162             print "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
     151            print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1);
     152            print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
    163153
    164154            # Filter build files from the less precise up to the most with overloading
     
    167157            # Find all build files first relatively to PBROOT
    168158            my %bfiles;
    169             print "DEBUG dir: $ENV{'PBCONF'}/$pkg\n" if ($debug >= 1);
     159            print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pkg\n" if ($debug >= 1);
    170160            $build{"$ddir-$dver"} = "yes";
    171161            if (-d "$ENV{'PBCONF'}/$pkg/$dtype") {
     
    205195                next;
    206196            }
    207             print "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
     197            print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
    208198
    209199            # Get all filters to apply
     
    233223            my $ptr;
    234224            if (@ffiles) {
    235                 print "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
     225                print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
    236226                $config->file(@ffiles);
    237227                $ptr = $config->get("filter");
    238                 print "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
     228                print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
    239229            } else {
    240230                $ptr = { };
     
    260250                push @notfound,$b if ($build{$b} =~ /no/);
    261251            }
    262             print "Build files generated for ".join(',',@found)."\n";
    263             print "No Build files found for ".join(',',@notfound)."\n";
     252            print $LOG "Build files generated for ".join(',',@found)."\n";
     253            print $LOG "No Build files found for ".join(',',@notfound)."\n";
    264254        }
    265255        close(D);
    266256        # Prepare the dest directory for archive
    267257        if (-x "$ENV{'PBCONF'}/$pkg/pbpkginit") {
     258            print $LOG " Executing $ENV{'PBCONF'}/$pkg/pbinit...\n" if ($debug >= 0);
    268259            system("cd $dest ; $ENV{'PBCONF'}/$pkg/pbinit");
    269260            if ($? == -1) {
    270                 print "failed to execute: $!\n" if ($debug >= 0);
     261                print $LOG "failed to execute: $!\n" if ($debug >= 0);
    271262            } elsif ($? & 127) {
    272                 printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     263                printf $LOG "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
    273264            } else {
    274                 print " $dest\n" if ($debug >= 0);
     265                print $LOG " OK\n" if ($debug >= 0);
    275266            }
    276267        }
    277268        # Archive dest dir
    278         chdir "$dest/..";
    279         print "Creating $pkg tar files (gzip... " if ($debug >= 0);
     269        chdir "$ENV{'PBDESTDIR'}";
     270        print $LOG "Creating $pkg tar files (gzip... " if ($debug >= 0);
    280271        system("tar cfphz $pkg-$pbver.tar.gz $pkg-$pbver");
    281272        if ($? == -1) {
    282             print "failed to execute: $!\n" if ($debug >= 0);
     273            print $LOG "failed to execute: $!\n" if ($debug >= 0);
    283274        } elsif ($? & 127) {
    284             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
    285         } else {
    286             print " OK)\n" if ($debug >= 0);
    287             print "Under $dest/../$pkg-$pbver.tar.gz\n" if ($debug >= 0);
    288         }
     275            printf $LOG "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     276        } else {
     277            print $LOG " OK)\n" if ($debug >= 0);
     278            print $LOG "Under $ENV{'PBDESTDIR'}/$pkg-$pbver.tar.gz\n" if ($debug >= 0);
     279            # Keep track of what is generated for build2pkg default
     280            open(LAST,"> $ENV{'PBDESTDIR'}/LAST") || die "Unable to create $ENV{'PBDESTDIR'}/LAST";
     281            print LAST "$pbver-$pbtag\n";
     282            close(LAST);
     283        }
     284    }
     285} elsif ($action =~ /^build2pkg$/) {
     286    # Check whether we have a specific version to build
     287    my $vertag = shift @ARGV;
     288    if (not defined $vertag) {
     289        open(LAST,"$ENV{'PBDESTDIR'}/LAST") || die "Unable to open $ENV{'PBDESTDIR'}/LAST\nYou may want to precise as parameter version-tag";
     290        $vertag = <LAST>;
     291        chomp($vertag);
     292        close(LAST);
     293    }
     294    ($pbver,$pbtag) = split(/-/,$vertag);
     295
     296    # Get list of packages to build
     297    my $ptr = get_pkg();
     298    @pkgs = @$ptr;
     299
     300    # Get the running distro to build on
     301
     302    foreach my $pkg (@pkgs) {
    289303    }
    290304} else {
    291     print "'$action' is not available\n";
     305    print $LOG "'$action' is not available\n";
    292306    syntax();
    293307}
     
    304318my $dsuf=shift;
    305319
    306 print "DEBUG: From $f to $destfile\n" if ($debug >= 1);
     320print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
    307321pbmkdir_p(dirname($destfile)) if (! -d dirname($destfile));
    308322open(DEST,"> $destfile") || die "Unable to create $destfile";
     
    312326    foreach my $s (keys %filter) {
    313327        # Process single variables
    314         print "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
     328        print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
    315329        my $tmp = $filter{$s};
    316330        next if (not defined $tmp);
     
    333347}
    334348
     349sub get_pkg {
     350
     351my @pkgs;
     352
     353# Get packages list
     354if (not defined $ARGV[0]) {
     355    @pkgs = keys %defpkgdir;
     356} elsif ($ARGV[0] =~ /^all$/) {
     357    @pkgs = keys %defpkgdir;
     358    if (defined %extpkgdir) {
     359        my $k = keys %extpkgdir;
     360        if (defined $k) {
     361            push(@pkgs, keys %extpkgdir);
     362        }
     363    }
     364} else {
     365    @pkgs = @ARGV;
     366}
     367print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
     368return(\@pkgs);
     369}
     370
    335371sub syntax {
    336372
     
    349385    print "\tcms2build: Create a tar file of the project under your CMS\n";
    350386    print "\t           CMS supported are SVN and CVS\n";
     387    print "\t           parameters are packages to build\n";
     388    print "\t           if not using default list\n";
    351389    print "\n";
    352390    print "\tbuild2pkg: Create packages for your running distribution  \n";
    353     print "\n";
    354     print "\n";
    355 }
     391    print "\t           first parameter is version-tag to build\n";
     392    print "\t           if not using default version-tag\n";
     393    print "\t           following parameters are packages to build\n";
     394    print "\t           if not using default list\n";
     395    print "\n";
     396    print "\n";
     397}
  • devel/pb/lib/distro.pm

    r18 r22  
    77
    88use strict;
     9use LinuxDistribution qw (distribution_name distribution_version);
    910
    1011sub distro_init {
     
    1718
    1819# 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));
     20$ddir = distribution_name() if (not defined $ddir);
     21$dver = distribution_version() if (not defined $dver);
    2022
    2123# There shold be unicity of names between ddir dfam and dtype
     
    8183return($ddir, $dver, $dfam, $dtype, $dsuf);
    8284}
    83 
    84 sub distro_get {
    85 }
    86851;
  • devel/pb/lib/pb.pm

    r21 r22  
    1616my $trace;
    1717
    18 if ($debug >= 0) {
     18if ($debug > 0) {
    1919    $trace = 1;
    2020} else {
Note: See TracChangeset for help on using the changeset viewer.