Changeset 315 in ProjectBuilder for devel/pb/bin


Ignore:
Timestamp:
Feb 10, 2008, 6:40:37 AM (16 years ago)
Author:
Bruno Cornec
Message:

Backup of local dev. cms2pkg compiles but doesn't work and even remove the SVN :-(
pb_log added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r314 r315  
    2323use ProjectBuilder::Distribution qw (pb_distro_init);
    2424use ProjectBuilder::Version qw (pb_version_init);
    25 use ProjectBuilder::Base qw (pb_conf_read pb_conf_get pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout);
     25use ProjectBuilder::Base qw (pb_conf_read pb_conf_get pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_filter_file_inplace pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout pb_get_date pb_log pb_log_init);
    2626
    2727my %opts;                   # CLI Options
     
    3636my %pbtag;                  # per package
    3737my $pbrev;                  # Global REVISION variable
    38 my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
     38my @date=pb_get_date();
    3939my $pbdate = strftime("%Y-%m-%d", @date);
    40 my $pbdatecvs = strftime("%Y-%m-%d %H:%M:%S", @date);
    4140my $debug = 0;
    4241my $pbaccount;              # Login to use to connect to the VM
     
    6463    $debug = 0  if ($debug == -1);
    6564    }
     65pb_log_init($debug, $LOG);
     66
    6667# Handles test option
    6768if (defined $opts{'t'}) {
     
    106107# And get global params
    107108if (defined $opts{'p'}) {
    108     ($debug,$LOG, $filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
     109    ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
    109110    = pb_env_init($opts{'p'},$pbinit);
    110111} else {
    111     ($debug,$LOG, $filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
     112    ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
    112113    = pb_env_init(undef,$pbinit);
    113114}
    114115
    115 print $LOG "Project: $ENV{'PBPROJ'}\n" if ($debug >= 0);
    116 print $LOG "Action: $action\n" if ($debug >= 0);
     116pb_log(0,"Project: $ENV{'PBPROJ'}\n");
     117pb_log(0,"Action: $action\n");
    117118
    118119# Keep those project values to store them at the end each time
     
    154155} elsif ($action =~ /^clean$/) {
    155156} else {
    156     print $LOG "'$action' is not available\n";
     157    pb_log(0,"\'$action\' is not available\n");
    157158    pb_syntax();
    158159}
     
    162163    my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
    163164    @pkgs = @$ptr;
    164     my $cms=pb_cms_init($ENV{'PBPROJ'});
     165    my ($scheme,$uri)=pb_cms_init($ENV{'PBPROJ'});
    165166
    166167    my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
     
    188189
    189190        $pbrev = $ENV{'PBREVISION'};
    190         print $LOG "\n";
    191         print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n";
     191        pb_log(2,"\n");
     192        pb_log(2,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
    192193        die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
    193194        # Clean up dest if necessary. The export will recreate it
     
    202203        my $dir = $defpkgdir->{$pbpkg};
    203204        $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
    204         print "def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n" if ($debug >= 1);
    205         pb_cms_export($cms,$pbdatecvs,"$ENV{'PBROOT'}/$dir",$dest);
     205        pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
     206
     207        # If it isn't a flat CMS, then we have the choice to export subdir
     208        $dir = "$uri/$dir" if ($ENV{'PBREVISION'} ne "flat");
     209        pb_cms_export($scheme,"$dir",$dest);
    206210
    207211        # Get project info on authors and log file
     
    216220        # Extract cms log history and store it
    217221        if ((defined $chglog) && (! -f "$dest/NEWS")) {
    218             print $LOG "Generating NEWS file from $chglog\n";
     222            pb_log(2,"Generating NEWS file from $chglog\n");
    219223            copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
    220224        }
    221         pb_cms_log($cms,"$ENV{'PBROOT'}/$dir",$dest,$chglog,$authors);
     225        pb_cms_log($scheme,$dir,$dest,$chglog,$authors);
    222226
    223227        my %build;
    224228
    225         my ($ptr) = pb_conf_get("vmlist");
     229        my ($ptr) = pb_conf_get_if("vmlist","chrootlist");
    226230        foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) {
    227             my ($name,$ver) = split(/_/,$d);
    228             chomp($ver);
     231            my ($name,$ver,$arch) = split(/-/,$d);
     232            chomp($arch);
    229233            my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
    230             print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n" if ($debug >= 1);
    231             print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
     234            pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n");
     235            pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
    232236
    233237            # Filter build files from the less precise up to the most with overloading
     
    236240            # Find all build files first relatively to PBROOT
    237241            # Find also all specific files referenced in the .pb conf file
    238             my %bfiles;
    239             my %pkgfiles;
    240             print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1);
     242            my %bfiles = {};
     243            my %pkgfiles = {};
     244            pb_log(2,"DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n");
    241245            $build{"$ddir-$dver"} = "yes";
    242             if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") {
    243                 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!";
    244                 foreach my $f (readdir(BDIR)) {
    245                     next if ($f =~ /^\./);
    246                     $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f";
    247                     $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
    248                     if (defined $supfiles->{$pbpkg}) {
    249                         $pkgfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f" if ($f =~ /$supfiles->{$pbpkg}/);
    250                     }
    251                 }
    252                 closedir(BDIR);
    253             } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") {
    254                 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!";
    255                 foreach my $f (readdir(BDIR)) {
    256                     next if ($f =~ /^\./);
    257                     $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f";
    258                     $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
    259                     if (defined $supfiles->{$pbpkg}) {
    260                         $pkgfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f" if ($f =~ /$supfiles->{$pbpkg}/);
    261                     }
    262                 }
    263                 closedir(BDIR);
    264             } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") {
    265                 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!";
    266                 foreach my $f (readdir(BDIR)) {
    267                     next if ($f =~ /^\./);
    268                     $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f";
    269                     $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
    270                     if (defined $supfiles->{$pbpkg}) {
    271                         $pkgfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
    272                     }
    273                 }
    274                 closedir(BDIR);
    275             } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") {
    276                 opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir-$dver: $!";
    277                 foreach my $f (readdir(BDIR)) {
    278                     next if ($f =~ /^\./);
    279                     $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f";
    280                     $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
    281                     if (defined $supfiles->{$pbpkg}) {
    282                         $pkgfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f" if ($f =~ /$supfiles->{$pbpkg}/);
    283                     }
    284                 }
    285                 closedir(BDIR);
     246
     247            if (-d "$ENV{'PBROOT'}/$pbpkg/$dtype") {
     248                pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$dtype",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     249            } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$dfam") {
     250                pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     251            } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$ddir") {
     252                pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     253            } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$ddir-$dver") {
     254                pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
    286255            } else {
    287256                $build{"$ddir-$dver"} = "no";
    288257                next;
    289258            }
    290             print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
     259            pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
    291260
    292261            # Get all filters to apply
     
    301270            }
    302271        }
    303         if ($debug >= 0) {
    304             my @found;
    305             my @notfound;
    306             foreach my $b (keys %build) {
    307                 push @found,$b if ($build{$b} =~ /yes/);
    308                 push @notfound,$b if ($build{$b} =~ /no/);
    309             }
    310             print $LOG "Build files generated for ".join(',',@found)."\n";
    311             print $LOG "No Build files found for ".join(',',@notfound)."\n" if (@notfound);
    312         }
     272        my @found;
     273        my @notfound;
     274        foreach my $b (keys %build) {
     275            push @found,$b if ($build{$b} =~ /yes/);
     276            push @notfound,$b if ($build{$b} =~ /no/);
     277        }
     278        pb_log(0,"Build files generated for ".join(',',@found)."\n");
     279        pb_log(0,"No Build files found for ".join(',',@notfound)."\n") if (@notfound);
    313280        # Get the generic filter (all.pbf) and
    314281        # apply those to the non-build files including those
     
    321288        if (defined $filteredfiles->{$pbpkg}) {
    322289            foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
    323                 pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
     290                pb_filter_file_inplace($ptr,"$dest/$f",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
    324291                $liste = "$f $liste";
    325292            }
    326293        }
    327         print $LOG "Files ".$liste."have been filtered\n";
     294        pb_log(2,"Files ".$liste."have been filtered\n");
    328295
    329296        # Prepare the dest directory for archive
    330         if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
    331             pb_filter_file("$ENV{'PBCONF'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
     297        if (-x "$ENV{'PBROOT'}/$pbpkg/pbinit") {
     298            pb_filter_file("$ENV{'PBROOT'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
    332299            chmod 0755,"$ENV{'PBTMP'}/pbinit";
    333             pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBCONF'}/$pbpkg/pbinit");
     300            pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOT'}/$pbpkg/pbinit");
    334301        }
    335302
     
    338305        # Possibility to look at PBSRC to guess more the filename
    339306        pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
    340         print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
     307        pb_log(2,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
    341308
    342309        # Keep track of what is generated by default
     
    354321        }
    355322
    356         print $LOG "DEBUG pkg: ".Dumper($pkg)."\n" if ($debug >= 1);
     323        pb_log(2,"DEBUG pkg: ".Dumper($pkg)."\n");
    357324        open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
    358325        foreach my $p (keys %$pkg) {
     
    374341    # Get the running distro to build on
    375342    my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
    376     print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
     343    pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
    377344
    378345    # Get content saved in cms2build
     
    392359
    393360        my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
    394         print $LOG "Source file: $src\n" if ($debug >= 0);
    395 
    396         print $LOG "Working directory: $ENV{'PBBUILDDIR'}\n" if ($debug >= 0);
     361        pb_log(2,"Source file: $src\n");
     362
     363        pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
    397364        if ($dtype eq "rpm") {
    398365            foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
     
    402369            }
    403370
     371            # Remove in case a previous link/file was there
    404372            unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
    405373            symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
     
    408376            @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
    409377
    410             print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
     378            pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
    411379            # set LANGUAGE to check for correct log messages
    412380            $ENV{'LANGUAGE'}="C";
    413             #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
    414381            foreach my $f (@specfile) {
    415382                if ($f =~ /\.spec$/) {
     
    432399            pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package");
    433400            $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz";
     401            if (-f "/usr/bin/lintian") {
     402                pb_system("lintian $made","Checking validity of debs with lintian");
     403            }
    434404        } elsif ($dtype eq "ebuild") {
    435405            my @ebuildfile;
     
    528498    }
    529499    my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
    530     print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
     500    pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
    531501
    532502    # Get content saved in cms2build
     
    575545    }
    576546
    577     print $LOG "Sources handled ($cmt): $src\n" if ($debug >= 0);
     547    pb_log(2,"Sources handled ($cmt): $src\n");
    578548    my ($sshhost,$sshlogin,$sshdir,$sshport,$vmtmout,$testver) = pb_conf_get($host,$login,$dir,$port,$tmout,"testver");
    579549    my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
     
    723693        }
    724694        if (! -f "$vem") {
    725             print "Unable to find VM $vem\n";
     695            pb_log(0,"Unable to find VM $vem\n");
    726696        } else {
    727697            pb_system("$cmd &","Launching the VM $vem");
     
    730700        }
    731701    } else {
    732         print "Found an existing VM $vem (pid $veexist)\n";
     702        pb_log(0,"Found an existing VM $vem (pid $veexist)\n");
    733703    }
    734704    return($veexist,$vepid);
     
    798768        }
    799769        if (! -f "$vmm") {
    800             print "Unable to find VM $vmm\n";
     770            pb_log(0,"Unable to find VM $vmm\n");
    801771        } else {
    802772            pb_system("$cmd &","Launching the VM $vmm");
     
    805775        }
    806776    } else {
    807         print "Found an existing VM $vmm (pid $vmexist)\n";
     777        pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
    808778    }
    809779    return($vmexist,$vmpid);
     
    864834
    865835    die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
    866     my $cms=pb_cms_init($ENV{'PBPROJ'});
    867     if ($cms->{$ENV{'PBPROJ'}} ne "svn") {
     836    my $scheme=pb_cms_init($ENV{'PBPROJ'});
     837    if ($scheme ne "svn") {
    868838        die "Only SVN is supported at the moment";
    869839    }
    870     my $res = pb_cms_isdiff($cms);
     840    my $res = pb_cms_isdiff($scheme);
    871841    die "You need to have no differences before creating a new version" if ($res != 0);
    872     my $cmsurl = pb_cms_getinfo($cms,$ENV{'PBROOT'});
     842    my $cmsurl = pb_cms_getinfo($scheme,$ENV{'PBROOT'},"URL:");
    873843    my $newurl = dirname($cmsurl)."/$newver";
    874     pb_cms_copy($cms,$cmsurl,$newurl);
    875     pb_cms_checkout($cms,$newurl,"$ENV{'PBROOT'}/../$newver");
     844    pb_cms_copy($scheme,$cmsurl,$newurl);
     845    pb_cms_checkout($scheme,$newurl,"$ENV{'PBROOT'}/../$newver");
    876846    my $oldver=basename($cmsurl);
    877847    open(FILE,"$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb";
     
    884854    close(OUT);
    885855    rename("$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb");
    886     pb_cms_checkin($cms,"$ENV{'PBROOT'}/../$newver");
     856    pb_cms_checkin($scheme,"$ENV{'PBROOT'}/../$newver");
    887857}
    888858
     
    905875    @pkgs = @ARGV;
    906876}
    907 print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
     877pb_log(2,"Packages: ".join(',',@pkgs)."\n");
    908878return(\@pkgs);
    909879}
     
    928898    $all = 1;
    929899}
    930 print $LOG "VMs: $ENV{'PBVM'}\n";
     900pb_log(2,"VMs: $ENV{'PBVM'}\n");
    931901@vm = split(/,/,$ENV{'PBVM'});
    932902return(\@vm,$all);
     
    969939    next if ($f =~ /^\./);
    970940    move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
    971     print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
     941    pb_log(2,"mv $dir/$f $ddir\n");
    972942    push @files,"$ddir/$f";
    973943}
     
    978948}
    979949
     950sub pb_list_bfiles {
     951
     952my $dir = shift;
     953my $pbpkg = shift;
     954my $bfiles = shift;
     955my $pkgfiles = shift;
     956my $supfiles = shift;
     957
     958opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
     959foreach my $f (readdir(BDIR)) {
     960    next if ($f =~ /^\./);
     961    $bfiles->{$f} = "$dir/$f";
     962    $bfiles->{$f} =~ s~$ENV{'PBROOT'}~~;
     963    if (defined $supfiles->{$pbpkg}) {
     964        $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
     965    }
     966}
     967closedir(BDIR);
     968}
     969
    980970sub pb_syntax {
    981971
Note: See TracChangeset for help on using the changeset viewer.