pkg_version.pl now understands the new package/port numbering scheme

introduced by version 1.349 of ports/Mk/bsd.port.mk and originally
submitted by kris.

In particular, it understands the $PORTREVISION (FreeBSD-specific changes
or patches to a port) and $PORTEPOCH (for re-sorting version numbers
when not used or when broken).
This commit is contained in:
Bruce A. Mah 2000-09-09 21:28:06 +00:00
parent 58359dc594
commit 186cbe8e5d

View File

@ -50,13 +50,13 @@ $CommentChar = "#";
$LimitFlag = "";
#
# CompareVersions
# CompareNumbers
#
# Try to figure out the relationship between two program version numbers.
# Detecting equality is easy, but determining order is a little difficult.
# This function returns -1, 0, or 1, in the same manner as <=> or cmp.
#
sub CompareVersions {
sub CompareNumbers {
local($v1, $v2);
$v1 = $_[0];
$v2 = $_[1];
@ -91,24 +91,95 @@ sub CompareVersions {
}
#
# CompareVersions
#
# Try to figure out the relationship between two program "full
# versions", which is defined as the
# ${PORTVERSION}[_${PORTREVISION}][,${PORTEPOCH}]
# part of a package's name.
#
# Key points: ${PORTEPOCH} supercedes ${PORTVERSION}
# supercedes ${PORTREVISION}. See the commit log for revision
# 1.349 of ports/Mk/bsd.port.mk for more information.
#
sub CompareVersions {
local($fv1, $fv2, $v1, $v2, $v1, $r2, $e1, $e2, $rc);
$fv1 = $_[0];
$fv2 = $_[1];
# Shortcut check for equality before invoking the parsing
# routines.
if ($fv1 eq $fv2) {
return 0;
}
else {
($v1, $r1, $e1) = &GetVersionComponents($fv1);
($v2, $r2, $e2) = &GetVersionComponents($fv2);
# Check epoch, port version, and port revision, in that
# order.
$rc = &CompareNumbers($e1, $e2);
if ($rc == 0) {
$rc = &CompareNumbers($v1, $v2);
if ($rc == 0) {
$rc = &CompareNumbers($r1, $r2);
}
}
return $rc;
}
}
#
# GetVersionComponents
#
# Parse out the version number, revision number, and epoch number
# of a port's version string and return them as a three-element array.
#
# Syntax is: ${PORTVERSION}[_${PORTREVISION}][,${PORTEPOCH}]
#
sub GetVersionComponents {
local ($fullversion, $version, $revision, $epoch);
$fullversion = $_[0];
$fullversion =~ /([^_,]+)/;
$version = $1;
if ($fullversion =~ /_([^_,]+)/) {
$revision = $1;
}
if ($fullversion =~ /,([^_,]+)/) {
$epoch = $1;
}
return($version, $revision, $epoch);
}
#
# GetNameAndVersion
#
# Get the name and version number of a package. Returns a two element
# array, first element is name, second element is version number.
# array, first element is name, second element is full version string.,
#
sub GetNameAndVersion {
local($string);
$string = $_[0];
local($fullname, $name, $fullversion);
$fullname = $_[0];
# If no hyphens then no version number
return ($string, "") if $string !~ /-/;
# If no hyphens then no version numbers
return ($fullname, "", "", "", "") if $fullname !~ /-/;
# Match (and group) everything in between two hyphens. Because the
# Match (and group) everything after hyphen(s). Because the
# regexp is 'greedy', the first .* will try and match everything up
# to (but not including) the last hyphen
$string =~ /(.*)-(.*)/;
return ($1, $2);
$fullname =~ /(.+)-(.+)/;
$name = $1;
$fullversion = $2;
return ($name, $fullversion);
}
#
@ -179,13 +250,14 @@ if ($DebugFlag) {
open CURRENT, "$CurrentPackagesCommand|";
while (<CURRENT>) {
($packageString, $rest) = split;
($packageName, $packageVersion) = &GetNameAndVersion($packageString);
($packageName, $packageFullversion) = &GetNameAndVersion($packageString);
$currentPackages{$packageName}{'name'} = $packageName;
if (defined $currentPackages{$packageName}{'version'}) {
$currentPackages{$packageName}{'version'} .= "," . $packageVersion;
if (defined $currentPackages{$packageName}{'fullversion'}) {
$currentPackages{$packageName}{'fullversion'} .= "|" . $packageFullversion;
}
else {
$currentPackages{$packageName}{'version'} = $packageVersion;
$currentPackages{$packageName}{'fullversion'} = $packageFullversion;
}
$currentPackages{$packageName}{'refcount'}++;
}
@ -198,14 +270,15 @@ if ($DebugFlag) {
open INDEX, "$IndexPackagesCommand|";
while (<INDEX>) {
($packageString, $packagePath, $rest) = split(/\|/);
($packageName, $packageVersion) = &GetNameAndVersion($packageString);
($packageName, $packageFullversion) = &GetNameAndVersion($packageString);
$indexPackages{$packageName}{'name'} = $packageName;
$indexPackages{$packageName}{'path'} = $packagePath;
if (defined $indexPackages{$packageName}{'version'}) {
$indexPackages{$packageName}{'version'} .= "," . $packageVersion;
if (defined $indexPackages{$packageName}{'fullversion'}) {
$indexPackages{$packageName}{'fullversion'} .= "|" . $packageFullversion;
}
else {
$indexPackages{$packageName}{'version'} = $packageVersion;
$indexPackages{$packageName}{'fullversion'} = $packageFullversion;
}
$indexPackages{$packageName}{'refcount'}++;
}
@ -214,16 +287,24 @@ close INDEX;
#
# Produce reports
#
# Prior versions of pkg_version used commas (",") as delimiters
# when there were multiple versions of a package installed.
# The new package version number syntax uses commas as well,
# so we've used vertical bars ("|") internally, and convert them
# to commas before we output anything so the reports look the
# same as they did before.
#
foreach $packageName (sort keys %currentPackages) {
$~ = "STDOUT_VERBOSE" if $VerboseFlag;
$~ = "STDOUT_COMMANDS" if $ShowCommandsFlag;
$packageNameVer = "$packageName-$currentPackages{$packageName}{'version'}";
$packageNameVer = "$packageName-$currentPackages{$packageName}{'fullversion'}";
$packageNameVer =~ s/\|/,/g;
if (defined $indexPackages{$packageName}{'version'}) {
if (defined $indexPackages{$packageName}{'fullversion'}) {
$indexVersion = $indexPackages{$packageName}{'version'};
$currentVersion = $currentPackages{$packageName}{'version'};
$indexVersion = $indexPackages{$packageName}{'fullversion'};
$currentVersion = $currentPackages{$packageName}{'fullversion'};
$indexRefcount = $indexPackages{$packageName}{'refcount'};
$currentRefcount = $currentPackages{$packageName}{'refcount'};
@ -233,10 +314,14 @@ foreach $packageName (sort keys %currentPackages) {
if (($indexRefcount > 1) || ($currentRefcount > 1)) {
$versionCode = "?";
$Comment = "multiple versions (index has $indexVersion)";
$Comment =~ s/\|/,/g;
}
else {
$rc = &CompareVersions($currentVersion, $indexVersion);
# Do the comparison
$rc =
&CompareVersions($currentPackages{$packageName}{'fullversion'},
$indexPackages{$packageName}{'fullversion'});
if ($rc == 0) {
next if $ShowCommandsFlag;
@ -288,7 +373,7 @@ $packageName, $versionCode
# Verbose report (-v flag)
format STDOUT_VERBOSE =
@<<<<<<<<<<<<<<<<<<<<<<<<< @< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@<<<<<<<<<<<<<<<<<<<<<<<<< @< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$packageNameVer, $versionCode, $Comment
.
;