nixpkgs-lint: Add support for filtering by maintainer

For instance, you can now say "nixpkgs-lint -m alice" to show only
packages maintained by Alice.

Also added command-line parsing.

+43 -11
+43 -11
maintainers/scripts/nixpkgs-lint.pl
··· 3 use strict; 4 use List::Util qw(min); 5 use XML::Simple qw(:strict); 6 - use Data::Dumper; 7 8 my $filter = "*"; 9 10 - my $xml = `nix-env -f . -qa '$filter' --xml --meta --drv-path`; 11 12 - my $info = XMLin($xml, KeyAttr => { 'item' => '+attrPath', 'meta' => 'name' }, ForceArray => 1, SuppressEmpty => '' ) or die "cannot parse XML output"; 13 14 - #print Dumper($info); 15 16 - my %pkgsByName; 17 - 18 - foreach my $attr (sort keys %{$info->{item}}) { 19 - my $pkg = $info->{item}->{$attr}; 20 - #print STDERR "attr = $attr, name = $pkg->{name}\n"; 21 - $pkgsByName{$pkg->{name}} //= []; 22 - push @{$pkgsByName{$pkg->{name}}}, $pkg; 23 } 24 25 # Check meta information. 26 print "=== Package meta information ===\n\n"; 27 my $nrMissingMaintainers = 0; ··· 44 @maintainers = ($x->{value}); 45 } 46 47 if (scalar @maintainers == 0) { 48 print "$attr: Lacks a maintainer\n"; 49 $nrMissingMaintainers++; ··· 85 86 # Find packages that have the same name. 87 print "=== Package name collisions ===\n\n"; 88 89 my $nrCollisions = 0; 90 foreach my $name (sort keys %pkgsByName) {
··· 3 use strict; 4 use List::Util qw(min); 5 use XML::Simple qw(:strict); 6 + use Getopt::Long qw(:config gnu_getopt); 7 8 + # Parse the command line. 9 + my $path = "<nixpkgs>"; 10 my $filter = "*"; 11 + my $maintainer; 12 13 + sub showHelp { 14 + print <<EOF; 15 + Usage: $0 [--package=NAME] [--maintainer=REGEXP] [--file=PATH] 16 17 + Check Nixpkgs for common errors/problems. 18 19 + -p, --package filter packages by name (default is ‘*’) 20 + -m, --maintainer filter packages by maintainer (case-insensitive regexp) 21 + -f, --file path to Nixpkgs (default is ‘<nixpkgs>’) 22 23 + Examples: 24 + \$ nixpkgs-lint -f /my/nixpkgs -p firefox 25 + \$ nixpkgs-lint -f /my/nixpkgs -m eelco 26 + EOF 27 + exit 0; 28 } 29 30 + GetOptions("package|p=s" => \$filter, 31 + "maintainer|m=s" => \$maintainer, 32 + "file|f=s" => \$path, 33 + "help" => sub { showHelp() } 34 + ) 35 + or die("syntax: $0 ...\n"); 36 + 37 + # Evaluate Nixpkgs into an XML representation. 38 + my $xml = `nix-env -f '$path' -qa '$filter' --xml --meta --drv-path`; 39 + die "$0: evaluation of ‘$path’ failed\n" if $? != 0; 40 + 41 + my $info = XMLin($xml, KeyAttr => { 'item' => '+attrPath', 'meta' => 'name' }, ForceArray => 1, SuppressEmpty => '' ) or die "cannot parse XML output"; 42 + 43 # Check meta information. 44 print "=== Package meta information ===\n\n"; 45 my $nrMissingMaintainers = 0; ··· 62 @maintainers = ($x->{value}); 63 } 64 65 + if (defined $maintainer && scalar(grep { $_ =~ /$maintainer/i } @maintainers) == 0) { 66 + delete $info->{item}->{$attr}; 67 + next; 68 + } 69 + 70 if (scalar @maintainers == 0) { 71 print "$attr: Lacks a maintainer\n"; 72 $nrMissingMaintainers++; ··· 108 109 # Find packages that have the same name. 110 print "=== Package name collisions ===\n\n"; 111 + 112 + my %pkgsByName; 113 + 114 + foreach my $attr (sort keys %{$info->{item}}) { 115 + my $pkg = $info->{item}->{$attr}; 116 + #print STDERR "attr = $attr, name = $pkg->{name}\n"; 117 + $pkgsByName{$pkg->{name}} //= []; 118 + push @{$pkgsByName{$pkg->{name}}}, $pkg; 119 + } 120 121 my $nrCollisions = 0; 122 foreach my $name (sort keys %pkgsByName) {