diff --git a/gnu/packages.scm b/gnu/packages.scm index c9efd0d..25f1221 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -370,19 +370,24 @@ but ~a is available upstream~%") "Return a package matching SPEC. SPEC may be a package name, or a package name followed by a hyphen and a version number. If the version number is not present, return the preferred newest version." - (let-values (((name version) - (package-name->name+version spec))) + (define (lookup name version) (match (find-best-packages-by-name name version) - ((p) ; one match + ((p) ;one match p) - ((p x ...) ; several matches + ((p x ...) ;several matches (warning (_ "ambiguous package specification `~a'~%") spec) (warning (_ "choosing ~a from ~a~%") (package-full-name p) (location->string (package-location p))) p) - (_ ; no matches - (if version - (leave (_ "~A: package not found for version ~a~%") - name version) - (leave (_ "~A: unknown package~%") name)))))) + (_ ;no matches + #f))) + + (let-values (((name version) + (package-name->name+version spec))) + (or (lookup name version) + (if version + (or (lookup spec #f) + (leave (_ "~A: package not found for version ~a~%") + name version)) + (leave (_ "~A: unknown package~%") name))))) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 21dc66c..ae11ee2 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -296,8 +296,7 @@ version; if SPEC does not specify an output, return OUTPUT." (package-full-name p) sub-drv))) - (let-values (((name version sub-drv) - (package-specification->name+version+output spec output))) + (define (lookup name version sub-drv) (match (find-best-packages-by-name name version) ((p) (values p (ensure-output p sub-drv))) @@ -309,7 +308,26 @@ version; if SPEC does not specify an output, return OUTPUT." (location->string (package-location p))) (values p (ensure-output p sub-drv))) (() - (leave (_ "~a: package not found~%") spec))))) + (values #f #f)))) + + (define (fail) + (leave (_ "~a: package not found~%") spec)) + + (let-values (((name version sub-drv) + (package-specification->name+version+output spec output))) + (let-values (((package output) (lookup name version sub-drv))) + (cond + ((package? package) + (values package output)) + (version + (let-values (((package output) + (lookup (string-append name "-" version) #f + sub-drv))) + (if package + (values package output) + (fail)))) + (else + (fail)))))) (define (upgradeable? name current-version current-path) "Return #t if there's a version of package NAME newer than CURRENT-VERSION,