OpenPKG CVS Repository
  http://cvs.openpkg.org/
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Michael van Elst
  Root:   /e/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-src                      Date:   03-Dec-2002 15:27:40
  Branch: HEAD                             Handle: 2002120314273900

  Modified files:
    openpkg-src/openpkg-tool openpkg-build.pl openpkg.pod

  Log:
    added status output (-S and -s options)
    several dependency issues no longer cause fatal errors
    or cause a fatal error only after all depencies have
    been evaluated
    XML parser ignored Conflicts element - fixed

  Summary:
    Revision    Changes     Path
    1.10        +153 -39    openpkg-src/openpkg-tool/openpkg-build.pl
    1.5         +59 -0      openpkg-src/openpkg-tool/openpkg.pod
  ____________________________________________________________________________

  Index: openpkg-src/openpkg-tool/openpkg-build.pl
  ============================================================
  $ cvs diff -u -r1.9 -r1.10 openpkg-build.pl
  --- openpkg-src/openpkg-tool/openpkg-build.pl 29 Nov 2002 10:10:21 -0000      1.9
  +++ openpkg-src/openpkg-tool/openpkg-build.pl 3 Dec 2002 14:27:39 -0000       1.10
  @@ -29,8 +29,8 @@
   $|=1; # autoflush
   
   use strict;
  -use vars qw/$opt_R $opt_r $opt_f $opt_u $opt_U $opt_a $opt_A $opt_z $opt_Z $opt_P 
$opt_N $opt_E $opt_i $opt_D $opt_p $opt_q/;
  -getopts('R:r:f:uUaAzZP:N:E:iD:p:q');
  +use vars qw/$opt_R $opt_r $opt_f $opt_u $opt_U $opt_a $opt_A $opt_z $opt_Z $opt_P 
$opt_N $opt_E $opt_i $opt_D $opt_p $opt_q $opt_s $opt_S/;
  +getopts('R:r:f:uUaAzZP:N:E:iD:p:qsS');
   
   ##########################################################################
   
  @@ -101,7 +101,7 @@
       close(FH);
   }
   
  -die "openpkg:build:USAGE: $0 [-R rpm] [-r repository] [-f index.rdf] [-uUzZiq] [-P 
priv-cmd] [-N non-priv-cmd] [-p platform] [-Dwith ...] [-Ename ...] ( [-aA] | 
patternlist )\n"
  +die "openpkg:build:USAGE: $0 [-R rpm] [-r repository] [-f index.rdf] [-uUzZiqS] [-P 
