aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-11-04 01:29:18 +0100
committerLudovic Courtès <ludo@gnu.org>2012-11-04 01:29:18 +0100
commit9b48fb88ca8177c987b0d3bf2e9ae46dac782430 (patch)
tree03cc3b7428339c1b9ba250dba3dd1aa6365f0d34 /guix
parentd388c2c435395aee61dc074023b1f218e6037545 (diff)
downloadguix-9b48fb88ca8177c987b0d3bf2e9ae46dac782430.tar
guix-9b48fb88ca8177c987b0d3bf2e9ae46dac782430.tar.gz
utils: Add `package-name->name+version'.
* guix/utils.scm (package-name->name+version): New procedure. * guix-package.in (guix-package)[find-package]: Use it. * tests/utils.scm ("package-name->name+version"): New test.
Diffstat (limited to 'guix')
-rw-r--r--guix/utils.scm24
1 files changed, 23 insertions, 1 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 345ed374cd..7ebc026702 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -58,7 +58,8 @@
source-properties->location
gnu-triplet->nix-system
- %current-system))
+ %current-system
+ package-name->name+version))
;;;
@@ -571,6 +572,27 @@ returned by `config.guess'."
;; System type as expected by Nix, usually ARCHITECTURE-KERNEL.
(make-parameter (gnu-triplet->nix-system %host-type)))
+(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
+#f are returned. The first hyphen followed by a digit is considered to
+introduce the version part."
+ ;; See also `DrvName' in Nix.
+
+ (define number?
+ (cut char-set-contains? char-set:digit <>))
+
+ (let loop ((chars (string->list name))
+ (prefix '()))
+ (match chars
+ (()
+ (values name #f))
+ ((#\- (? number? n) rest ...)
+ (values (list->string (reverse prefix))
+ (list->string (cons n rest))))
+ ((head tail ...)
+ (loop tail (cons head prefix))))))
+
;;;
;;; Source location.