From eea6284c3e1d83a95f14fc093752c04042719c7d Mon Sep 17 00:00:00 2001 From: Kurt Hindenburg Date: Thu, 25 Feb 2021 23:32:01 -0500 Subject: [PATCH] Add vercmp as a port action that compares two versions Expose pextlib's vercmp as a port action to allow users to determine how macports calculates versions. closes: https://trac.macports.org/ticket/61050 --- src/port/port.tcl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/port/port.tcl b/src/port/port.tcl index 97ea67b967..5c7f330d5d 100755 --- a/src/port/port.tcl +++ b/src/port/port.tcl @@ -4230,6 +4230,26 @@ proc action_mirror { action portlist opts } { action_target $action $portlist $opts } +proc action_vercmp { action portlist opts } { + if {[llength $portlist] != 2} { + ui_error "Usage: port vercmp versionA versionB" + return 1 + } + set versionA [lindex $portlist 0] + set versionB [lindex $portlist 1] + set result [vercmp $versionA $versionB] + ui_msg -nonewline "MacPorts considers $versionA to be " + if {$result < 0} { + ui_msg -nonewline "less than" + } elseif {$result == 0} { + ui_msg -nonewline "equal to" + } else { + ui_msg -nonewline "greater than" + } + ui_msg " $versionB" + return 0 +} + proc action_exit { action portlist opts } { # Return a semaphore telling the main loop to quit return -999 @@ -4368,6 +4388,8 @@ array set action_array [list \ mpkg [list action_target [ACTION_ARGS_PORTS]] \ pkg [list action_target [ACTION_ARGS_PORTS]] \ \ + vercmp [list action_vercmp [ACTION_ARGS_STRINGS]] \ + \ quit [list action_exit [ACTION_ARGS_NONE]] \ exit [list action_exit [ACTION_ARGS_NONE]] \ ]