priv-cmd] [-N non-priv-cmd] [-p platform] [-Dwith ...] [-Ename ...] ( [-aA] | 
patternlist )\n"
       unless $#ARGV >= 0 || ($#ARGV == -1 && ($opt_a || $opt_A));
   
   ##########################################################################
  @@ -623,6 +623,9 @@
                   keeps    =>
                       ( $_->{'PreReq'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'}
                       || [] ),
  +                conflicts =>
  +                    ( $_->{'Conflicts'}->[0]->{'rdf:bag'}->[0]->{'rdf:li'}
  +                    || [] ),
                   desc     => xel($_->{'Description'})
               };
               $rec->{OPTIONS} = parse_options($rec->{desc});
  @@ -713,7 +716,7 @@
               print "# $i: ".vsn($_)." = $_->{href}\n";
               $i++;
           }
  -        die "ERROR: ambigous dependency\n";
  +        return;
   
       } else {
           if ($env->{upgrade}) {
  @@ -837,6 +840,18 @@
   }
   
   #
  +# record target status
  +#
  +sub target_setstatus ($$$) {
  +    my($target, $status, $pri) = @_;
  +
  +    if ($pri > $target->{STATUSPRI}) {
  +        $target->{STATUSPRI} = $pri;
  +        $target->{STATUS}    = $status;
  +    }
  +}
  +
  +#
   # report options that are not used for 
   #
   sub warn_about_options ($$$) {
  @@ -879,7 +894,8 @@
       } elsif ($dep =~ /^\s*$/) {
           $cond = sub { 1; };
       } else {
  -        die "FATAL: don't know how to handle PreReq: $name $dep\n";
  +        print "# don't know how to handle PreReq: $name $dep\n";
  +        return;
       }
   
       if ($i && (@vers = get_versions($i, $cond))) {
  @@ -900,9 +916,10 @@
   }
   
   
  -sub make_dep ($$$$$) {
  -    my($target,$depth,$env,$list,$blist) = @_;
  +sub make_dep ($$$$$$) {
  +    my($target,$depth,$env,$list,$blist,$clist) = @_;
       my($d,$k,%d,%k,$t,$old);
  +    my(@deps,$conflict);
   
       if (target_exists($target, $env->{built})) {
           print "# $target->{name} is already in list\n";
  @@ -910,11 +927,15 @@
       }
   
       if ($t = target_conflicts($target, $env->{installed})) {
  +        target_setstatus($target,'CONFLICT',4);
  +        push(@$clist,$target);
           print "# $target->{name} conflicts with ",vsn($t),"\n";
           return;
       }
   
       if ($t = target_conflicts($target, $env->{built})) {
  +        target_setstatus($target,'CONFLICT',4);
  +        push(@$clist,$target);
           print "# $target->{name} conflicts with ",vsn($t),"\n";
           return;
       }
  @@ -929,12 +950,16 @@
           }
           get_with($t);
           if ($target->{REBUILD}) {
  +            target_setstatus($target,'DEPEND',1);
               print "# rebuilding $target->{name} (dependency)\n";
           } elsif ($env->{zero}) {
  +            target_setstatus($target,'ZERO',1);
               print "# rebuilding $target->{name} (zero)\n";
           } elsif (target_newer($target, $env->{installed})) {
  +            target_setstatus($target,'UPGRADE',3);
               print "# rebuilding $target->{name} (upgrade)\n";
           } elsif (!target_suitable($t, $env->{with})) {
  +            target_setstatus($target,'MISMATCH',2);
               print "# rebuilding $target->{name} (parameter mismatch)\n";
           } else {
               print "# $target->{name} is already installed\n";
  @@ -946,6 +971,8 @@
           # remember this is a rebuild for a proxy package
           $target->{PROXY} = $t->{PROXY};
           $target->{REBUILD} = 1;
  +    } else {
  +        target_setstatus($target,'ADD',3);
       }
   
       if (exists $env->{exclude}->{$target->{name}}) {
  @@ -967,6 +994,8 @@
           %d = map { $_ => 1 } @$d, @$k;
           %k = map { $_ => 1 } @$k;
   
  +        @deps     = ();
  +        $conflict = 0;
           foreach (keys %d) {
   
               # old index misses a OpenPKG provider in the index... skip it
  @@ -981,14 +1010,24 @@
   
                   # record which targets to keep in blist
                   if ($k{$_}) {
  -                    push(@$blist,$t);
  +                    push @$blist,$t;
                       print "# $target->{name} installs ".vsn($t)." for $_\n";
                   } else {
                       print "# $target->{name} requires ".vsn($t)." for $_\n";
                   }
  -                make_dep($t,$depth+1,$env,$list,$blist);
  +                push @deps, $t;
               } else {
  -                die "FATAL: $target->{name} searches for a frood called '$_'\n";
  +                print "# $target->{name} searches for a frood called '$_'\n";
  +                push(@{$env->{fatal}},vsn($target));
  +                target_setstatus($target,'UNDEF',4);
  +                push @$clist, $target;
  +                $conflict = 1;
  +            }
  +        }
  +
  +        unless ($conflict) {
  +            foreach $t (@deps) {
  +                make_dep($t,$depth+1,$env,$list,$blist,$clist);
               }
           }
       }
  @@ -996,6 +1035,8 @@
       print "# adding ".vsn($target)." to list\n";
       push(@$list, $target);
   
  +    return if $conflict;
  +
       if (!$env->{quick} &&
           $target->{name} ne 'openpkg' &&
           $target->{REBUILD}) {
  @@ -1013,7 +1054,7 @@
               push(@$blist, $t);
   
               print "# rebuilding revdep ".vsn($t)."\n";
  -            make_dep($t,$depth+1,$env,$list,$blist);
  +            make_dep($t,$depth+1,$env,$list,$blist,$clist);
           }
       }
   }
  @@ -1031,7 +1072,7 @@
   
   sub build_list ($$) {
       my($pattern, $env) = @_;
  -    my(@goals,@targets,@keeps,$bonly,$t);
  +    my(@goals,@targets,@keeps,@conflicts,$bonly,$t);
       my($name,$r,$i,@vers);
       my(@todo);
   
  @@ -1084,10 +1125,16 @@
               }
           }
   
  -        die "FATAL: no known source found for '$name'\n" unless $t;
  -
  -        warn_about_options($t, $env->{with}, $env->{config});
  -        push(@goals, $t);
  +        if ($t) {
  +            warn_about_options($t, $env->{with}, $env->{config});
  +            push(@goals, $t);
  +        } else {
  +            if ($env->{status}) {
  +                print "# dropping goal '$name'\n";
  +            } else {
  +                die "FATAL: cannot find source for '$name'\n";
  +            }
  +        }
       }
       return unless @goals;
   
  @@ -1095,12 +1142,12 @@
       @keeps   = @goals;
       foreach $t (@goals) {
           print "# recursing over dependencies for ".vsn($t)."\n";
  -        make_dep($t,0,$env,\@targets,\@keeps);
  +        make_dep($t,0,$env,\@targets,\@keeps,\@conflicts);
       }
   
       $bonly = remove_list(\@targets, \@keeps, $env->{installed});
   
  -    return (\@targets, $bonly);
  +    return (\@targets, $bonly, \@conflicts);
   }
   
   #######################################################################
  @@ -1246,9 +1293,61 @@
       }
   }
   
  +sub print_status ($$$$$) {
  +    my($installed,$repository,$list,$bonly,$clist) = @_;
  +    my(%bonly) = map { $_ => 1 } @$bonly;
  +    my(%map,$n,@names,$t);
  +    my($old,$tag,$new);
  +
  +    foreach (@$list, @$clist) {
  +        $map{$_->{name}} = {
  +            rel    => "$_->{version}-$_->{release}",
  +            status => $_->{STATUS}
  +        };
  +    }
  +    
  +    foreach (@$bonly) {
  +        $map{$_->{name}} = {
  +            rel    => "$_->{version}-$_->{release}",
  +            status => 'TEMP'
  +        };
  +    }
  +
  +    @names = keys %map;
  +    foreach $n (keys %$installed) {
  +        next if exists $map{$n};
  +        next unless grep { $_ ne '-' } keys %{$installed->{$n}};
  +        $map{$n}->{'status'} = 'OK';
  +        push @names,$n;
  +    }
  +
  +    foreach $n (keys %$repository) {
  +        next if exists $map{$n};
  +        next unless grep { $_ ne '-' } keys %{$repository->{$n}};
  +        $t = find_target($n, $repository);
  +        $map{$n}->{'status'} = 'NEW';
  +        $map{$n}->{'rel'}    = vs($t);
  +        push @names,$n;
  +    }
  +
  +    foreach $n (sort @names) {
  +        $old = join ',',
  +            map { "$n-$_" }
  +            sort
  +            grep { $_ ne '-' }
  +            keys %{$installed->{$n}};
  +        $old = $n if $old eq '';
  +
  +        $tag = $map{$n}->{status};
  +        $new = defined $map{$n}->{rel} ? " $n-$map{$n}->{rel}" : '';
  +
  +        printf "%-35s %-8s%s\n", $old, $tag, $new;
  +    }
  +}
  +
   #######################################################################
   
  -my($config,$url,$repository,$installed,$list,$bonly);
  +my($config,$url,$repository,$installed,$env,$list,$bonly,$clist);
   my($pattern,%with,%exclude);
   
   if ($opt_a) {
  @@ -1294,27 +1393,42 @@
   $installed      = $opt_Z ? {} : get_installed();
   $repository     = get_index($url.'00INDEX.rdf',$opt_f,\%with);
   
  -($list,$bonly)  = build_list($pattern, {
  -                      config     => $config,
  -                      installed  => $installed,
  -                      repository => $repository,
  -                      built      => {},
  -                      revdep     => undef,
  -                      with       => \%with,
  -                      exclude    => \%exclude,
  -                      upgrade    => ($opt_a || $opt_U),
  -                      zero       => ($opt_z || $opt_Z),
  -                      quick      => $opt_q,
  -                      sourceonly => (
  -                                $opt_u ||
  -                                $opt_U ||
  -                                $opt_z ||
  -                                $opt_Z ||
  -                                scalar(%with) > 0 )
  -                  });
  +$env = {
  +    config     => $config,
  +    installed  => $installed,
  +    repository => $repository,
  +    built      => {},
  +    revdep     => undef,
  +    with       => \%with,
  +    exclude    => \%exclude,
  +    upgrade    => ($opt_a || $opt_U),
  +    zero       => ($opt_z || $opt_Z),
  +    quick      => $opt_q,
  +    status     => ($opt_s || $opt_S),
  +    fatal      => [],
  +    sourceonly => ($opt_u ||
  +                   $opt_U ||
  +                   $opt_z ||
  +                   $opt_Z ||
  +                   scalar(%with) > 0 )
  +};
   
  +($list,$bonly,$clist) = build_list($pattern, $env);
   die "FATAL: cannot find package\n" unless defined $list;
   
  -print_list1($list,$config,$opt_a || $opt_u || $opt_U,\%with,$opt_i);
  -print_list2($bonly,$config);
  +if ($opt_S) {
  +    print_status($installed,$repository,$list,$bonly,$clist);
  +} elsif ($opt_s) {
  +    print_status($installed,{},$list,$bonly,$clist);
  +} else {
  +    if (@{$env->{fatal}}) {
  +        die "FATAL errors occured while building:\n",
  +            join ',',
  +                @{$env->{fatal}},
  +            "\n";
  +    }
  +
  +    print_list1($list,$config,$opt_a || $opt_u || $opt_U,\%with,$opt_i);
  +    print_list2($bonly,$config);
  +}
   
  Index: openpkg-src/openpkg-tool/openpkg.pod
  ============================================================
  $ cvs diff -u -r1.4 -r1.5 openpkg.pod
  --- openpkg-src/openpkg-tool/openpkg.pod      27 Nov 2002 14:51:43 -0000      1.4
  +++ openpkg-src/openpkg-tool/openpkg.pod      3 Dec 2002 14:27:39 -0000       1.5
  @@ -57,6 +57,8 @@
   [B<-Z>]
   [B<-i>]
   [B<-q>]
  +[B<-s>]
  +[B<-S>]
   [B<-P> I<priv-cmd>]
   [B<-N> I<non-priv-cmd>]
   [B<-p> I<platform>]
  @@ -189,6 +191,63 @@
   
   Ignore all reverse dependencies.
   I<ATTENTION: this might break already installed packages!>
  +
  +=item B<-s>
  +
  +Print a status map instead of the install script. The map consists
  +of 3 columns: "old", "tag" and "new". "old" shows the installed
  +version of a package or just the package name if no package of
  +that name is installed and "new" shows the repository version
  +of a package if it is considered for installation. "tag" has the
  +following possible values:
  +
  +=over 4
  +
  +=item OK
  +
  +The installed package is suitable and will not be touched.
  +
  +=item ADD
  +
  +There is no installed package yet.
  +
  +=item UPGRADE
  +
  +The installed package is outdated and requires an update.
  +
  +=item DEPEND
  +
  +The installed package needs rebuilding because one of its
  +dependencies is rebuilt.
  +
  +=item MISMATCH
  +
  +The installed package needs rebuilding because it was build
  +with different parameters.
  +
  +=item CONFLICT
  +
  +The required new package cannot be installed because it
  +conflicts with some already installed package.
  +
  +=item UNDEF
  +
  +The package has an invalid or ambigous dependency.
  +
  +=back
  +
  +=item B<-S>
  +
  +Similar to B<-s> but also lists the newest versions in the
  +repository. The following tag might appear in the map.
  +
  +=over 4
  +
  +=item NEW
  +
  +The package exists in the repository but isn't required yet.
  +
  +=back
   
   =item B<-P> I<priv-cmd>
   
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     [EMAIL PROTECTED]

Reply via email to