Changeset 108


Ignore:
Timestamp:
Sep 6, 2007, 2:18:18 AM (12 years ago)
Author:
bruno
Message:

Lots of changes to prepare the dev of the VMs support.
No more global variables
Support $ENV{'HOME'} in pbrc for pbrc keyword (allows portability across accounts and share of .pbrc)
Fixes on pb_cms_export for SVN in order to be called externally
pn_env_init retunrs now a lot of params in a list
pb_get_pkg needs params and is simplified by consequence
pbinit is called with a simple system. pb_system has isues with cascading stdout/stderr redirections
pb_send2ssh now supports sending to VM + launch of a pbscript if it exists and it should bring back packages from VM in the future and it now supports more parameters.

Location:
devel/pb
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r107 r108  
    2121
    2222# Global variables
    23 use vars qw (%defpkgdir %extpkgdir %filteredfiles %pbrc $debug $LOG);
    24 
    2523use lib qw (lib);
    2624use ProjectBuilder::Distribution qw (pb_distro_init);
     
    4139my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
    4240my $pbdate = strftime("%Y-%m-%d", @date);
     41my $debug = 0;
     42my $LOG = \*STDOUT;
    4343
    4444getopts('hl:m:p:qr:tv',\%opts);
     
    6767}
    6868
     69# Handle root of the project if defined
     70if (defined $opts{'r'}) {
     71    $ENV{'PBROOT'} = $opts{'r'};
     72}
     73# Handle virtual machines if any
     74if (defined $opts{'m'}) {
     75    $ENV{'PBVM'} = $opts{'m'};
     76}
     77
    6978# Get Action
    7079$action = shift @ARGV;
    7180die pb_syntax() if (not defined $action);
    7281
    73 # Handle root of the project if defined
    74 if (defined $opts{'r'}) {
    75     $ENV{'PBROOT'} = $opts{'r'};
    76 }
    77 # Handle virtual machines if any
    78 if (defined $opts{'m'}) {
    79     $ENV{'PBVM'} = $opts{'m'};
    80 }
     82my ($pbrc, $filteredfiles, $defpkgdir, $extpkgdir);
     83
    8184# Handles project name if any
     85# And get global params
    8286if (defined $opts{'p'}) {
    8387    ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir)
     
    8791    = pb_env_init();
    8892}
    89 
    90 print $LOG "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);
     93my %pbrc = %$pbrc;
     94my %filteredfiles = %$filteredfiles;
     95my %defpkgdir = %$defpkgdir;
     96my %extpkgdir = %$extpkgdir;
     97
     98print $LOG "Project: $ENV{'PBPROJ'}\n" if ($debug >= 0);
    9199print $LOG "Action: $action\n" if ($debug >= 0);
    92100
     
    125133sub pb_cms2build {
    126134
    127     my $ptr = pb_get_pkg();
     135    my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
    128136    @pkgs = @$ptr;
    129137    my $cms=pb_cms_init($ENV{'PBPROJ'},$pbdate);
     
    224232            if (defined $ptr) {
    225233                foreach my $f (values %bfiles) {
    226                     pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate);
     234                    pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,\%defpkgdir,\%extpkgdir);
    227235                }
    228236                if (defined $filteredfiles{$pbpkg}) {
     
    245253        # Prepare the dest directory for archive
    246254        if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
    247             pb_system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
     255            #pb_system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
     256            print $LOG "Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit\n";
     257            system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit");
    248258        }
    249259
     
    283293
    284294    # Get list of packages to build
    285     my $ptr = pb_get_pkg();
     295    my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
    286296    @pkgs = @$ptr;
    287297
     
    343353}
    344354
     355# By default deliver to the the public site hosting the
     356# ftp structure (or whatever) or a VM
    345357sub pb_send2ssh {
    346358
    347359    my $cmt = shift;
     360    my $host = shift || "sshhost";
     361    my $login = shift || "sshlogin";
     362    my $dir = shift || "sshdir";
     363    my $port = shift || "sshport";
    348364
    349365    my @src;
    350366
    351367    # Get list of packages to build
    352     my $ptr = pb_get_pkg();
     368    my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
    353369    @pkgs = @$ptr;
    354370
     
    370386        if ($cmt eq "Sources") {
    371387            $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
     388        } elsif ($cmt eq "VMs") {
     389            $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/pbscript $ENV{'PBETC'}";
    372390        } elsif ($cmt eq "Packages") {
    373391            if ($dtype eq "rpm") {
     
    383401                die "Unknown dtype format $dtype";
    384402            }
     403            # Also make a pbscript to generate yum/urpmi/apt bases
     404            # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
    385405        }
    386406        print $LOG "$cmt: $src\n" if ($debug >= 0);
    387407        push @src, $src;
    388408    }
    389     my ($sshhost,$sshlogin,$sshdir) = pb_conf_get("sshhost", "sshlogin", "sshdir");
     409    my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
    390410    my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
    391     my $dir;
     411    my $tdir;
    392412    if ($cmt eq "Sources") {
    393         $dir = "$sshdir->{$ENV{'PBPROJ'}}/src";
     413        $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
     414    } elsif ($cmt eq "VMs") {
     415        $tdir = "$sshdir->{$ENV{'PBPROJ'}}";
    394416    } elsif ($cmt eq "Packages") {
    395         $dir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
     417        $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
    396418    } else {
    397419        return;
    398420    }
    399421    $src = join(' ',@src);
    400     pb_system("ssh -q $mac \"mkdir -p $dir ; cd $dir ; rm -f $src\"","Preparing $dir on $mac");
    401     pb_system("scp -p $src $mac:$dir","$cmt delivery in $dir on $mac");
     422    pb_system("ssh -q $mac \"mkdir -p $tdir ; cd $tdir ; rm -f $src\"","Preparing $tdir on $mac");
     423    pb_system("scp -p -P $sshport $src $mac:$tdir","$cmt delivery in $tdir on $mac");
     424    pb_system("ssh -q $mac \"cd $tdir ; if [-f pbscript]; then chmod 755 ./pbscript ; ./pbscript\"","Executing pbscript on $mac");
     425    if ($cmt eq "VMs") {
     426        pb_system("scp -p -P $sshport $mac:$tdir/.... ...","Package recovery in $tdir from $mac");
     427    }
    402428}
    403429
     
    405431    my ($vm,$all) = pb_get_vm();
    406432
     433    # Prepare the script to be executed on the VM
     434    # in $ENV{'PBDESTDIR'}/pbscript
     435    # Launch the VM
     436    # Gather all required files to send them to the VM
     437    pb_send2ssh("VMs","vmhost","vmlogin","vmdir","vmport");
     438   
    407439    # Send tar files when we do a global generation
    408440    pb_build2ssh() if ($all == 1);
     
    412444
    413445my @pkgs;
     446my $defpkgdir = shift;
     447my $extpkgdir = shift;
     448
     449my %defpkgdir = %$defpkgdir;
     450my %extpkgdir = %$extpkgdir;
    414451
    415452# Get packages list
     
    418455} elsif ($ARGV[0] =~ /^all$/) {
    419456    @pkgs = keys %defpkgdir;
    420     if (defined %extpkgdir) {
    421         my $k = keys %extpkgdir;
    422         if (defined $k) {
    423             push(@pkgs, keys %extpkgdir);
    424         }
    425     }
     457    push(@pkgs, keys %extpkgdir);
    426458} else {
    427459    @pkgs = @ARGV;
     
    443475# Get VM list
    444476if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
    445     my $ptr = pb_conf_get("vmlist");
     477    my ($ptr) = pb_conf_get("vmlist");
    446478    $ENV{'PBVM'} = $ptr->{$ENV{'PBPROJ'}};
    447479    $all = 1;
    448480}
    449481@vm = split(/,/,$ENV{'PBVM'});
    450 print $LOG "VMs: ".join(',',@vm)."\n" if ($debug >= 0);
     482print $LOG "VMs: ".join(',',@vm)."\n";
    451483return(\@vm,$all);
    452484}
  • devel/pb/lib/ProjectBuilder/Base.pm

    r107 r108  
    4444print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
    4545
    46 %pbrc = %$pbrc;
     46my %pbrc = %$pbrc;
    4747if (not defined $proj) {
    4848    # Take the first as the default project
     
    5656#
    5757my $topdir=dirname($pbrc{$proj});
     58# Expand potential env variable in it
     59eval { $topdir =~ s/(\$ENV.+\})/$1/eeg };
    5860chdir $topdir || die "Unable to change directory to $topdir";
     61$pbrc{$proj} = $topdir."/pbrc";
    5962$ENV{'PBDESTDIR'}=$topdir."/delivery";
    6063
     
    8083
    8184my %version = ();
     85my %defpkgdir = ();
     86my %extpkgdir = ();
     87my %filteredfiles = ();
    8288
    8389if (-f "$ENV{'PBCONF'}/$proj.pb") {
     
    95101    %defpkgdir = %$defpkgdir;
    96102    # Global
    97     %extpkgdir = ();
    98103    %extpkgdir = %$defpkgdir if (defined $defpkgdir);
    99     %version = ();
    100104    %version = %$version if (defined $version);
    101105    # Global
    102     %filteredfiles = ();
    103106    %filteredfiles = %$filteredfiles if (defined $filteredfiles);
    104107    #
     
    185188my $cmt=shift || $cmd;
    186189
    187 print $LOG "$cmt... ";
     190print "$cmt... ";
    188191system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
    189192if ($? == -1) {
    190     print $LOG "failed to execute ($cmd) : $!\n" if ($debug >= 0);
     193    print "failed to execute ($cmd) : $!\n";
    191194    pb_display_file("$ENV{'PBTMP'}/system.log");
    192195} elsif ($? & 127) {
    193     printf $LOG "child ($cmd) died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     196    printf "child ($cmd) died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
    194197    pb_display_file("$ENV{'PBTMP'}/system.log");
    195198} elsif ($? == 0) {
    196     print $LOG "OK\n" if ($debug >= 0);
     199    print "OK\n";
    197200} else {
    198201    printf "child ($cmd) exited with value %d\n", $? >> 8;
     
    207210open(FILE,"$file") || die "Unable to open $file";
    208211while (<FILE>) {
    209     print $LOG;
     212    print $_;
    210213}
    211214close(FILE);
     
    227230    die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $p->{$ENV{'PBPROJ'}});
    228231}
    229 print "DEBUG: param: ".Dumper(@ptr)."\n" if ($debug >= 1);
     232#print "DEBUG: param: ".Dumper(@ptr)."\n" if ($debug >= 1);
    230233return(@ptr);
    231234}
     
    239242my $trace;
    240243my @ptr;
     244
     245my $debug = 0;
    241246
    242247if ($debug > 0) {
     
    299304my $cms = shift;
    300305my $pbdate = shift || undef;
    301 my $pkgdir = shift;
     306my $source = shift;
    302307my $destdir = shift;
     308my $tmp;
    303309
    304310if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
    305     pb_system("svn export $pkgdir $destdir","Exporting $pkgdir from SVN");
     311    if (-d $source) {
     312        $tmp = $destdir;
     313    } else {
     314        $tmp = $destdir."/".basename($source);
     315    }
     316    pb_system("svn export $source $tmp","Exporting $source from SVN");
    306317} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
    307318    my $dir=dirname($destdir);
    308319    my $base=basename($destdir);
    309     my $tmp=basename($pkgdir);
     320    # Doesn't work if called from outside with a full path name to a file/dir to export
     321    $tmp=basename($source);
    310322    # CVS needs a relative path !
    311     pb_system("cd $dir ; cvs export -D $pbdate -d $base $tmp","Exporting $pkgdir from CVS");
     323    pb_system("cd $dir ; cvs export -D $pbdate -d $base $tmp","Exporting $source from CVS");
    312324} else {
    313325    die "cms $cms->{$ENV{'PBPROJ'}} unknown";
     
    338350
    339351sub pb_get_filters {
     352
     353# For the moment not dynamic
     354my $debug = 0;                  # Debug level
     355my $LOG = *STDOUT;              # Where to log
    340356
    341357my @ffiles;
     
    397413my $pbrev=shift;
    398414my $pbdate=shift;
     415my $defpkgdir = shift;
     416my $extpkgdir = shift;
     417
     418# For the moment not dynamic
     419my $debug = 0;                  # Debug level
     420my $LOG = *STDOUT;              # Where to log
    399421
    400422print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
     
    416438        } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
    417439            $tmp = "";
    418             my $p = $defpkgdir{$pbpkg};
    419             $p = $extpkgdir{$pbpkg} if (not defined $p);
     440            my $p = $defpkgdir->{$pbpkg};
     441            $p = $extpkgdir->{$pbpkg} if (not defined $p);
    420442            pb_changelog($dtype, $pbpkg, $pbtag, $pbsuf, $p, \*DEST);
    421443        }
     
    441463my $pbrev=shift;
    442464my $pbdate=shift;
     465
     466# For the moment not dynamic
     467my $debug = 0;                  # Debug level
     468my $LOG = *STDOUT;              # Where to log
    443469
    444470print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
  • devel/pb/lib/ProjectBuilder/Changelog.pm

    r89 r108  
    3535my $chglog = "$ENV{'PBROOT'}/$path/ChangeLog";
    3636if (! -f $chglog) {
    37     print "Unable to find the ChangeLog file ($chglog) for $pkg\n" if ($debug >= 0);
     37    print "No ChangeLog file ($chglog) for $pkg\n";
    3838    return("\n");
    3939}
  • devel/pb/lib/ProjectBuilder/Distribution.pm

    r74 r108  
    194194        my $found = 0;
    195195        my $ptr = $distro_similar{$d};
    196         print $LOG "amb: ".Dumper($ptr)."\n" if ($debug >= 1);
     196        #print $LOG "amb: ".Dumper($ptr)."\n" if ($debug >= 1);
    197197        $release = "unknown";
    198198        foreach my $dd (@$ptr) {
    199             print $LOG "check $dd\n" if ($debug >= 1);
     199            #print $LOG "check $dd\n" if ($debug >= 1);
    200200            # Try to check pattern
    201201            if (defined $distro_match{$dd}) {
    202                 print $LOG "cmp: $distro_match{$dd} - vs - $tmp\n" if ($debug >= 1);
     202                #print $LOG "cmp: $distro_match{$dd} - vs - $tmp\n" if ($debug >= 1);
    203203                ($release) = $tmp =~ m/$distro_match{$dd}/m;
    204204                if ((defined $release) && ($release ne "unknown")) {
Note: See TracChangeset for help on using the changeset viewer.