Browse Source

optimize get_revdep, add -L and -W option for generating a dependency list

Michael van Elst 23 years ago
parent
commit
103c899907
3 changed files with 103 additions and 36 deletions
  1. 86 34
      openpkg-tool/openpkg-build.pl
  2. 2 2
      openpkg-tool/openpkg-tool.spec
  3. 15 0
      openpkg-tool/openpkg.pod

+ 86 - 34
openpkg-tool/openpkg-build.pl

@@ -29,8 +29,12 @@ require 5;
 $|=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 $opt_s $opt_S $opt_X $opt_M/;
-my $getopts = 'R:r:f:uUaAzZP:N:E:iD:p:qsSXM';
+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 $opt_X $opt_M $opt_L
+    $opt_W/;
+my $getopts = 'R:r:f:uUaAzZP:N:E:iD:p:qsSXMLW';
 getopts($getopts);
 
 ##########################################################################
@@ -116,7 +120,7 @@ sub conditional ($$) {
     my($cond,$with) = @_;
     my(@s,$res);
 
-    return 1 if $cond eq '';
+    return 1 if $cond eq '' || !defined $with;
 
     foreach (split(/\s+/,$cond)) {
         if ($_ eq '+') {
@@ -449,9 +453,8 @@ sub get_installed () {
 # compute reverse dependency map
 #
 #
-sub get_revdep ($) {
-    my($env) = @_;
-    my($i) = $env->{'installed'};
+sub get_revdep ($$) {
+    my($env, $i) = @_;
     my($r) = $env->{'repository'};
     my($pkg, %dep, %dlist, %rev);
     my(@vers,$t);
@@ -481,8 +484,10 @@ sub get_revdep ($) {
                 next unless $i->{$t->{name}};
                 next unless $t->{depends};
                 foreach (depends2pkglist($t->{depends})) {
-                    $dep{$_}{$t->{name}} = 1;
-                    push @{$dlist{$_}}, $t;
+                    unless ($dep{$_}{$t->{name}}) {
+                        $dep{$_}{$t->{name}} = 1;
+                        push @{$dlist{$_}}, $t;
+                    }
                 }
             }
         }
@@ -1389,7 +1394,7 @@ sub make_dep ($$$$$$$) {
         $target->{REBUILD}) {
 
         unless ($env->{revdep}) {
-            $env->{revdep} = get_revdep($env);
+            $env->{revdep} = get_revdep($env, $env->{intalled});
         }
 
         foreach $t (@{$env->{revdep}->{$target->{name}}}) {
@@ -1407,15 +1412,11 @@ sub make_dep ($$$$$$$) {
 }
 
 #
-# generate build lists for targets matched by pattern
+# grep environment for packages that match a pattern
 #
-# all input and output is passed in 'env' hash
-#
-sub build_list ($$) {
+sub search_pattern ($$) {
     my($pattern, $env) = @_;
-    my(@goals,@targets,@keeps,@conflicts,@bonly,$t);
-    my($name,$r,$i,@vers);
-    my(@todo,%keep);
+    my(@todo);
 
     #
     # handle various patterns
@@ -1446,10 +1447,26 @@ sub build_list ($$) {
                 } keys %{$env->{repository}};
     }
 
+    return \@todo;
+}
+
+#
+# generate build lists for targets matched by pattern
+#
+# all input and output is passed in 'env' hash
+#
+sub build_list ($$) {
+    my($pattern, $env) = @_;
+    my(@goals,@targets,@keeps,@conflicts,@bonly,$t);
+    my($name,$r,$i,@vers);
+    my($todo,%keep);
+
+    $todo = search_pattern($pattern, $env);
+
     #
     # chose sources for goals from repository
     #
-    foreach $name (@todo) {
+    foreach $name (@$todo) {
         $t = undef;
 
         #
@@ -1502,6 +1519,21 @@ sub build_list ($$) {
     return (\@targets, \@bonly, \@conflicts);
 }
 
+sub build_deps ($$) {
+    my($pattern, $env) = @_;
+    my($todo);
+
+    $todo = search_pattern($pattern, $env);
+
+    $env->{revdep} = get_revdep($env, $env->{repository});
+
+    return [ map {
+        $env->{revdep}->{$_}
+        ? ( @{$env->{revdep}->{$_}} )
+        : ( )
+    } @$todo ];
+}
+
 #######################################################################
 
 #
@@ -1765,6 +1797,17 @@ sub print_map ($$$$$) {
     }
 }
 
+#
+# print dependency list
+#
+sub print_deps ($) {
+    my($list) = @_;
+
+    foreach (@$list) {
+        print vsn($_),"\n";
+    }
+}
+
 #######################################################################
 
 my($config,$url,$repository,$installed,$env,$list,$bonly,$clist);
@@ -1809,7 +1852,11 @@ if (defined $opt_f && !defined $opt_r) {
 }
 
 $installed      = $opt_Z ? {} : get_installed();
-$repository     = get_index($url.'00INDEX.rdf',$opt_f,\%with,$opt_X);
+$repository     = get_index(
+                    $url.'00INDEX.rdf',
+                    $opt_f,
+                    ($opt_W ? undef : \%with),
+                    $opt_X);
 
 $env = {
     config     => $config,
@@ -1831,23 +1878,28 @@ $env = {
                    scalar(%with) > 0 )
 };
 
-($list,$bonly,$clist) = build_list($pattern, $env);
-die "FATAL: cannot find package\n" unless defined $list;
-
-if ($opt_M) {
-    print_map($installed,$repository,$list,$bonly,$clist);
-} elsif ($opt_S) {
-    print_status($installed,$repository,$list,$bonly,$clist);
-} elsif ($opt_s) {
-    print_status($installed,{},$list,$bonly,$clist);
+if ($opt_L) {
+    ($list) = build_deps($pattern, $env);
+    print_deps($list);
 } else {
-    if (@{$env->{fatal}}) {
-        die "FATAL errors occured while building:\n",
-            join (',', @{$env->{fatal}}),
-            "\n";
-    }
+    ($list,$bonly,$clist) = build_list($pattern, $env);
+    die "FATAL: cannot find package\n" unless defined $list;
+
+    if ($opt_M) {
+        print_map($installed,$repository,$list,$bonly,$clist);
+    } elsif ($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);
+        print_list1($list,$config,$opt_a || $opt_u || $opt_U,\%with,$opt_i);
+        print_list2($bonly,$config);
+    }
 }
 

+ 2 - 2
openpkg-tool/openpkg-tool.spec

@@ -32,8 +32,8 @@ Packager:     The OpenPKG Project
 Distribution: OpenPKG [PLUS]
 Group:        Bootstrapping
 License:      GPL
-Version:      20030114
-Release:      20030114
+Version:      20030115
+Release:      20030115
 
 #   list of sources
 Source0:      openpkg.sh

+ 15 - 0
openpkg-tool/openpkg.pod

@@ -60,6 +60,8 @@ B<build>
 [B<-s>]
 [B<-S>]
 [B<-M>]
+[B<-L>]
+[B<-W>]
 [B<-X>]
 [B<-P> I<priv-cmd>]
 [B<-N> I<non-priv-cmd>]
@@ -255,6 +257,19 @@ The package exists in the repository but isn't required yet.
 
 Similar to B<-s> but print a short dependency map.
 
+=item B<-L>
+
+Print a list of packages in the repository that depend on the target.
+
+=item B<-W>
+
+Include all conditional dependencies as if all possible configuration
+options had been switched on. This has little use except for generating
+an all-inclusive list with the B<-L> option.
+I<ATTENTION: Even mutually exclusive options are evaluated to be 'on',
+building packages with B<-W> therefore might fail or cause unusuable
+results!>
+
 =item B<-X>
 
 Ignore an installed XML parser module but use the internal