How to detect the version of a installed perl module during portbuild

Matthew Seaman m.seaman at infracaninophile.co.uk
Wed Jan 4 08:59:31 UTC 2012


On 03/01/2012 23:41, Paul Schmehl wrote:
> This returns the installed package:
> 
> pkg_info -qa | grep "p5-JSON-RPC" | sort | uniq

Woah!  Try it like this:

pkg_info -Ex p5-JSON-RPC

> so maybe you could do something like?
> 
> JSON_VER=`pkg_info -qa | grep "p5-JSON-RPC" | sort | uniq | cut -d'-' -f4`

JSON_VER=$( pkg_info -Ex p5-JSON-RPC | sed -e 's/^.*-//' )

> .if ${JSON_VER} >= 1
>  do this
> .else
>  do this
> .endif

case ${JSON_VER) in
	1.*)
	    do_stuff
	    ;;
	0.*)
	    do_something_else
	    ;;
esac

case does a string comparison using standard shell globbing rules --
it's a lot more flexible than trying to do maths on version numbers.

Using perl to generate the version number is also viable as suggested by
Jason:

perl -MJSON::RPC -le 'print $JSON::RPC::VERSION'

but it strikes me as slightly wasteful to fire up an entire perl
interpreter just to print out the value of one variable.

However, if the object is to create a port that has a BUILD_DEPENDS on
devel/p5-JSON-RPC then you only need to support what is already in the
ports -- and that's version 1.01.  The BUILD_DEPENDS line can enforce that:

BUILD_DEPENDS = p5-JSON-RPC>=1.01:${PORTSDIR}/devel/p5-JSON-RPC

Should you have some program that requires JSON::RPC <= 0.96, then
create a p5-JSON-RPC-096 port to provide exactly that.

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
JID: matthew at infracaninophile.co.uk               Kent, CT11 9PW

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 267 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20120104/532cb1fb/signature.pgp


More information about the freebsd-ports mailing list