From 74c52ac8ad9d5e7383de4a7f495d087f14ce51a7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 30 Jul 2013 11:45:54 +0200 Subject: 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. --- maintainers/scripts/nixpkgs-lint.pl | 54 +++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'maintainers/scripts/nixpkgs-lint.pl') diff --git a/maintainers/scripts/nixpkgs-lint.pl b/maintainers/scripts/nixpkgs-lint.pl index 0b1519ef15c..c82cf75e3f8 100755 --- a/maintainers/scripts/nixpkgs-lint.pl +++ b/maintainers/scripts/nixpkgs-lint.pl @@ -3,25 +3,43 @@ use strict; use List::Util qw(min); use XML::Simple qw(:strict); -use Data::Dumper; +use Getopt::Long qw(:config gnu_getopt); +# Parse the command line. +my $path = ""; my $filter = "*"; +my $maintainer; -my $xml = `nix-env -f . -qa '$filter' --xml --meta --drv-path`; +sub showHelp { + print < { 'item' => '+attrPath', 'meta' => 'name' }, ForceArray => 1, SuppressEmpty => '' ) or die "cannot parse XML output"; - -#print Dumper($info); +Check Nixpkgs for common errors/problems. -my %pkgsByName; + -p, --package filter packages by name (default is ‘*’) + -m, --maintainer filter packages by maintainer (case-insensitive regexp) + -f, --file path to Nixpkgs (default is ‘’) -foreach my $attr (sort keys %{$info->{item}}) { - my $pkg = $info->{item}->{$attr}; - #print STDERR "attr = $attr, name = $pkg->{name}\n"; - $pkgsByName{$pkg->{name}} //= []; - push @{$pkgsByName{$pkg->{name}}}, $pkg; +Examples: + \$ nixpkgs-lint -f /my/nixpkgs -p firefox + \$ nixpkgs-lint -f /my/nixpkgs -m eelco +EOF + exit 0; } +GetOptions("package|p=s" => \$filter, + "maintainer|m=s" => \$maintainer, + "file|f=s" => \$path, + "help" => sub { showHelp() } + ) + or die("syntax: $0 ...\n"); + +# Evaluate Nixpkgs into an XML representation. +my $xml = `nix-env -f '$path' -qa '$filter' --xml --meta --drv-path`; +die "$0: evaluation of ‘$path’ failed\n" if $? != 0; + +my $info = XMLin($xml, KeyAttr => { 'item' => '+attrPath', 'meta' => 'name' }, ForceArray => 1, SuppressEmpty => '' ) or die "cannot parse XML output"; + # Check meta information. print "=== Package meta information ===\n\n"; my $nrMissingMaintainers = 0; @@ -44,6 +62,11 @@ foreach my $attr (sort keys %{$info->{item}}) { @maintainers = ($x->{value}); } + if (defined $maintainer && scalar(grep { $_ =~ /$maintainer/i } @maintainers) == 0) { + delete $info->{item}->{$attr}; + next; + } + if (scalar @maintainers == 0) { print "$attr: Lacks a maintainer\n"; $nrMissingMaintainers++; @@ -86,6 +109,15 @@ print "\n"; # Find packages that have the same name. print "=== Package name collisions ===\n\n"; +my %pkgsByName; + +foreach my $attr (sort keys %{$info->{item}}) { + my $pkg = $info->{item}->{$attr}; + #print STDERR "attr = $attr, name = $pkg->{name}\n"; + $pkgsByName{$pkg->{name}} //= []; + push @{$pkgsByName{$pkg->{name}}}, $pkg; +} + my $nrCollisions = 0; foreach my $name (sort keys %pkgsByName) { my @pkgs = @{$pkgsByName{$name}}; -- cgit 1.4.1