pkgcheck icon indicating copy to clipboard operation
pkgcheck copied to clipboard

[Feature request] CLI option to check the reverse dependencies of the (current/specified/changed) packages.

Open kentfredric opened this issue 5 years ago • 4 comments

This is very helpful to do when doing keywording work. You don't want to have to scan the whole tree just to find revdeps with keyword problems.

And I've found a neat hack that does 95% of the work without any of the performance problems.

#!perl
use strict;
use warnings;

use constant root      => "/usr/local/gentoo";
use constant http_root => "https://qa-reports.gentoo.org/output/genrdeps/";

my $client = do {
    require HTTP::Tiny;
    HTTP::Tiny->new();
};

my ( $package, $match ) = @ARGV;

my $deps = {};
for my $grade ( 'rindex', 'dindex', 'pindex', 'bindex' ) {
    my $result = $client->get( http_root . $grade . '/' . $package );
    if ( $result->{success} ) {
      for my $line ( split qr/\n/, $result->{content} ) {
        my $data = {
          in => $grade,
          statement => $line,
        };
        if ( $line =~ s/:([^:]+)$// ) {
          $data->{use} = $1;
        }
        $deps->{$line} ||=[];
        push @{$deps->{$line}}, $data;
      }
    }
}
my %categories;
for my $dep ( sort keys %{$deps} ) {
  my $package = get_package($dep);
  my ( $category, $pn ) = split q[/], $package;
  $categories{$category}{$pn}++;
}
for my $category ( sort keys %categories ) {
  chdir root . $category;
  print "\e[31m> $category\e[0m\n";
  printf "\e[31m  %s\e[0m\n", join q[, ], sort keys %{$categories{$category}};
  system('pkgcheck', 'scan','-v', '-s=-profiles', sort keys %{$categories{$category}} ) == 0
    or die;

}

sub get_package {
  my ( $atom ) = @_;
  open my $fh, '-|', 'qatom', '-F', "%{CATEGORY}/%{PN}", $atom or die "Can't invoke qatom";
  my $content = do {
    local $/ = undef;
    <$fh>;
  };
  chomp $content;
  return $content;
}

This is a really simply cheap hack:

  • Query https://qa-reports.gentoo.org/output/genrdeps/ for revdeps
  • Parse it
  • Mangle it into {CAT}/{PN}
  • Run pkgcheck scan on {CAT}/{PN}

I'm sure there's a better way to do this natively though.

kentfredric avatar Jul 18 '20 11:07 kentfredric

You're spending too much time on perl.

https://github.com/mgorny/mgorny-dev-scripts/blob/master/rdep

Much less code and supports fetching the whole revdep tree as cache.

mgorny avatar Jul 18 '20 12:07 mgorny

Much less code

Of course its less code.

a. Half of that code I just forgot to remove out of something else b. It does substantially less.

kentfredric avatar Jul 18 '20 12:07 kentfredric

fetching the whole revdep tree as cache.

Would be a simple change of

  ->get( uri )

to

  ->mirror( uri, file )

But that's not the point. This is just a trival example showing what can be done, not that it should be used wholesale this way.

kentfredric avatar Jul 18 '20 12:07 kentfredric

To do this properly, a local revdeps cache (https://github.com/pkgcore/pkgcheck/issues/285) needs to be generated as well as support for temporary cache splicing with local git repo changes. Using a remote source would often not be fully correct and therefore pointless.

radhermit avatar Sep 15 '20 05:09 radhermit