| @@ -1,16 +1,16 @@ | | | @@ -1,16 +1,16 @@ |
1 | #!@PERL5@ | | 1 | #!@PERL5@ |
2 | | | 2 | |
3 | # $NetBSD: lintpkgsrc.pl,v 1.28 2022/07/30 08:18:31 rillig Exp $ | | 3 | # $NetBSD: lintpkgsrc.pl,v 1.29 2022/07/30 08:21:31 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; |
| @@ -291,27 +291,27 @@ sub listdir($$) { | | | @@ -291,27 +291,27 @@ sub listdir($$) { |
291 | } | | 291 | } |
292 | @list; | | 292 | @list; |
293 | } | | 293 | } |
294 | | | 294 | |
295 | sub canonicalize_pkgname($) { | | 295 | sub canonicalize_pkgname($) { |
296 | my ($pkgname) = @_; | | 296 | my ($pkgname) = @_; |
297 | | | 297 | |
298 | $pkgname =~ s,^py\d+(?:pth|)-,py-,; | | 298 | $pkgname =~ s,^py\d+(?:pth|)-,py-,; |
299 | $pkgname =~ s,^ruby\d+-,ruby-,; | | 299 | $pkgname =~ s,^ruby\d+-,ruby-,; |
300 | $pkgname =~ s,^php\d+-,php-,; | | 300 | $pkgname =~ s,^php\d+-,php-,; |
301 | return $pkgname; | | 301 | return $pkgname; |
302 | } | | 302 | } |
303 | | | 303 | |
304 | sub convert_to_standard_dewey(@) { | | 304 | sub convert_to_standard_pkgversion(@) { |
305 | my ($elem, $underscore, @temp); | | 305 | my ($elem, $underscore, @temp); |
306 | | | 306 | |
307 | # According to the current implementation in pkg_install/lib/str.c | | 307 | # According to the current implementation in pkg_install/lib/str.c |
308 | # as of 2002/06/02, '_' before a number, '.', and 'pl' get treated as 0, | | 308 | # as of 2002/06/02, '_' before a number, '.', and 'pl' get treated as 0, |
309 | # while 'rc' and 'pre' get treated as -1; beta as '-2', alpha as '-3'. | | 309 | # while 'rc' and 'pre' get treated as -1; beta as '-2', alpha as '-3'. |
310 | # Other characters are converted to lower | | 310 | # Other characters are converted to lower |
311 | # case and then to a number: a->1, b->2, c->3, etc. Numbers stay the same. | | 311 | # case and then to a number: a->1, b->2, c->3, etc. Numbers stay the same. |
312 | # 'nb' is a special case that's already been handled when we are here. | | 312 | # 'nb' is a special case that's already been handled when we are here. |
313 | foreach $elem (@_) { | | 313 | foreach $elem (@_) { |
314 | if ($elem =~ /\d+/) { | | 314 | if ($elem =~ /\d+/) { |
315 | push(@temp, $elem); | | 315 | push(@temp, $elem); |
316 | } elsif ($elem =~ /^pl$/ or $elem =~ /^\.$/) { | | 316 | } elsif ($elem =~ /^pl$/ or $elem =~ /^\.$/) { |
317 | push(@temp, 0); | | 317 | push(@temp, 0); |
| @@ -323,79 +323,79 @@ sub convert_to_standard_dewey(@) { | | | @@ -323,79 +323,79 @@ sub convert_to_standard_dewey(@) { |
323 | push(@temp, -1); | | 323 | push(@temp, -1); |
324 | } elsif ($elem =~ /^beta$/) { | | 324 | } elsif ($elem =~ /^beta$/) { |
325 | push(@temp, -2); | | 325 | push(@temp, -2); |
326 | } elsif ($elem =~ /^alpha$/) { | | 326 | } elsif ($elem =~ /^alpha$/) { |
327 | push(@temp, -3); | | 327 | push(@temp, -3); |
328 | } else { | | 328 | } else { |
329 | push(@temp, 0); | | 329 | push(@temp, 0); |
330 | push(@temp, ord($elem) - ord("a") + 1); | | 330 | push(@temp, ord($elem) - ord("a") + 1); |
331 | } | | 331 | } |
332 | } | | 332 | } |
333 | @temp; | | 333 | @temp; |
334 | } | | 334 | } |
335 | | | 335 | |
336 | sub deweycmp_extract($$) { | | 336 | sub pkgversioncmp_extract($$) { |
337 | my ($match, $val) = @_; | | 337 | my ($match, $val) = @_; |
338 | my ($cmp, @matchlist, @vallist, $i, $len); | | 338 | my ($cmp, @matchlist, @vallist, $i, $len); |
339 | | | 339 | |
340 | @matchlist = convert_to_standard_dewey(split(/(\D+)/, lc($match))); | | 340 | @matchlist = convert_to_standard_pkgversion(split(/(\D+)/, lc($match))); |
341 | @vallist = convert_to_standard_dewey(split(/(\D+)/, lc($val))); | | 341 | @vallist = convert_to_standard_pkgversion(split(/(\D+)/, lc($val))); |
342 | $cmp = 0; | | 342 | $cmp = 0; |
343 | $i = 0; | | 343 | $i = 0; |
344 | if ($#matchlist > $#vallist) { | | 344 | if ($#matchlist > $#vallist) { |
345 | $len = $#matchlist; | | 345 | $len = $#matchlist; |
346 | } else { | | 346 | } else { |
347 | $len = $#vallist; | | 347 | $len = $#vallist; |
348 | } | | 348 | } |
349 | while (!$cmp && ($i++ <= $len)) { | | 349 | while (!$cmp && ($i++ <= $len)) { |
350 | if (!@matchlist) { | | 350 | if (!@matchlist) { |
351 | push(@matchlist, 0); | | 351 | push(@matchlist, 0); |
352 | } | | 352 | } |
353 | if (!@vallist) { | | 353 | if (!@vallist) { |
354 | push(@vallist, 0); | | 354 | push(@vallist, 0); |
355 | } | | 355 | } |
356 | $cmp = (shift @matchlist <=> shift @vallist); | | 356 | $cmp = (shift @matchlist <=> shift @vallist); |
357 | } | | 357 | } |
358 | $cmp; | | 358 | $cmp; |
359 | } | | 359 | } |
360 | | | 360 | |
361 | # Dewey decimal version number matching - or thereabouts | | 361 | # Package version number matching - or thereabouts |
362 | # Also handles 'nb<N>' suffix (checked iff values otherwise identical) | | 362 | # Also handles 'nb<N>' suffix (checked iff values otherwise identical) |
363 | # | | 363 | # |
364 | sub deweycmp($$$) { | | 364 | sub pkgversioncmp($$$) { |
365 | my ($match, $test, $val) = @_; | | 365 | my ($match, $test, $val) = @_; |
366 | my ($cmp, $match_nb, $val_nb); | | 366 | my ($cmp, $match_nb, $val_nb); |
367 | | | 367 | |
368 | $match_nb = $val_nb = 0; | | 368 | $match_nb = $val_nb = 0; |
369 | if ($match =~ /(.*)nb(.*)/) { | | 369 | if ($match =~ /(.*)nb(.*)/) { |
370 | # Handle nb<N> suffix | | 370 | # Handle nb<N> suffix |
371 | $match = $1; | | 371 | $match = $1; |
372 | $match_nb = $2; | | 372 | $match_nb = $2; |
373 | } | | 373 | } |
374 | | | 374 | |
375 | if ($val =~ /(.*)nb(.*)/) { | | 375 | if ($val =~ /(.*)nb(.*)/) { |
376 | # Handle nb<N> suffix | | 376 | # Handle nb<N> suffix |
377 | $val = $1; | | 377 | $val = $1; |
378 | $val_nb = $2; | | 378 | $val_nb = $2; |
379 | } | | 379 | } |
380 | | | 380 | |
381 | $cmp = deweycmp_extract($match, $val); | | 381 | $cmp = pkgversioncmp_extract($match, $val); |
382 | | | 382 | |
383 | if (!$cmp) { | | 383 | if (!$cmp) { |
384 | # Iff otherwise identical, check nb suffix | | 384 | # Iff otherwise identical, check nb suffix |
385 | $cmp = deweycmp_extract($match_nb, $val_nb); | | 385 | $cmp = pkgversioncmp_extract($match_nb, $val_nb); |
386 | } | | 386 | } |
387 | | | 387 | |
388 | debug("eval deweycmp $cmp $test 0\n"); | | 388 | debug("eval pkgversioncmp $cmp $test 0\n"); |
389 | eval "$cmp $test 0"; | | 389 | eval "$cmp $test 0"; |
390 | } | | 390 | } |
391 | | | 391 | |
392 | sub parse_expand_vars_dumb($$) { | | 392 | sub parse_expand_vars_dumb($$) { |
393 | my ($line, $vars) = @_; | | 393 | my ($line, $vars) = @_; |
394 | | | 394 | |
395 | while ($line =~ /\$\{([-\w.]+)\}/) { | | 395 | while ($line =~ /\$\{([-\w.]+)\}/) { |
396 | if (defined(${$vars}{$1})) { | | 396 | if (defined(${$vars}{$1})) { |
397 | $line = $` . ${$vars}{$1} . $'; | | 397 | $line = $` . ${$vars}{$1} . $'; |
398 | } else { | | 398 | } else { |
399 | $line = $` . $magic_undefined . $'; | | 399 | $line = $` . $magic_undefined . $'; |
400 | } | | 400 | } |
401 | } | | 401 | } |
| @@ -999,39 +999,39 @@ sub glob2regex($) { | | | @@ -999,39 +999,39 @@ sub glob2regex($) { |
999 | '^' . $regex . '$'; | | 999 | '^' . $regex . '$'; |
1000 | } | | 1000 | } |
1001 | | | 1001 | |
1002 | # Perform some (reasonable) subset of 'pkg_info -e' / glob(3) | | 1002 | # Perform some (reasonable) subset of 'pkg_info -e' / glob(3) |
1003 | # Returns (sometimes best guess at) package name, | | 1003 | # Returns (sometimes best guess at) package name, |
1004 | # and either 'problem version' or undef if all OK | | 1004 | # and either 'problem version' or undef if all OK |
1005 | # | | 1005 | # |
1006 | sub package_globmatch($) { | | 1006 | sub package_globmatch($) { |
1007 | my ($pkgmatch) = @_; | | 1007 | my ($pkgmatch) = @_; |
1008 | my ($matchpkgname, $matchver, $regex); | | 1008 | my ($matchpkgname, $matchver, $regex); |
1009 | | | 1009 | |
1010 | if ($pkgmatch =~ /^([^*?[]+)(<|>|<=|>=|-)(\d[^*?[{]*)$/) { | | 1010 | if ($pkgmatch =~ /^([^*?[]+)(<|>|<=|>=|-)(\d[^*?[{]*)$/) { |
1011 | | | 1011 | |
1012 | # (package)(cmp)(dewey) | | 1012 | # (package)(cmp)(pkgversion) |
1013 | my ($test, @pkgvers); | | 1013 | my ($test, @pkgvers); |
1014 | | | 1014 | |
1015 | ($matchpkgname, $test, $matchver) = ($1, $2, $3); | | 1015 | ($matchpkgname, $test, $matchver) = ($1, $2, $3); |
1016 | if (@pkgvers = $pkglist->pkgver($matchpkgname)) { | | 1016 | if (@pkgvers = $pkglist->pkgver($matchpkgname)) { |
1017 | foreach my $pkgver (@pkgvers) { | | 1017 | foreach my $pkgver (@pkgvers) { |
1018 | if ($test eq '-') { | | 1018 | if ($test eq '-') { |
1019 | if ($pkgver->ver eq $matchver) { | | 1019 | if ($pkgver->ver eq $matchver) { |
1020 | $matchver = undef; | | 1020 | $matchver = undef; |
1021 | last; | | 1021 | last; |
1022 | } | | 1022 | } |
1023 | } else { | | 1023 | } else { |
1024 | if (deweycmp($pkgver->ver, $test, $matchver)) { | | 1024 | if (pkgversioncmp($pkgver->ver, $test, $matchver)) { |
1025 | $matchver = undef; | | 1025 | $matchver = undef; |
1026 | last; | | 1026 | last; |
1027 | } | | 1027 | } |
1028 | } | | 1028 | } |
1029 | } | | 1029 | } |
1030 | | | 1030 | |
1031 | if ($matchver && $test ne '-') { | | 1031 | if ($matchver && $test ne '-') { |
1032 | $matchver = "$test$matchver"; | | 1032 | $matchver = "$test$matchver"; |
1033 | } | | 1033 | } |
1034 | } | | 1034 | } |
1035 | | | 1035 | |
1036 | } elsif ($pkgmatch =~ /^([^[]+)-([\d*?{[].*)$/) { | | 1036 | } elsif ($pkgmatch =~ /^([^[]+)-([\d*?{[].*)$/) { |
1037 | | | 1037 | |