| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | #!@PERL5@ | | 1 | #!@PERL5@ |
2 | # $NetBSD: lintpkgsrc.pl,v 1.98 2022/08/16 18:47:50 rillig Exp $ | | 2 | # $NetBSD: lintpkgsrc.pl,v 1.99 2022/08/16 18:58:00 rillig Exp $ |
3 | | | 3 | |
4 | # Written by David Brownlee <abs@netbsd.org>. | | 4 | # Written by David Brownlee <abs@netbsd.org>. |
5 | # | | 5 | # |
6 | # Caveats: | | 6 | # Caveats: |
7 | # The 'Makefile parsing' algorithm used to obtain package versions and | | 7 | # The 'Makefile parsing' algorithm used to obtain package versions and |
8 | # DEPENDS information is geared towards speed rather than perfection, | | 8 | # DEPENDS information is geared towards speed rather than perfection, |
9 | # though it has gotten somewhat better over time, it only parses the | | 9 | # though it has gotten somewhat better over time, it only parses the |
10 | # simpler Makefile conditionals. | | 10 | # simpler Makefile conditionals. |
11 | # | | 11 | # |
12 | # TODO: Handle fun DEPENDS like avifile-devel with | | 12 | # TODO: Handle fun DEPENDS like avifile-devel with |
13 | # {qt2-designer>=2.2.4,qt2-designer-kde>=2.3.1nb1} | | 13 | # {qt2-designer>=2.2.4,qt2-designer-kde>=2.3.1nb1} |
14 | | | 14 | |
15 | use v5.36; | | 15 | use v5.36; |
| @@ -1395,49 +1395,38 @@ sub remove_distfiles($pkgsrcdir, $pkgdis | | | @@ -1395,49 +1395,38 @@ sub remove_distfiles($pkgsrcdir, $pkgdis |
1395 | if ($pkgname =~ /^([^*?[]+)-([\d*?[].*)/) { | | 1395 | if ($pkgname =~ /^([^*?[]+)-([\d*?[].*)/) { |
1396 | foreach my $pkgver ($pkgdb->pkgvers_by_pkgbase($1)) { | | 1396 | foreach my $pkgver ($pkgdb->pkgvers_by_pkgbase($1)) { |
1397 | next if $pkgver->var('dir') =~ /-current/; | | 1397 | next if $pkgver->var('dir') =~ /-current/; |
1398 | push @installed, $pkgver; | | 1398 | push @installed, $pkgver; |
1399 | last; | | 1399 | last; |
1400 | } | | 1400 | } |
1401 | } | | 1401 | } |
1402 | } | | 1402 | } |
1403 | | | 1403 | |
1404 | # distfiles belonging to the currently installed packages | | 1404 | # distfiles belonging to the currently installed packages |
1405 | my (%distfiles, @pkgdistfiles); | | 1405 | my (%distfiles, @pkgdistfiles); |
1406 | foreach my $pkgver (sort @installed) { | | 1406 | foreach my $pkgver (sort @installed) { |
1407 | my $pkgpath = $pkgver->var('dir'); | | 1407 | my $pkgpath = $pkgver->var('dir'); |
1408 | next unless open(DISTINFO, "$pkgsrcdir/$pkgpath/distinfo"); | | 1408 | foreach my $entry (load_distinfo("$pkgsrcdir/$pkgpath")) { |
1409 | while (<DISTINFO>) { | | 1409 | my $distfile = $entry->{distfile}; |
1410 | next unless m/^(\w+) ?\(([^\)]+)\) = (\S+)/; | | 1410 | next if $distfile =~ /^patch-[\w.+\-]+$/; |
1411 | my $dn = $2; | | 1411 | next if defined $distfiles{$distfile}; |
1412 | next if $dn =~ /^patch-[\w.+\-]+$/; | | 1412 | $distfiles{$distfile}->{name} = $distfile; |
1413 | # Strip leading ./ which sometimes gets added | | 1413 | push @pkgdistfiles, $distfile; |
1414 | # because of DISTSUBDIR=. | | | |
1415 | $dn =~ s/^(\.\/)*//; | | | |
1416 | if (!defined $distfiles{$dn}) { | | | |
1417 | $distfiles{$dn}{name} = $dn; | | | |
1418 | push @pkgdistfiles, $dn; | | | |
1419 | } | | | |
1420 | } | | 1414 | } |
1421 | close(DISTINFO); | | | |
1422 | } | | 1415 | } |
1423 | | | 1416 | |
1424 | # distfiles downloaded on the current system | | 1417 | # distfiles downloaded on the current system |
1425 | my @tmpdistfiles = listdir("$pkgdistdir", undef); | | 1418 | my @dldistfiles = sort grep { $_ ne 'pkg-vulnerabilities' } |
1426 | my @dldistfiles = grep { $_ ne 'pkg-vulnerabilities' } @tmpdistfiles; | | 1419 | listdir("$pkgdistdir", undef); |
1427 | | | | |
1428 | # sort the two arrays to make searching a bit faster | | | |
1429 | @dldistfiles = sort @dldistfiles; | | | |
1430 | @pkgdistfiles = sort @pkgdistfiles; | | | |
1431 | | | 1420 | |
1432 | if ($opt{y}) { | | 1421 | if ($opt{y}) { |
1433 | # looking for files that are downloaded on the current system | | 1422 | # looking for files that are downloaded on the current system |
1434 | # but do not belong to any currently installed package i.e. orphaned | | 1423 | # but do not belong to any currently installed package i.e. orphaned |
1435 | my $found = 0; | | 1424 | my $found = 0; |
1436 | my @orphan; | | 1425 | my @orphan; |
1437 | foreach my $dldf (@dldistfiles) { | | 1426 | foreach my $dldf (@dldistfiles) { |
1438 | foreach my $pkgdf (@pkgdistfiles) { | | 1427 | foreach my $pkgdf (@pkgdistfiles) { |
1439 | if ($dldf eq $pkgdf) { | | 1428 | if ($dldf eq $pkgdf) { |
1440 | $found = 1; | | 1429 | $found = 1; |
1441 | } | | 1430 | } |
1442 | } | | 1431 | } |
1443 | if ($found != 1) { | | 1432 | if ($found != 1) { |
| @@ -1451,27 +1440,27 @@ sub remove_distfiles($pkgsrcdir, $pkgdis | | | @@ -1451,27 +1440,27 @@ sub remove_distfiles($pkgsrcdir, $pkgdis |
1451 | chdir_or_fail("$pkgdistdir"); | | 1440 | chdir_or_fail("$pkgdistdir"); |
1452 | verbose("Unlinking 'orphaned' distfiles\n"); | | 1441 | verbose("Unlinking 'orphaned' distfiles\n"); |
1453 | foreach my $distfile (@orphan) { | | 1442 | foreach my $distfile (@orphan) { |
1454 | unlink($distfile) | | 1443 | unlink($distfile) |
1455 | } | | 1444 | } |
1456 | } | | 1445 | } |
1457 | } | | 1446 | } |
1458 | | | 1447 | |
1459 | if ($opt{z}) { | | 1448 | if ($opt{z}) { |
1460 | # looking for files that are downloaded on the current system | | 1449 | # looking for files that are downloaded on the current system |
1461 | # but belong to a currently installed package i.e. parented | | 1450 | # but belong to a currently installed package i.e. parented |
1462 | my $found = 0; | | 1451 | my $found = 0; |
1463 | my @parent; | | 1452 | my @parent; |
1464 | foreach my $pkgdf (@pkgdistfiles) { | | 1453 | foreach my $pkgdf (sort @pkgdistfiles) { |
1465 | foreach my $dldf (@dldistfiles) { | | 1454 | foreach my $dldf (@dldistfiles) { |
1466 | if ($pkgdf eq $dldf) { | | 1455 | if ($pkgdf eq $dldf) { |
1467 | $found = 1; | | 1456 | $found = 1; |
1468 | } | | 1457 | } |
1469 | } | | 1458 | } |
1470 | if ($found == 1) { | | 1459 | if ($found == 1) { |
1471 | push @parent, $pkgdf; | | 1460 | push @parent, $pkgdf; |
1472 | print "Parented file: $pkgdf\n"; | | 1461 | print "Parented file: $pkgdf\n"; |
1473 | } | | 1462 | } |
1474 | $found = 0; | | 1463 | $found = 0; |
1475 | } | | 1464 | } |
1476 | | | 1465 | |
1477 | if ($opt{r}) { | | 1466 | if ($opt{r}) { |