From 19d37ea3843d236a3e32127a724a712dba3c58db Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Mon, 7 Dec 2015 05:20:08 +0100 Subject: [PATCH] utils: Improve 'package-name->name+version' version detection. Fixes . * guix/build/utils.scm (package-name->name+version): Use a more generic heuristic to detect version. Usage of digits in names is now possible. * tests/utils.scm ("package-name->name+version"): Add some cases. --- guix/build/utils.scm | 29 +++++++++++++++-------------- tests/utils.scm | 6 +++++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/guix/build/utils.scm b/guix/build/utils.scm index e3f9edc..0ace2c7 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -100,25 +100,26 @@ is typically a \"PACKAGE-VERSION\" string." (+ 34 (string-length (%store-directory))))) (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." + "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 version part must contain a dot to be properly detected." ;; 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)))))) + (let ((lst (reverse (string->list name)))) + (let loop ((chars lst) (suffix '()) (retry #t) (dots #f)) + (match chars + (() + (values name #f)) + ((#\- rest ...) + (cond (dots (values (list->string (reverse rest)) + (list->string suffix))) + (retry (loop rest (cons #\- suffix) #f #f)) + (else (values name #f)))) + ((head tail ...) + (loop tail (cons head suffix) retry (or dots (char=? #\. head)))))))) (define parallel-job-count ;; Number of processes to be passed next to GNU Make's `-j' argument. diff --git a/tests/utils.scm b/tests/utils.scm index 04a859f..a7d8900 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -68,7 +68,11 @@ '(("foo" "0.9.1b") ("foo-bar" "1.0") ("foo-bar2" #f) - ("guile" "2.0.6.65-134c9") ; as produced by `git-version-gen' + ("emacs" "24.5") + ("font-adobe-100-dpi" #f) + ("rxvt-unicode-256-color" "9.21") + ("guile" "2.0.6.65-134c9") ;as produced by Gnulib 'git-version-gen' + ("guile" "2.1.1.75-a147") ;and with a different hash ("nixpkgs" "1.0pre22125_a28fe19") ("gtk2" "2.38.0")))) -- 2.6.3