Changeset 9


Ignore:
Timestamp:
Jul 30, 2007, 1:22:32 AM (11 years ago)
Author:
bruno
Message:

cms2build begins to export

Location:
devel/pb
Files:
4 edited

Legend:

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

    r8 r9  
    88# Provided under the GPL v2
    99
     10# Syntax: pb [-p project] <action> [<params>...]
     11
    1012use strict;
    1113use Switch;
    1214use Getopt::Std;
     15use Data::Dumper;
     16use English;
    1317
    1418use lib qw (lib etc);
    1519use vars qw (%defpkgdir %extpkgdir %version);
    16 use common qw (set_env);
     20use common qw (env_init);
    1721use pb qw (defpkgdir extpkgdir version pb_init);
    1822use cms;
    1923
    2024my %opts;                   # CLI Options
     25my $action;                 # action to realize
     26my $test = "FALSE";
     27my $option = "";
     28my @pkgs;
    2129
    22 getopts('p:',\%opts);
     30getopts('p:t',\%opts);
    2331
    2432# Handles project name if any
    2533if (defined $opts{'p'}) {
    26     $ENV{'PBPROJ'} = set_env($opts{'p'});
     34    $ENV{'PBPROJ'} = env_init($opts{'p'});
    2735} else {
    28     $ENV{'PBPROJ'} = set_env();
     36    $ENV{'PBPROJ'} = env_init();
     37}
     38# Handles test option
     39if (defined $opts{'t'}) {
     40    $test = "TRUE";
     41    # Works only for SVN
     42    $option = "-r BASE";
    2943}
    3044
    31 print "PBPROJ: $ENV{'PBPROJ'}\n";
     45# Get Action
     46$action = shift @ARGV;
     47die "Syntax: pb [-p project] <action> [<params>...]" if (not defined $action);
    3248
    33 cms_init();
     49print "Project $ENV{'PBPROJ'}\n";
     50#print "Action: $action - ARGV:".Dumper(\@ARGV);
     51
     52# Act depending on action
     53if ($action =~ /^cms2build$/) {
     54    print "Action: cms2build\n";
     55    # Get packages list
     56    if (not defined $ARGV[0]) {
     57        @pkgs = keys %defpkgdir;
     58    } elsif ($ARGV[0] =~ /^all$/) {
     59        @pkgs = keys %defpkgdir;
     60        push(@pkgs, keys %extpkgdir);
     61    } else {
     62        @pkgs = @ARGV;
     63    }
     64    print "Packages:\n";
     65    print Dumper(@pkgs);
     66    cms_init();
     67
     68    foreach my $p (@pkgs) {
     69
     70        my $v;
     71
     72        if (-f "$ENV{'PBROOT'}/$p/VERSION") {
     73            open(V,"$ENV{'PBROOT'}/$p/VERSION") || die "Unable to open $ENV{'PBROOT'}/$p/VERSION";
     74            $v = <V>;
     75            chomp($v);
     76            close(V);
     77        } else {
     78            $v = $ENV{'PBVER'};
     79        }
     80
     81        my $tag;
     82
     83        if (-f "$ENV{'PBROOT'}/$p/TAG") {
     84            open(T,"$ENV{'PBROOT'}/$p/TAG") || die "Unable to open $ENV{'PBROOT'}/$p/TAG";
     85            $tag = <T>;
     86            chomp($tag);
     87            close(T);
     88        } else {
     89            $tag = $ENV{'PBTAG'};
     90        }
     91        print "Management of $p $v-$tag (rev $ENV{'PBREVISION'})\n";
     92        die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
     93        # Clean up dest if necessary
     94        my $dest = "$ENV{'PBDESTDIR'}/$p-$v";
     95        pbrm_rf($dest) if (-d $dest);
     96
     97        # Export CMS tree for the concerned package to dest
     98        # And generate some additional files
     99        $OUTPUT_AUTOFLUSH=1;
     100        print "$ENV{'PBCMSEXP'} of $p...";
     101        # computes in which dir we have to work
     102        my $dir = $defpkgdir{$p};
     103        $dir = $extpkgdir{$p} if (not defined $dir);
     104        system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null");
     105        if ($? == -1) {
     106            print "failed to execute: $!\n";
     107        } elsif ($? & 127) {
     108            printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
     109        } else {
     110            print " Done under $dest\n";
     111        }
     112
     113        # Creates a REVISION file
     114        open(R,"> $dest/REVISION") || die "Unable to create $dest/REVISION";
     115        print R "$ENV{'PBREVISION'}\n";
     116        close(R);
     117
     118        # Extract cms log history and store it
     119        system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}");
     120        print "$ENV{'PBCMSLOG'} of $p...";
     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 " OK\n";
     127        }
     128    }
     129} else {
     130    print "'$action' is not available\n";
     131    print "Available actions are:\n";
     132    print "    cms2build\n";
     133}
  • devel/pb/etc/pb.pb

    r8 r9  
    1818
    1919# Hash of additional package/package directory
    20 extpkgdir "" = ""
     20#extpkgdir pkg1 = dir1
    2121
    2222# Hash of valid version names
  • devel/pb/lib/cms.pm

    r8 r9  
    2727    if ($ret == 0) {
    2828        $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
     29        chomp($ENV{'PBREVISION'});
    2930        $ENV{'PBCMSLOG'}="svn log";
     31        $ENV{'PBCMSLOGFILE'}="svn.log";
    3032        $ENV{'PBCMSEXP'}="svn export";
    3133    } else {
    3234        # By default if not SVN take CVS
    3335        $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate  -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
     36        chomp($ENV{'PBREVISION'});
    3437        $ENV{'PBCMSLOG'}="cvs log";
     38        $ENV{'PBCMSLOGFILE'}="cvs.log";
    3539        $ENV{'PBCMSEXP'}="cvs export"
    3640    }
  • devel/pb/lib/common.pm

    r8 r9  
    77require Exporter;
    88@ISA = qw(Exporter);
    9 @EXPORT = qw(set_env);
     9@EXPORT = qw(env_init);
    1010
    1111use lib qw (lib);
     
    1313use strict;
    1414use File::Basename;
    15 use ExtUtils::Command;
     15use File::Path;
    1616use File::Temp qw /tempdir/;
    1717use vars qw (%defpkgdir %extpkgdir %version);
     
    2020$ENV{'PBCONF'} = "/etc/pb";
    2121
    22 sub set_env {
     22sub env_init {
    2323
    2424my $proj=shift;
     
    8585#
    8686$ENV{'PBTOPDIR'}="$ENV{'PBROOT'}/../delivery";
    87 $ENV{'PBDESTDIR'}=$ENV{'PBTOPDIR'}."/".$ENV{'PBVER'}."-".$ENV{'PBTAG'};
    88 mkpath $ENV{'PBDESTDIR'};
     87$ENV{'PBDESTDIR'}="$ENV{'PBTOPDIR'}/$ENV{'PBVER'}-$ENV{'PBTAG'}";
     88pbrm_rf($ENV{'PBDESTDIR'}) if (-d "$ENV{'PBDESTDIR'}");
     89pbmkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
    8990
    9091umask 0022;
    9192return($proj);
    9293}
     94
     95sub pbmkdir_p {
     96    my @dir = @_;
     97    my $ret = mkpath(@dir, 0, 0755);
     98    return($ret);
     99}
     100
     101sub pbrm_rf {
     102    my @dir = @_;
     103    my $ret = rmtree(@dir, 0, 0);
     104    return($ret);
     105}
     106
    931071;
Note: See TracChangeset for help on using the changeset viewer.