| @@ -1,16 +1,16 @@ | | | @@ -1,16 +1,16 @@ |
1 | #!@PERL5@ | | 1 | #!@PERL5@ |
2 | | | 2 | |
3 | # $NetBSD: lintpkgsrc.pl,v 1.41 2022/07/30 17:30:47 rillig Exp $ | | 3 | # $NetBSD: lintpkgsrc.pl,v 1.42 2022/07/30 18:20:23 rillig Exp $ |
4 | | | 4 | |
5 | # Written by David Brownlee <abs@netbsd.org>. | | 5 | # Written by David Brownlee <abs@netbsd.org>. |
6 | # | | 6 | # |
7 | # Caveats: | | 7 | # Caveats: |
8 | # The 'Makefile parsing' algorithm used to obtain package versions and | | 8 | # The 'Makefile parsing' algorithm used to obtain package versions and |
9 | # DEPENDS information is geared towards speed rather than perfection, | | 9 | # DEPENDS information is geared towards speed rather than perfection, |
10 | # though it has gotten somewhat better over time, it only parses the | | 10 | # though it has gotten somewhat better over time, it only parses the |
11 | # simpler Makefile conditionals. | | 11 | # simpler Makefile conditionals. |
12 | # | | 12 | # |
13 | # TODO: Handle fun DEPENDS like avifile-devel with | | 13 | # TODO: Handle fun DEPENDS like avifile-devel with |
14 | # {qt2-designer>=2.2.4,qt2-designer-kde>=2.3.1nb1} | | 14 | # {qt2-designer>=2.2.4,qt2-designer-kde>=2.3.1nb1} |
15 | | | 15 | |
16 | use locale; | | 16 | use locale; |
| @@ -1467,316 +1467,344 @@ sub check_prebuilt_packages() { | | | @@ -1467,316 +1467,344 @@ sub check_prebuilt_packages() { |
1467 | if (-l $_) { | | 1467 | if (-l $_) { |
1468 | my ($dest) = readlink($_); | | 1468 | my ($dest) = readlink($_); |
1469 | | | 1469 | |
1470 | if (substr($dest, 0, 1) ne '/') { | | 1470 | if (substr($dest, 0, 1) ne '/') { |
1471 | $dest = "$File::Find::dir/$dest"; | | 1471 | $dest = "$File::Find::dir/$dest"; |
1472 | } | | 1472 | } |
1473 | if (!$prebuilt_pkgdir_cache{$dest}) { | | 1473 | if (!$prebuilt_pkgdir_cache{$dest}) { |
1474 | push(@prebuilt_pkgdirs, $dest); | | 1474 | push(@prebuilt_pkgdirs, $dest); |
1475 | } | | 1475 | } |
1476 | } | | 1476 | } |
1477 | } | | 1477 | } |
1478 | } | | 1478 | } |
1479 | | | 1479 | |
1480 | sub main() { | | 1480 | sub debug_parse_makefiles(@) { |
1481 | | | 1481 | |
1482 | $ENV{PATH} .= | | 1482 | foreach my $file (@_) { |
1483 | ":/bin:/usr/bin:/sbin:/usr/sbin:$conf_prefix/sbin:$conf_prefix/bin"; | | 1483 | -d $file and $file .= "/Makefile"; |
| | | 1484 | -f $file or fail("No such file: $file"); |
1484 | | | 1485 | |
1485 | if ( | | 1486 | my ($pkgname, $vars) = parse_makefile_pkgsrc($file); |
1486 | !getopts('BDE:I:K:LM:OP:RSVdg:himopruyz', \%opt) | | 1487 | $pkgname ||= 'uNDEFINEd'; |
1487 | || $opt{h} | | 1488 | |
1488 | || !grep(/[BDEORSdgimopruyz]/, keys %opt)) { | | 1489 | print "$file -> $pkgname\n"; |
1489 | usage_and_exit(); | | 1490 | foreach my $varname (sort keys %$vars) { |
| | | 1491 | print "\t$varname = $vars->{$varname}\n"; |
| | | 1492 | } |
| | | 1493 | |
| | | 1494 | #if ($opt{d}) { |
| | | 1495 | # pkgsrc_check_depends(); |
| | | 1496 | #} |
1490 | } | | 1497 | } |
1491 | $| = 1; | | 1498 | } |
1492 | | | 1499 | |
1493 | get_default_makefile_vars(); # $default_vars | | 1500 | sub check_distfiles($$) { |
| | | 1501 | my ($pkgsrcdir, $pkgdistdir) = @_; |
1494 | | | 1502 | |
1495 | if ($opt{D} && @ARGV) { | | 1503 | my @baddist = scan_pkgsrc_distfiles_vs_distinfo( |
1496 | foreach my $file (@ARGV) { | | 1504 | $pkgsrcdir, $pkgdistdir, $opt{o}, $opt{m}); |
1497 | if (-d $file) { | | 1505 | |
1498 | $file .= "/Makefile"; | | 1506 | return unless $opt{r}; |
1499 | } | | 1507 | verbose("Unlinking 'bad' distfiles\n"); |
1500 | if (!-f $file) { | | 1508 | foreach my $distfile (@baddist) { |
1501 | fail("No such file: $file"); | | 1509 | unlink("$pkgdistdir/$distfile"); |
1502 | } | | | |
1503 | my ($pkgname, $vars) = parse_makefile_pkgsrc($file); | | | |
1504 | $pkgname ||= 'uNDEFINEd'; | | | |
1505 | print "$file -> $pkgname\n"; | | | |
1506 | foreach my $varname (sort keys %{$vars}) { | | | |
1507 | print "\t$varname = $vars->{$varname}\n"; | | | |
1508 | } | | | |
1509 | | | | |
1510 | #if ($opt{d}) { | | | |
1511 | # pkgsrc_check_depends(); | | | |
1512 | #} | | | |
1513 | } | | | |
1514 | exit; | | | |
1515 | } | | 1510 | } |
| | | 1511 | } |
1516 | | | 1512 | |
1517 | my $pkgsrcdir = $default_vars->{PKGSRCDIR}; | | 1513 | sub remove_distfiles($$) { |
1518 | my $pkgdistdir = $default_vars->{DISTDIR}; | | 1514 | my ($pkgsrcdir, $pkgdistdir) = @_; |
1519 | | | 1515 | |
1520 | if ($opt{r} && !$opt{o} && !$opt{m} && !$opt{p}) { | | 1516 | my @pkgs = list_installed_packages(); |
1521 | $opt{o} = $opt{m} = $opt{p} = 1; | | 1517 | scan_pkgsrc_makefiles($pkgsrcdir); |
| | | 1518 | |
| | | 1519 | # list the installed packages and the directory they live in |
| | | 1520 | my @installed; |
| | | 1521 | foreach my $pkgname (sort @pkgs) { |
| | | 1522 | if ($pkgname =~ /^([^*?[]+)-([\d*?[].*)/) { |
| | | 1523 | foreach my $pkgver ($pkglist->pkgver($1)) { |
| | | 1524 | next if $pkgver->var('dir') =~ /-current/; |
| | | 1525 | push(@installed, $pkgver); |
| | | 1526 | last; |
| | | 1527 | } |
| | | 1528 | } |
1522 | } | | 1529 | } |
1523 | if ($opt{o} || $opt{m}) { | | | |
1524 | my (@baddist); | | | |
1525 | | | 1530 | |
1526 | @baddist = scan_pkgsrc_distfiles_vs_distinfo( | | 1531 | # distfiles belonging to the currently installed packages |
1527 | $pkgsrcdir, $pkgdistdir, $opt{o}, $opt{m}); | | 1532 | my (%distfiles, @pkgdistfiles); |
1528 | if ($opt{r}) { | | 1533 | foreach my $pkgver (sort @installed) { |
1529 | verbose("Unlinking 'bad' distfiles\n"); | | 1534 | my $pkgpath = $pkgver->var('dir'); |
1530 | foreach my $distfile (@baddist) { | | 1535 | next unless open(DISTINFO, "$pkgsrcdir/$pkgpath/distinfo"); |
1531 | unlink("$pkgdistdir/$distfile"); | | 1536 | while (<DISTINFO>) { |
| | | 1537 | next unless m/^(\w+) ?\(([^\)]+)\) = (\S+)/; |
| | | 1538 | my $dn = $2; |
| | | 1539 | next if $dn =~ /^patch-[\w.+\-]+$/; |
| | | 1540 | # Strip leading ./ which sometimes gets added |
| | | 1541 | # because of DISTSUBDIR=. |
| | | 1542 | $dn =~ s/^(\.\/)*//; |
| | | 1543 | if (!defined $distfiles{$dn}) { |
| | | 1544 | $distfiles{$dn}{name} = $dn; |
| | | 1545 | push(@pkgdistfiles, $dn); |
1532 | } | | 1546 | } |
1533 | } | | 1547 | } |
| | | 1548 | close(DISTINFO); |
1534 | } | | 1549 | } |
1535 | | | 1550 | |
1536 | # Remove all distfiles that are / are not part of an installed package | | 1551 | # distfiles downloaded on the current system |
1537 | if ($opt{y} || $opt{z}) { | | 1552 | my @tmpdistfiles = listdir("$pkgdistdir", undef); |
1538 | my (@pkgs, @installed, %distfiles, @pkgdistfiles, @dldistfiles); | | 1553 | my @dldistfiles = grep { $_ ne "pkg-vulnerabilities" } @tmpdistfiles; |
1539 | my (@tmpdistfiles, @orphan, $found, @parent); | | | |
1540 | | | 1554 | |
1541 | @pkgs = list_installed_packages(); | | 1555 | # sort the two arrays to make searching a bit faster |
1542 | scan_pkgsrc_makefiles($pkgsrcdir); | | 1556 | @dldistfiles = sort { $a cmp $b } @dldistfiles; |
| | | 1557 | @pkgdistfiles = sort { $a cmp $b } @pkgdistfiles; |
1543 | | | 1558 | |
1544 | # list the installed packages and the directory they live in | | 1559 | if ($opt{y}) { |
1545 | foreach my $pkgname (sort @pkgs) { | | 1560 | # looking for files that are downloaded on the current system |
1546 | if ($pkgname =~ /^([^*?[]+)-([\d*?[].*)/) { | | 1561 | # but do not belong to any currently installed package i.e. orphaned |
1547 | foreach my $pkgver ($pkglist->pkgver($1)) { | | 1562 | my $found = 0; |
1548 | $pkgver->var('dir') =~ /-current/ && next; | | 1563 | my @orphan; |
1549 | push(@installed, $pkgver); | | 1564 | foreach my $dldf (@dldistfiles) { |
1550 | last; | | 1565 | foreach my $pkgdf (@pkgdistfiles) { |
| | | 1566 | if ($dldf eq $pkgdf) { |
| | | 1567 | $found = 1; |
1551 | } | | 1568 | } |
1552 | } | | 1569 | } |
1553 | } | | 1570 | if ($found != 1) { |
1554 | | | 1571 | push(@orphan, $dldf); |
1555 | # distfiles belonging to the currently installed packages | | 1572 | print "Orphaned file: $dldf\n"; |
1556 | foreach my $pkgver (sort @installed) { | | | |
1557 | if (open(DISTINFO, "$pkgsrcdir/" . $pkgver->var('dir') . "/distinfo")) { | | | |
1558 | while (<DISTINFO>) { | | | |
1559 | if (m/^(\w+) ?\(([^\)]+)\) = (\S+)/) { | | | |
1560 | my ($dn); | | | |
1561 | if ($2 =~ /^patch-[\w.+\-]+$/) { next; } | | | |
1562 | $dn = $2; | | | |
1563 | # Strip leading ./ which sometimes gets added | | | |
1564 | # because of DISTSUBDIR=. | | | |
1565 | $dn =~ s/^(\.\/)*//; | | | |
1566 | if (!defined $distfiles{$dn}) { | | | |
1567 | $distfiles{$dn}{name} = $dn; | | | |
1568 | push(@pkgdistfiles, $dn); | | | |
1569 | } | | | |
1570 | } | | | |
1571 | } | | | |
1572 | close(DISTINFO); | | | |
1573 | } | | 1573 | } |
| | | 1574 | $found = 0; |
1574 | } | | 1575 | } |
1575 | | | 1576 | |
1576 | # distfiles downloaded on the current system | | 1577 | if ($opt{r}) { |
1577 | @tmpdistfiles = listdir("$pkgdistdir", undef); | | 1578 | chdir_or_fail("$pkgdistdir"); |
1578 | foreach my $tmppkg (@tmpdistfiles) { | | 1579 | verbose("Unlinking 'orphaned' distfiles\n"); |
1579 | if ($tmppkg ne "pkg-vulnerabilities") { | | 1580 | foreach my $distfile (@orphan) { |
1580 | push(@dldistfiles, $tmppkg); | | 1581 | unlink($distfile) |
1581 | } | | 1582 | } |
1582 | } | | 1583 | } |
| | | 1584 | } |
1583 | | | 1585 | |
1584 | # sort the two arrays to make searching a bit faster | | 1586 | if ($opt{z}) { |
1585 | @dldistfiles = sort { $a cmp $b } @dldistfiles; | | 1587 | # looking for files that are downloaded on the current system |
1586 | @pkgdistfiles = sort { $a cmp $b } @pkgdistfiles; | | 1588 | # but belong to a currently installed package i.e. parented |
1587 | | | 1589 | my $found = 0; |
1588 | if ($opt{y}) { | | 1590 | my @parent; |
1589 | # looking for files that are downloaded on the current system | | 1591 | foreach my $pkgdf (@pkgdistfiles) { |
1590 | # but do not belong to any currently installed package i.e. orphaned | | | |
1591 | $found = 0; | | | |
1592 | foreach my $dldf (@dldistfiles) { | | 1592 | foreach my $dldf (@dldistfiles) { |
1593 | foreach my $pkgdf (@pkgdistfiles) { | | 1593 | if ($pkgdf eq $dldf) { |
1594 | if ($dldf eq $pkgdf) { | | 1594 | $found = 1; |
1595 | $found = 1; | | | |
1596 | } | | | |
1597 | } | | 1595 | } |
1598 | if ($found != 1) { | | | |
1599 | push(@orphan, $dldf); | | | |
1600 | print "Orphaned file: $dldf\n"; | | | |
1601 | } | | | |
1602 | $found = 0; | | | |
1603 | } | | 1596 | } |
1604 | | | 1597 | if ($found == 1) { |
1605 | if ($opt{r}) { | | 1598 | push(@parent, $pkgdf); |
1606 | chdir_or_fail("$pkgdistdir"); | | 1599 | print "Parented file: $pkgdf\n"; |
1607 | verbose("Unlinking 'orphaned' distfiles\n"); | | | |
1608 | foreach my $distfile (@orphan) { | | | |
1609 | unlink($distfile) | | | |
1610 | } | | | |
1611 | } | | 1600 | } |
1612 | } | | | |
1613 | | | | |
1614 | if ($opt{z}) { | | | |
1615 | # looking for files that are downloaded on the current system | | | |
1616 | # but belong to a currently installed package i.e. parented | | | |
1617 | $found = 0; | | 1601 | $found = 0; |
1618 | foreach my $pkgdf (@pkgdistfiles) { | | | |
1619 | foreach my $dldf (@dldistfiles) { | | | |
1620 | if ($pkgdf eq $dldf) { | | | |
1621 | $found = 1; | | | |
1622 | } | | | |
1623 | } | | | |
1624 | if ($found == 1) { | | | |
1625 | push(@parent, $pkgdf); | | | |
1626 | print "Parented file: $pkgdf\n"; | | | |
1627 | } | | | |
1628 | $found = 0; | | | |
1629 | } | | | |
1630 | } | | 1602 | } |
1631 | | | 1603 | |
1632 | if ($opt{r}) { | | 1604 | if ($opt{r}) { |
1633 | chdir_or_fail("$pkgdistdir"); | | 1605 | chdir_or_fail("$pkgdistdir"); |
1634 | verbose("Unlinking 'parented' distfiles\n"); | | 1606 | verbose("Unlinking 'parented' distfiles\n"); |
1635 | foreach my $distfile (@parent) { | | 1607 | foreach my $distfile (@parent) { |
1636 | unlink($distfile); | | 1608 | unlink($distfile); |
1637 | } | | 1609 | } |
1638 | } | | 1610 | } |
1639 | } | | 1611 | } |
| | | 1612 | } |
1640 | | | 1613 | |
1641 | # List BROKEN packages | | 1614 | sub list_broken_packages($) { |
1642 | if ($opt{B}) { | | 1615 | my ($pkgsrcdir) = @_; |
1643 | scan_pkgsrc_makefiles($pkgsrcdir); | | 1616 | |
1644 | foreach my $pkgver ($pkglist->pkgver) { | | 1617 | scan_pkgsrc_makefiles($pkgsrcdir); |
1645 | $pkgver->var('BROKEN') || next; | | 1618 | foreach my $pkgver ($pkglist->pkgver) { |
1646 | print $pkgver->pkgname . ': ' . $pkgver->var('BROKEN') . "\n"; | | 1619 | my $broken = $pkgver->var('BROKEN'); |
1647 | } | | 1620 | next unless $broken; |
| | | 1621 | print $pkgver->pkgname . ": $broken\n"; |
1648 | } | | 1622 | } |
| | | 1623 | } |
1649 | | | 1624 | |
1650 | # List obsolete or NO_BIN_ON_FTP/RESTRICTED prebuilt packages | | 1625 | # List obsolete or NO_BIN_ON_FTP/RESTRICTED prebuilt packages |
1651 | # | | 1626 | # |
1652 | if ($opt{p} || $opt{O} || $opt{R}) { | | 1627 | sub list_prebuilt_packages($) { |
1653 | scan_pkgsrc_makefiles($pkgsrcdir); | | 1628 | my ($pkgsrcdir) = @_; |
1654 | | | 1629 | |
1655 | @prebuilt_pkgdirs = ($default_vars->{PACKAGES}); | | 1630 | scan_pkgsrc_makefiles($pkgsrcdir); |
1656 | %prebuilt_pkgdir_cache = (); | | | |
1657 | | | 1631 | |
1658 | while (@prebuilt_pkgdirs) { | | 1632 | @prebuilt_pkgdirs = ($default_vars->{PACKAGES}); |
1659 | find(\&check_prebuilt_packages, shift @prebuilt_pkgdirs); | | 1633 | %prebuilt_pkgdir_cache = (); |
1660 | } | | | |
1661 | | | 1634 | |
1662 | if ($opt{r}) { | | 1635 | while (@prebuilt_pkgdirs) { |
1663 | verbose("Unlinking listed prebuilt packages\n"); | | 1636 | find(\&check_prebuilt_packages, shift @prebuilt_pkgdirs); |
1664 | foreach my $pkgfile (@matched_prebuiltpackages) { | | 1637 | } |
1665 | unlink($pkgfile); | | 1638 | |
1666 | } | | 1639 | if ($opt{r}) { |
| | | 1640 | verbose("Unlinking listed prebuilt packages\n"); |
| | | 1641 | foreach my $pkgfile (@matched_prebuiltpackages) { |
| | | 1642 | unlink($pkgfile); |
1667 | } | | 1643 | } |
1668 | } | | 1644 | } |
| | | 1645 | } |
1669 | | | 1646 | |
1670 | if ($opt{S}) { | | 1647 | sub list_packages_not_in_SUBDIR($) { |
1671 | my (%in_subdir); | | 1648 | my ($pkgsrcdir) = @_; |
1672 | | | 1649 | |
1673 | foreach my $cat (list_pkgsrc_categories($pkgsrcdir)) { | | 1650 | my (%in_subdir); |
1674 | my $vars = parse_makefile_vars("$pkgsrcdir/$cat/Makefile", undef); | | 1651 | foreach my $cat (list_pkgsrc_categories($pkgsrcdir)) { |
| | | 1652 | my $vars = parse_makefile_vars("$pkgsrcdir/$cat/Makefile", undef); |
1675 | | | 1653 | |
1676 | if (!$vars->{SUBDIR}) { | | 1654 | if (!$vars->{SUBDIR}) { |
1677 | print "Warning - no SUBDIR for $cat\n"; | | 1655 | print "Warning - no SUBDIR for $cat\n"; |
1678 | next; | | 1656 | next; |
1679 | } | | | |
1680 | foreach my $pkgdir (split(/\s+/, $vars->{SUBDIR})) { | | | |
1681 | $in_subdir{"$cat/$pkgdir"} = 1; | | | |
1682 | } | | | |
1683 | } | | 1657 | } |
| | | 1658 | foreach my $pkgdir (split(/\s+/, $vars->{SUBDIR})) { |
| | | 1659 | $in_subdir{"$cat/$pkgdir"} = 1; |
| | | 1660 | } |
| | | 1661 | } |
1684 | | | 1662 | |
1685 | scan_pkgsrc_makefiles($pkgsrcdir); | | 1663 | scan_pkgsrc_makefiles($pkgsrcdir); |
1686 | foreach my $pkgver ($pkglist->pkgver) { | | 1664 | foreach my $pkgver ($pkglist->pkgver) { |
1687 | if (!defined $in_subdir{ $pkgver->var('dir') }) { | | 1665 | my $pkgpath = $pkgver->var('dir'); |
1688 | print $pkgver->var('dir') . ": Not in SUBDIR\n"; | | 1666 | if (!defined $in_subdir{$pkgpath}) { |
1689 | } | | 1667 | print "$pkgpath: Not in SUBDIR\n"; |
1690 | } | | 1668 | } |
1691 | } | | 1669 | } |
| | | 1670 | } |
1692 | | | 1671 | |
1693 | if ($opt{g}) { | | 1672 | sub generate_map_file($$) { |
1694 | my $tmpfile = "$opt{g}.tmp.$$"; | | 1673 | my ($pkgsrcdir, $fname) = @_; |
1695 | | | 1674 | |
1696 | scan_pkgsrc_makefiles($pkgsrcdir); | | 1675 | my $tmpfile = "$fname.tmp.$$"; |
1697 | if (!open(TABLE, ">$tmpfile")) { | | 1676 | |
1698 | fail("Unable to write '$tmpfile': $!"); | | 1677 | scan_pkgsrc_makefiles($pkgsrcdir); |
1699 | } | | 1678 | open(TABLE, '>', $tmpfile) or fail("Cannot write '$tmpfile': $!"); |
1700 | foreach my $pkgver ($pkglist->pkgver) { | | 1679 | foreach my $pkgver ($pkglist->pkgver) { |
1701 | print TABLE $pkgver->pkg . "\t" | | 1680 | print TABLE $pkgver->pkg . "\t" |
1702 | . $pkgver->var('dir') . "\t" | | 1681 | . $pkgver->var('dir') . "\t" |
1703 | . $pkgver->ver . "\n"; | | 1682 | . $pkgver->ver . "\n"; |
1704 | } | | | |
1705 | if (!close(TABLE)) { | | | |
1706 | fail("Error while writing '$tmpfile': $!"); | | | |
1707 | } | | | |
1708 | if (!rename($tmpfile, $opt{g})) { | | | |
1709 | fail("Error in rename('$tmpfile','$opt{g}'): $!"); | | | |
1710 | } | | | |
1711 | } | | 1683 | } |
| | | 1684 | close(TABLE) or fail("close('$tmpfile'): $!"); |
| | | 1685 | rename($tmpfile, $fname) |
| | | 1686 | or fail("rename('$tmpfile', '$fname'): $!"); |
| | | 1687 | } |
1712 | | | 1688 | |
1713 | if ($opt{d}) { | | 1689 | sub check_outdated_installed_packages($) { |
1714 | scan_pkgsrc_makefiles($pkgsrcdir); | | 1690 | my ($pkgsrcdir) = @_; |
1715 | pkgsrc_check_depends(); | | 1691 | |
| | | 1692 | my @pkgs = list_installed_packages(); |
| | | 1693 | scan_pkgsrc_makefiles($pkgsrcdir); |
| | | 1694 | |
| | | 1695 | my @update; |
| | | 1696 | foreach my $pkgname (sort @pkgs) { |
| | | 1697 | next unless $_ = invalid_version($pkgname); |
| | | 1698 | |
| | | 1699 | print $_; |
| | | 1700 | next unless $pkgname =~ /^([^*?[]+)-([\d*?[].*)/; |
| | | 1701 | |
| | | 1702 | foreach my $pkgver ($pkglist->pkgver($1)) { |
| | | 1703 | next if $pkgver->var('dir') =~ /-current/; |
| | | 1704 | push(@update, $pkgver); |
| | | 1705 | last; |
| | | 1706 | } |
1716 | } | | 1707 | } |
1717 | | | 1708 | |
1718 | if ($opt{i} || $opt{u}) { | | 1709 | return unless $opt{u}; |
1719 | my (@pkgs, @update); | | | |
1720 | | | 1710 | |
1721 | @pkgs = list_installed_packages(); | | 1711 | print "\nREQUIRED details for packages that could be updated:\n"; |
1722 | scan_pkgsrc_makefiles($pkgsrcdir); | | | |
1723 | | | 1712 | |
1724 | foreach my $pkgname (sort @pkgs) { | | 1713 | foreach my $pkgver (@update) { |
1725 | if ($_ = invalid_version($pkgname)) { | | 1714 | print $pkgver->pkg . ':'; |
1726 | print $_; | | 1715 | if (open(PKGINFO, 'pkg_info -R ' . $pkgver->pkg . '|')) { |
1727 | | | 1716 | my ($list); |
1728 | if ($pkgname =~ /^([^*?[]+)-([\d*?[].*)/) { | | 1717 | |
1729 | foreach my $pkgver ($pkglist->pkgver($1)) { | | 1718 | while (<PKGINFO>) { |
1730 | $pkgver->var('dir') =~ /-current/ && next; | | 1719 | if (/Required by:/) { |
1731 | push(@update, $pkgver); | | 1720 | $list = 1; |
1732 | last; | | 1721 | } elsif ($list) { |
1733 | } | | 1722 | chomp; |
| | | 1723 | s/-\d.*//; |
| | | 1724 | print " $_"; |
1734 | } | | 1725 | } |
1735 | } | | 1726 | } |
| | | 1727 | close(PKGINFO); |
1736 | } | | 1728 | } |
| | | 1729 | print "\n"; |
| | | 1730 | } |
1737 | | | 1731 | |
1738 | if ($opt{u}) { | | 1732 | print "\nRunning '$conf_make fetch-list | sh' for each package:\n"; |
1739 | print "\nREQUIRED details for packages that could be updated:\n"; | | 1733 | foreach my $pkgver (@update) { |
| | | 1734 | my $pkgpath = $pkgver->var('dir'); |
| | | 1735 | defined($pkgpath) |
| | | 1736 | or fail('Cannot determine ' . $pkgver->pkg . ' directory'); |
1740 | | | 1737 | |
1741 | foreach my $pkgver (@update) { | | 1738 | print "$pkgsrcdir/$pkgpath\n"; |
1742 | print $pkgver->pkg . ':'; | | 1739 | chdir_or_fail("$pkgsrcdir/$pkgpath"); |
1743 | if (open(PKGINFO, 'pkg_info -R ' . $pkgver->pkg . '|')) { | | 1740 | system("$conf_make fetch-list | sh"); |
1744 | my ($list); | | 1741 | } |
1745 | | | 1742 | } |
1746 | while (<PKGINFO>) { | | | |
1747 | if (/Required by:/) { | | | |
1748 | $list = 1; | | | |
1749 | } elsif ($list) { | | | |
1750 | chomp; | | | |
1751 | s/-\d.*//; | | | |
1752 | print " $_"; | | | |
1753 | } | | | |
1754 | } | | | |
1755 | close(PKGINFO); | | | |
1756 | } | | | |
1757 | print "\n"; | | | |
1758 | } | | | |
1759 | | | 1743 | |
1760 | print "\nRunning '$conf_make fetch-list | sh' for each package:\n"; | | 1744 | sub main() { |
1761 | foreach my $pkgver (@update) { | | | |
1762 | my ($pkgdir); | | | |
1763 | | | 1745 | |
1764 | $pkgdir = $pkgver->var('dir'); | | 1746 | $ENV{PATH} .= |
1765 | if (!defined($pkgdir)) { | | 1747 | ":/bin:/usr/bin:/sbin:/usr/sbin:$conf_prefix/sbin:$conf_prefix/bin"; |
1766 | fail('Unable to determine ' . $pkgver->pkg . ' directory'); | | | |
1767 | } | | | |
1768 | | | 1748 | |
1769 | print "$pkgsrcdir/$pkgdir\n"; | | 1749 | if ( |
1770 | chdir_or_fail("$pkgsrcdir/$pkgdir"); | | 1750 | !getopts('BDE:I:K:LM:OP:RSVdg:himopruyz', \%opt) |
1771 | system("$conf_make fetch-list | sh"); | | 1751 | || $opt{h} |
1772 | } | | 1752 | || !grep(/[BDEORSdgimopruyz]/, keys %opt)) { |
1773 | } | | 1753 | usage_and_exit(); |
| | | 1754 | } |
| | | 1755 | $| = 1; |
| | | 1756 | |
| | | 1757 | get_default_makefile_vars(); # $default_vars |
| | | 1758 | |
| | | 1759 | if ($opt{D} && @ARGV) { |
| | | 1760 | debug_parse_makefiles(@ARGV); |
| | | 1761 | exit; |
| | | 1762 | } |
| | | 1763 | |
| | | 1764 | my $pkgsrcdir = $default_vars->{PKGSRCDIR}; |
| | | 1765 | my $pkgdistdir = $default_vars->{DISTDIR}; |
| | | 1766 | |
| | | 1767 | if ($opt{r} && !$opt{o} && !$opt{m} && !$opt{p}) { |
| | | 1768 | $opt{o} = $opt{m} = $opt{p} = 1; |
| | | 1769 | } |
| | | 1770 | if ($opt{o} || $opt{m}) { |
| | | 1771 | check_distfiles($pkgsrcdir, $pkgdistdir); |
| | | 1772 | } |
| | | 1773 | |
| | | 1774 | # Remove all distfiles that are / are not part of an installed package |
| | | 1775 | if ($opt{y} || $opt{z}) { |
| | | 1776 | remove_distfiles($pkgsrcdir, $pkgdistdir); |
| | | 1777 | } |
| | | 1778 | |
| | | 1779 | if ($opt{B}) { |
| | | 1780 | list_broken_packages($pkgsrcdir); |
| | | 1781 | } |
| | | 1782 | |
| | | 1783 | if ($opt{p} || $opt{O} || $opt{R}) { |
| | | 1784 | list_prebuilt_packages($pkgsrcdir); |
| | | 1785 | } |
| | | 1786 | |
| | | 1787 | if ($opt{S}) { |
| | | 1788 | list_packages_not_in_SUBDIR($pkgsrcdir); |
| | | 1789 | } |
| | | 1790 | |
| | | 1791 | if ($opt{g}) { |
| | | 1792 | generate_map_file($pkgsrcdir, $opt{g}); |
| | | 1793 | } |
| | | 1794 | |
| | | 1795 | if ($opt{d}) { |
| | | 1796 | scan_pkgsrc_makefiles($pkgsrcdir); |
| | | 1797 | pkgsrc_check_depends(); |
| | | 1798 | } |
| | | 1799 | |
| | | 1800 | if ($opt{i} || $opt{u}) { |
| | | 1801 | check_outdated_installed_packages($pkgsrcdir); |
1774 | } | | 1802 | } |
1775 | | | 1803 | |
1776 | if ($opt{E}) { | | 1804 | if ($opt{E}) { |
1777 | scan_pkgsrc_makefiles($pkgsrcdir); | | 1805 | scan_pkgsrc_makefiles($pkgsrcdir); |
1778 | store_pkgsrc_makefiles($opt{E}); | | 1806 | store_pkgsrc_makefiles($opt{E}); |
1779 | } | | 1807 | } |
1780 | } | | 1808 | } |
1781 | | | 1809 | |
1782 | main() unless caller(); | | 1810 | main() unless caller(); |