Changeset 77 for devel/pb/bin/pb


Ignore:
Timestamp:
Sep 3, 2007, 3:34:11 AM (12 years ago)
Author:
bruno
Message:

transfer pb_fiter_file to Base and duplicate :-( for external call
Create sub functions per action

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r75 r77  
    2929use ProjectBuilder::Changelog qw (pb_changelog);
    3030use ProjectBuilder::Version qw (pb_version_init);
    31 use ProjectBuilder::Base qw (pb_conf_read pb_cms_init pb_mkdir_p pb_system pb_rm_rf);
     31use ProjectBuilder::Base qw (pb_conf_read pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb);
    3232
    3333my %opts;                   # CLI Options
     
    3838my $pbtag;                  # Global TAG variable
    3939my $pbver;                  # Global VERSION variable
     40my %pbver;                  # per package
     41my %pbtag;                  # per package
    4042my $pbrev;                  # Global REVISION variable
    4143my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
     
    8789# Act depending on action
    8890if ($action =~ /^cms2build$/) {
    89     my $ptr = get_pkg();
     91    pb_cms2build();
     92} elsif ($action =~ /^build2pkg$/) {
     93    pb_build2pkg();
     94} elsif ($action =~ /^cms2pkg$/) {
     95    pb_cms2build();
     96    pb_build2pkg();
     97} else {
     98    print $LOG "'$action' is not available\n";
     99    pb_syntax();
     100}
     101
     102sub pb_cms2build {
     103
     104    my $ptr = pb_get_pkg();
    90105    @pkgs = @$ptr;
    91106    pb_cms_init($ENV{'PBPROJ'});
     
    190205
    191206            # Get all filters to apply
    192             # They're cumulative from less specific to most specific
    193             # suffix is .pbf
    194             my @ffiles;
    195             my ($ffile0, $ffile1, $ffile2, $ffile3);
    196             if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
    197                 $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
    198                 $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
    199                 $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
    200                 $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
    201                 push @ffiles,$ffile0 if (defined $ffile0);
    202                 push @ffiles,$ffile1 if (defined $ffile1);
    203                 push @ffiles,$ffile2 if (defined $ffile2);
    204                 push @ffiles,$ffile3 if (defined $ffile3);
    205             }
    206             my $config = AppConfig->new({
    207                             # Auto Create variables mentioned in Conf file
    208                             CREATE => 1,
    209                             DEBUG => 0,
    210                             GLOBAL => {
    211                                 # Each conf item is a hash
    212                                 ARGCOUNT => AppConfig::ARGCOUNT_HASH
    213                             }
    214                         });
    215             my $ptr;
    216             if (@ffiles) {
    217                 print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
    218                 $config->file(@ffiles);
    219                 $ptr = $config->get("filter");
    220                 print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
    221             } else {
    222                 $ptr = { };
    223             }
     207            my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
    224208
    225209            # Apply now all the filters on all the files concerned
     
    227211            if (defined $ptr) {
    228212                foreach my $f (values %bfiles) {
    229                     filter_file("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$pbpkg,$dtype,$dsuf);
     213                    pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$pbpkg,$dtype,$dsuf);
    230214                }
    231215                if (defined $filteredfiles{$dir}) {
    232216                    foreach my $f (split(/,/,$filteredfiles{$dir})) {
    233                         filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$pbpkg,$dtype,$dsuf);
     217                        pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f");
    234218                    }
    235219                }
     
    258242        print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
    259243        # Keep track of what is generated for default
    260         open(LAST,"> $pbrc{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc{$ENV{'PBPROJ'}}";
    261         print LAST "pbroot $pbver-$pbtag = $ENV{'PBROOT'}\n";
    262         close(LAST);
     244        $pbver{$pbpkg} = $pbver;
     245        $pbtag{$pbpkg} = $pbtag;
    263246    }
    264 } elsif ($action =~ /^build2pkg$/) {
     247    open(LAST,"> $pbrc{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc{$ENV{'PBPROJ'}}";
     248    foreach my $v (keys %pbver) {
     249        print LAST "pbroot $v-_-$pbver{v}-$pbtag{v} = $ENV{'PBROOT'}\n";
     250    }
     251    close(LAST);
     252}
     253
     254sub pb_build2pkg {
     255
     256    # Get list of packages to build
     257    my $ptr = pb_get_pkg();
     258    @pkgs = @$ptr;
     259
    265260    # Check whether we have a specific version to build
    266261    my $vertag = shift @ARGV;
    267     if (not defined $vertag) {
    268         if (-f $pbrc{$ENV{'PBPROJ'}}) {
    269             my $pbroot = pb_conf_read($pbrc{$ENV{'PBPROJ'}},"pbroot");
    270             # There is only one line normaly
    271             $vertag = (keys %$pbroot)[0];
    272             $ENV{'PBROOT'} = (values %$pbroot)[0];
    273         } else {
    274             die "Unable to open $pbrc{$ENV{'PBPROJ'}}\nYou may want to precise as parameter version-tag";
    275         }
    276     }
    277     ($pbver,$pbtag) = split(/-/,$vertag);
    278 
    279     # Get list of packages to build
    280     my $ptr = get_pkg();
    281     @pkgs = @$ptr;
    282262
    283263    # Get the running distro to build on
     
    287267    chdir "$ENV{'PBBUILDDIR'}";
    288268    foreach my $pbpkg (@pkgs) {
     269        # get the version of the current package - maybe different
     270        if (not defined $vertag) {
     271            if (-f $pbrc{$ENV{'PBPROJ'}}) {
     272                my $pbroot = pb_conf_read($pbrc{$ENV{'PBPROJ'}},"pbroot");
     273                # All lines should point to the same pbroot so take the first
     274                $ENV{'PBROOT'} = (values %$pbroot)[0];
     275                foreach my $k (keys %$pbroot) {
     276                        if ($k =~ /^$pbpkg-_-/) {
     277                            ($ptr,$vertag) = split(/-_-/,$k);
     278                            last;
     279                        }
     280                }
     281                die "Unable to find $pbpkg in $pbrc{$ENV{'PBPROJ'}}\nYou may want to precise as parameter version-tag" if (not defined $vertag);
     282            } else {
     283                die "Unable to open $pbrc{$ENV{'PBPROJ'}}\nYou may want to precise as parameter version-tag";
     284            }
     285        }
     286        ($pbver,$pbtag) = split(/-/,$vertag);
     287
    289288        my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
    290289        print $LOG "Source file: $src\n" if ($debug >= 0);
     
    305304            symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
    306305            my @specfile;
    307             @specfile = extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
     306            @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
    308307
    309308            print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
     
    324323        }
    325324    }
    326 } else {
    327     print $LOG "'$action' is not available\n";
    328     pb_syntax();
    329 }
    330 
    331 # Function which applies filter on files
    332 sub filter_file {
    333 
    334 my $f=shift;
    335 my $ptr=shift;
    336 my %filter=%$ptr;
    337 my $destfile=shift;
    338 my $pbpkg=shift;
    339 my $dtype=shift;
    340 my $dsuf=shift;
    341 
    342 print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
    343 pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
    344 open(DEST,"> $destfile") || die "Unable to create $destfile";
    345 open(FILE,"$f") || die "Unable to open $f: $!";
    346 while (<FILE>) {
    347     my $line = $_;
    348     foreach my $s (keys %filter) {
    349         # Process single variables
    350         print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
    351         my $tmp = $filter{$s};
    352         next if (not defined $tmp);
    353         # Expand variables if any single one found
    354         if ($tmp =~ /\$/) {
    355             eval { $tmp =~ s/(\$\w+)/$1/eeg };
    356         # special case for ChangeLog
    357         } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
    358             my $p = $defpkgdir{$pbpkg};
    359             $p = $extpkgdir{$pbpkg} if (not defined $p);
    360             pb_changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST);
    361             $tmp = "";
    362         }
    363         $line =~ s|$s|$tmp|;
    364     }
    365     print DEST $line;
    366 }
    367 close(FILE);
    368 close(DEST);
    369 }
    370 
    371 sub get_pkg {
     325}
     326
     327sub pb_get_pkg {
    372328
    373329my @pkgs;
     
    391347}
    392348
    393 sub extract_build_files {
     349sub pb_extract_build_files {
    394350
    395351my $src=shift;
     
    442398    print "\t           if not using default list\n";
    443399    print "\n";
    444     print "\n";
    445 }
     400    print "\tcms2pkg:   cms2build + build2pkg\n";
     401    print "\n";
     402}
Note: See TracChangeset for help on using the changeset viewer.