Changeset 499 in ProjectBuilder


Ignore:
Timestamp:
Jul 30, 2008, 5:58:00 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Modification of filter interface: use a single pb hash which contains the tag that will be handled during the filtering. Allow for easiest interface of functions, removal of a redundant function and evolution by simple addition of tags in pb.
  • Attempt to code patch management. Not tested yet.
Location:
devel/pb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r498 r499  
    454454    my @pkgs = @$pkg;
    455455    my %pkgs;
     456    my %pb;             # Structure to store conf info
    456457
    457458    my ($scheme, $uri) = pb_cms_init($pbinit);
     
    520521        my @pt;
    521522        my $tmpl = "";
     523        my @patches = ();
    522524
    523525        @pt = pb_conf_get_if("vmlist","velist");
     
    532534            $tmpl .= $pt[1]->{$ENV{'PBPROJ'}}
    533535        }
     536
     537        # Setup %pb structure to allow filtering later on on files using that structure
     538        $pb{'tag'} = $pbtag;
     539        $pb{'rev'} = $pbrev;
     540        $pb{'pkg'} = $pbpkg;
     541        $pb{'ver'} = $pbver;
     542        $pb{'date'} = $pbdate;
     543        $pb{'defpkgdir'} = $defpkgdir;
     544        $pb{'extpkgdir'} = $extpkgdir;
     545        $pb{'chglog'} = $chglog;
     546        $pb{'packager'} = $ENV{'PBPACKAGER'};
     547        $pb{'proj'} = $ENV{'PBPROJ'};
     548        $pb{'repo'} = $ENV{'PBREPO'};
     549
    534550        foreach my $d (split(/,/,$tmpl)) {
    535551            my ($name,$ver,$arch) = split(/-/,$d);
    536552            chomp($arch);
    537             my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
    538             pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n");
     553            my ($ddir, $dver, $dfam);
     554            ($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'}) = pb_distro_init($name,$ver);
     555            pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'})."\n");
    539556            pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
    540557
     
    548565            $build{"$ddir-$dver"} = "yes";
    549566
    550             if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dtype") {
    551                 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dtype",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     567            if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
     568                pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
    552569            } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
    553570                pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
     
    563580
    564581            # Get all filters to apply
    565             my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
     582            my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
    566583
    567584            # Prepare patches for this distro
    568             my @patches;
    569 
    570585            foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
    571586                push @patches,$p if ($p =~ /\.all$/);
    572                 push @patches,$p if ($p =~ /\.$dtype$/);
     587                push @patches,$p if ($p =~ /\.$pb{'dtype'}$/);
    573588                push @patches,$p if ($p =~ /\.$dfam$/);
    574589                push @patches,$p if ($p =~ /\.$ddir$/);
    575590                push @patches,$p if ($p =~ /\.$ddir-$dver$/);
    576591            }
     592            $pb{'patches'} = \@patches;
    577593
    578594            # Apply now all the filters on all the files concerned
     
    580596            if (defined $ptr) {
    581597                foreach my $f (values %bfiles,values %pkgfiles) {
    582                     pb_filter_file_pb("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$defpkgdir,$extpkgdir,$ENV{'PBPACKAGER'},$chglog,$ENV{'PBPROJ'},$ENV{'PBREPO'});
     598                    pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),\%pb);
    583599                }
    584600            }
     
    602618        if (defined $filteredfiles->{$pbpkg}) {
    603619            foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
    604                 pb_filter_file_inplace($ptr,"$dest/$f",$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$ENV{'PBPACKAGER'},$ENV{'PBPROJ'},$ENV{'PBREPO'});
     620                pb_filter_file_inplace($ptr,"$dest/$f",\%pb);
    605621                $liste = "$f $liste";
    606622            }
    607623        }
    608624        pb_log(2,"Files ".$liste."have been filtered\n");
     625
     626        # Filter potential patches
     627        pb_mkdir_p("$dest/pbconf/pbpatch");
     628        foreach my $p (sort(@patches)) {
     629            my $pp = basename($p);
     630            pb_filter_file($p,$ptr,"$dest/pbconf/pbpatch/$pp",\%pb);
     631            pb_system("gzip -9 $dest/pbconf/pbpatch/$pp");
     632        }
    609633
    610634        # Prepare the dest directory for archive
    611635        if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
    612             pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$ENV{'PBPACKAGER'},$ENV{'PBPROJ'},$ENV{'PBREPO'});
     636            pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",\%pb);
    613637            chmod 0755,"$ENV{'PBTMP'}/pbinit";
    614638            pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit","verbose");
    615         }
    616 
    617         # Filter potential patches
    618         foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
    619             pb_mkdir_p("$dest/pbconf/pbpatch");
    620             pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/$p",$ptr,"$dest/pbconf/pbpatch/$p",$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$ENV{'PBPACKAGER'},$ENV{'PBPROJ'},$ENV{'PBREPO'});
    621639        }
    622640
     
    694712            symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
    695713            # We need to first extract the spec file
    696             my @specfile;
    697             @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
     714            my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
    698715
    699716            # We need to handle potential patches to upstream sources
     717            my @patchfiles = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES");
    700718
    701719            pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
  • devel/pb/lib/ProjectBuilder/Filter.pm

    r475 r499  
    119119}
    120120
    121 =item B<pb_filter_file_pb>
    122 
    123 This function applies all filters to pb build files.
    124 
    125 It takes 15 parameters. To be filtered a variable has to be passed to that function.
     121=item B<pb_filter_file>
     122
     123This function applies all filters to files.
     124
     125It takes 4 parameters.
    126126
    127127The first parameter is the file to filter.
    128128The second parameter is the pointer on the hash of filters.
    129129The third parameter is the destination file after filtering.
    130 The fourth parameter is the distribution type.
    131 The fifth parameter is the suffix of the distribution.
    132 The sixth parameter is the package name.
    133 The seventh parameter is the version of the package.
    134 The eighth parameter is the tag of the package.
    135 The nineth parameter is the revision of the package.
    136 The tenth parameter is the current date.
    137 The eleventh parameter is the list of required packages.
    138 The twelveth parameter is the list of optional packages.
    139 The thirteenth parameter is the packager name.
    140 The fourteenth parameter is the changelog.
    141 The fifteenth parameter is the project.
    142 The sixteenth parameter is the repo.
    143 
    144 =cut
    145 
    146 sub pb_filter_file_pb {
     130The fourth parameter is the pointer on the hash of variables to filter (tag, ver, ...)
     131
     132=cut
     133
     134sub pb_filter_file {
    147135
    148136my $f=shift;
     
    150138my %filter=%$ptr;
    151139my $destfile=shift;
    152 my $dtype=shift;
    153 my $pbsuf=shift;
    154 my $pbpkg=shift;
    155 my $pbver=shift;
    156 my $pbtag=shift;
    157 my $pbrev=shift;
    158 my $pbdate=shift;
    159 my $defpkgdir = shift;
    160 my $extpkgdir = shift;
    161 my $pbpackager = shift;
    162 my $chglog = shift || undef;
    163 my $pbproj = shift;
    164 my $pbrepo = shift;
     140my $pb=shift;
     141my %pb = %$pb;
    165142
    166143pb_log(2,"DEBUG: From $f to $destfile\n");
     
    182159        # special case for ChangeLog only for pb
    183160        } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
    184             my $p = $defpkgdir->{$pbpkg};
    185             $p = $extpkgdir->{$pbpkg} if (not defined $p);
    186             pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
     161            my $p = $pb{'defpkgdir'}->{$pbpkg};
     162            $p = $pb{'extpkgdir'}->{$pbpkg} if (not defined $p);
     163            pb_changelog($pb{'dtype'}, $pb{'pkg'}, $pb{'ver'}, $pb{'tag'}, $pb{'suf'}, $p, \*DEST, $tmp, $pb{'chglog'});
     164            $tmp = "";
     165        } elsif (($s =~ /^PBPATCHSRC$/) && ($line =~ /^PBPATCHSRC$/)) {
     166            my $i = 0;
     167            foreach my $p (sort @$pb{'patches'}) {
     168                print DEST "Patch$i: $p\n";
     169            }
     170            $tmp = "";
     171        } elsif (($s =~ /^PBPATCHCMD$/) && ($line =~ /^PBPATCHCMD$/)) {
     172            my $i = 0;
     173            foreach my $p (sort @$pb{'patches'}) {
     174                print DEST "%patch$i\n";
     175            }
     176            print DEST "\n";
    187177            $tmp = "";
    188178        }
     
    199189This function applies all filters to a file in place.
    200190
    201 It takes 9 parameters.
     191It takes 3 parameters.
    202192
    203193The first parameter is the pointer on the hash of filters.
    204194The second parameter is the destination file after filtering.
    205 The third parameter is the package name.
    206 The fourth parameter is the version of the package.
    207 The fifth parameter is the tag of the package.
    208 The sixth parameter is the revision of the package.
    209 The seventh parameter is the current date.
    210 The eighth parameter is the packager name.
    211 The nineth parameter is the project name.
    212 The tenth parameter is the repo.
     195The third parameter is the pointer on the hash of variables to filter (tag, ver, ...)
    213196
    214197=cut
     
    220203my %filter=%$ptr;
    221204my $destfile=shift;
    222 my $pbpkg=shift;
    223 my $pbver=shift;
    224 my $pbtag=shift;
    225 my $pbrev=shift;
    226 my $pbdate=shift;
    227 my $pbpackager=shift;
    228 my $pbproj=shift;
    229 my $pbrepo = shift;
     205my $pb=shift;
     206my %pb = %$pb;
    230207
    231208my $cp = "$ENV{'PBTMP'}/".basename($destfile);
    232209copy($destfile,$cp) || die "Unable to create $cp";
    233210
    234 pb_filter_file($cp,$ptr,$destfile,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager,$pbproj,$pbrepo);
     211pb_filter_file($cp,$ptr,$destfile,$pb);
    235212unlink $cp;
    236213}
    237214
    238 =item B<pb_filter_file>
    239 
    240 This function applies all filters on a file to generate a new filtered one.
    241 
    242 It takes 10 parameters. To be filtered a variable has to be passed to that function.
    243 
    244 The first parameter is the original file to filter.
    245 The second parameter is the pointer on the hash of filters.
    246 The third parameter is the destination file after filtering.
    247 The fourth parameter is the package name.
    248 The fifth parameter is the version of the package.
    249 The sixth parameter is the tag of the package.
    250 The seventh parameter is the revision of the package.
    251 The eighth parameter is the current date.
    252 The nineth parameter is the packager name.
    253 The tenth parameter is the project name.
    254 The eleventh parameter is the repo.
    255 
    256 =cut
    257 
    258 
    259 # Function which applies filter on files (external call)
    260 sub pb_filter_file {
    261 
    262 my $f=shift;
    263 my $ptr=shift;
    264 my %filter=%$ptr;
    265 my $destfile=shift;
    266 my $pbpkg=shift;
    267 my $pbver=shift;
    268 my $pbtag=shift;
    269 my $pbrev=shift;
    270 my $pbdate=shift;
    271 my $pbpackager=shift;
    272 my $pbproj=shift;
    273 my $pbrepo = shift;
    274 
    275 pb_log(2,"DEBUG: From $f to $destfile\n");
    276 pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
    277 open(DEST,"> $destfile") || die "Unable to create $destfile";
    278 open(FILE,"$f") || die "Unable to open $f: $!";
    279 while (<FILE>) {
    280     my $line = $_;
    281     foreach my $s (keys %filter) {
    282         # Process single variables
    283         pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
    284         my $tmp = $filter{$s};
    285         next if (not defined $tmp);
    286         # Expand variables if any single one found
    287         if ($tmp =~ /\$/) {
    288             eval { $tmp =~ s/(\$\w+)/$1/eeg };
    289             eval { $tmp =~ s/(\$\/)/$1/eeg };
    290         }
    291         $line =~ s|$s|$tmp|g;
    292     }
    293     print DEST $line;
    294 }
    295 close(FILE);
    296 close(DEST);
    297 }
    298215
    299216=back
Note: See TracChangeset for help on using the changeset viewer.