Ignore:
Timestamp:
Jul 30, 2008, 5:58:00 AM (11 years ago)
Author:
bruno
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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.