Skip to content

Commit

Permalink
Implement --recursive for 'fink list --format=dotty*' modes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmacks committed Nov 27, 2014
1 parent 4ad47fd commit 1d454b5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
15 changes: 12 additions & 3 deletions fink.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,11 @@ and other
tools (compare to the human-readable list format of the
.Cm fink show-deps
command). This output mode just gives runtime dependencies of each
package You can parse the output to get reverse-depends
package. This format mode also supports the
.Cm --recursive
list-option.
.Pp
You can parse the output to get reverse-depends
information, for example:
.Dl fink list --format=dotty | grep ' \*[q]libgettext8-shlibs\*[q]'
will list all packages that have a runtime dependency on the
Expand All @@ -404,10 +408,15 @@ tools (compare to the human-readable list format of the
.Cm fink show-deps
command). This output mode gives compiletime dependencies of each
package, which includes runtime and build dependencies of every
package in a family (packages built together). Using the
package in a family (packages built together). This format mode also
supports the
.Cm --recursive
list-option. Using the
.Cm -m
flag will also include dependencies for the package-family's
self-testing (i.e., including TestDepends data). You can parse the
self-testing (i.e., including TestDepends data).
.Pp
You can parse the
output to get reverse-builddepends information, for example:
.Dl fink -m list --format=dotty-build | grep ' \*[q]libgettext8-dev\*[q]'
will list all packages that have a compiletime dependency on the
Expand Down
49 changes: 45 additions & 4 deletions perlmod/Fink/Engine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,16 @@ sub _user_visible_versions {
}

sub do_real_list {
my (@selected);
my @selected; # list of pkg-names to list partly based on user options
my %list_always; # hash of pkg-names to list regardless of user options
my %pkg_listed; # hash of pkg-names that have already been listed
my %sel_opts = (
'installedstate' => 0,
'section' => undef,
'maintainer' => undef,
'buildonly' => undef,
'apropos_pattern' => undef,
'recursive' => undef,
);
# bits used by $sel_opts{intalledstate}
my $ISTATE_OUTDATED = 1;
Expand Down Expand Up @@ -532,6 +535,8 @@ sub do_real_list {
[ 'maintainer|m=s' => \$sel_opts{'maintainer'},
"Only list packages with the maintainer(s) matching EXPR\n" .
"(example: fink list --maintainer=beren12).", 'EXPR'],
[ 'recursive|r' => \$sel_opts{'recursive'},
"List recursively (dotty and dotty-build formats only)." ],
);
}
get_options($cmd, \@options, \@_,
Expand Down Expand Up @@ -570,10 +575,15 @@ sub do_real_list {
$fmt_opts{'desclen'} = 0;
}

if ( $sel_opts{'recursive'} && ($fmt_opts{'format'} ne 'dotty' && $fmt_opts{'format'} ne 'dotty_build') ) {
print "The chosen --format does not support the --recursive option\n";
}

Fink::Package->require_packages();
@selected = Fink::Package->list_packages(); # first gather all package-names
if ($cmd eq "list") {
# narrow down the list if user gave a regex on commandline
# NB: may be re-extended later based on --recursive
if (@_) {
# prepare the regex patterns
foreach (@_) {
Expand Down Expand Up @@ -606,6 +616,10 @@ sub do_real_list {

my $reload_disable_save = Fink::Status->is_reload_disabled(); # save previous setting
Fink::Status->disable_reload(1); # don't keep stat()ing status db

while (@selected) {
my @next_selected = (); # propagate additional from inner loop

foreach my $pname (sort @selected) {
my $package = Fink::Package->package_by_name($pname);

Expand All @@ -621,6 +635,7 @@ sub do_real_list {
my $vo = $lversion ? $package->get_version($lversion, 1) : 0;

my $iflag;
unless ($list_always{$pname}) {
if ($vo && $vo->is_installed()) {
if ($vo->is_type('dummy') && $vo->get_subtype('dummy') eq 'status') {
# Newer version than fink knows about
Expand All @@ -641,6 +656,7 @@ sub do_real_list {
next unless $sel_opts{installedstate} & $ISTATE_ABSENT;
$iflag = " ";
}
}

# Now load the fields
$vo = $lversion ? $package->get_version($lversion) : 0;
Expand All @@ -649,6 +665,7 @@ sub do_real_list {
? $vo->get_shortdescription($fmt_opts{'desclen'})
: '[virtual package]';

unless ($list_always{$pname}) {
if (defined $sel_opts{'buildonly'}) {
next unless $vo && $vo->param_boolean("builddependsonly");
}
Expand All @@ -666,6 +683,7 @@ sub do_real_list {
$ok ||= $vo->get_name() =~ /\Q$sel_opts{'apropos_pattern'}\E/i;
next unless $ok;
}
}

my $dispname = $pname;
if ($fmt_opts{'namelen'} && length($pname) > $fmt_opts{'namelen'}) {
Expand All @@ -681,21 +699,44 @@ sub do_real_list {
# for each ANDed (comma-sep) chunk...
for my $subdep (@$dep) {
# include all ORed items in it
$subdep =~ /^([+\-.a-z0-9]+)/; # only %n, not versioning
print "\"$pname\" -> \"$1\";\n";
my ($subdepname) = ($subdep =~ /^([+\-.a-z0-9]+)/); # only %n, not versioning
print "\"$pname\" -> \"$subdepname\";\n";
if ($sel_opts{'recursive'}) {
# as a dep, it *must* be listed
unless ($list_always{$subdepname}++) {
# haven't already found it implicitly;
# may have been excluded earlier
push @next_selected, $subdepname;
}
}
}
}
} else {
my @providers = $package->get_all_providers();
for my $provider (@providers) {
my $name = $provider->get_name();
print "\"$pname\" -> \"$name\";\n" if $name ne $pname;
if ($name ne $pname) {
print "\"$pname\" -> \"$name\";\n";
if ($sel_opts{'recursive'}) {
# as a dep, it *must* be listed
unless ($list_always{$name}++) {
# haven't already found it implicitly;
# may have been excluded earlier
push @next_selected, $name;
}
}
}
}
}
} else {
printf $fmt_opts{'formatstr'},
$iflag, $pname, $lversion, $description;
}

$pkg_listed{$pname}++; # track which ones we've done
}

@selected = @next_selected;
}

if ($fmt_opts{'format'} eq 'dotty' or $fmt_opts{'format'} eq 'dotty-build') {
Expand Down

0 comments on commit 1d454b5

Please sign in to comment.