summaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2013-02-12 12:02:15 -0500
committerMark H Weaver <mhw@netris.org>2013-02-12 20:34:25 -0500
commit0d1e6ce4d2e384b73fc393ca13602ac6db41c1be (patch)
tree65726a222f350f6e1905687580d3e75a3f386aa0 /guix/utils.scm
parent96be765ca5f89640b5d13e61ca04de7254040f3c (diff)
downloadgnu-guix-0d1e6ce4d2e384b73fc393ca13602ac6db41c1be.tar
gnu-guix-0d1e6ce4d2e384b73fc393ca13602ac6db41c1be.tar.gz
Add version-compare and version>? to utils.scm.
* guix/utils.scm (version-compare, version>?): New exported procedures, based on version-string>?, which was formerly in gnu-maintenance.scm. * guix/gnu-maintenance.scm (version-string>?): Removed procedure. (latest-release): Use 'version>?' instead of 'version-string>?'.
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm20
1 files changed, 20 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 7ab835e7f1..d7c37e37d1 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -57,6 +57,8 @@
gnu-triplet->nix-system
%current-system
+ version-compare
+ version>?
package-name->name+version))
@@ -422,6 +424,24 @@ returned by `config.guess'."
;; By default, this is equal to (gnu-triplet->nix-system %host-type).
(make-parameter %system))
+(define version-compare
+ (let ((strverscmp
+ (let ((sym (or (dynamic-func "strverscmp" (dynamic-link))
+ (error "could not find `strverscmp' (from GNU libc)"))))
+ (pointer->procedure int sym (list '* '*)))))
+ (lambda (a b)
+ "Return '> when A denotes a newer version than B,
+'< when A denotes a older version than B,
+or '= when they denote equal versions."
+ (let ((result (strverscmp (string->pointer a) (string->pointer b))))
+ (cond ((positive? result) '>)
+ ((negative? result) '<)
+ (else '=))))))
+
+(define (version>? a b)
+ "Return #t when A denotes a newer version than B."
+ (eq? '> (version-compare a b)))
+
(define (package-name->name+version name)
"Given NAME, a package name like \"foo-0.9.1b\", return two values:
\"foo\" and \"0.9.1b\". When the version part is unavailable, NAME and