diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2022-03-14 18:20:31 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2022-04-04 22:58:03 +0200 |
| commit | f54f2aa9df5047b348ca104f5145af50c1a482f6 (patch) | |
| tree | 0cba8a8b405861fdabaefa4eba5276c47247599d /gnu/packages.scm | |
| parent | 4b451813f7c5677086772e29a66a8265ec0ca2c7 (diff) | |
packages: Add 'package-unique-version-prefix'.
* gnu/packages.scm (package-unique-version-prefix): New procedure.
* guix/scripts/package.scm (manifest-entry-version-prefix): Use it.
* tests/packages.scm ("package-unique-version-prefix, gcc@8")
("package-unique-version-prefix, grep"): New tests.
Diffstat (limited to 'gnu/packages.scm')
| -rw-r--r-- | gnu/packages.scm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gnu/packages.scm b/gnu/packages.scm index 65ab7a7c1e4..2ba838fd0af 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm | |||
| @@ -66,6 +66,8 @@ | |||
| 66 | specification->location | 66 | specification->location |
| 67 | specifications->manifest | 67 | specifications->manifest |
| 68 | 68 | ||
| 69 | package-unique-version-prefix | ||
| 70 | |||
| 69 | generate-package-cache)) | 71 | generate-package-cache)) |
| 70 | 72 | ||
| 71 | ;;; Commentary: | 73 | ;;; Commentary: |
| @@ -559,3 +561,22 @@ output." | |||
| 559 | ;; fiddle with multiple-value returns. | 561 | ;; fiddle with multiple-value returns. |
| 560 | (packages->manifest | 562 | (packages->manifest |
| 561 | (map (compose list specification->package+output) specs))) | 563 | (map (compose list specification->package+output) specs))) |
| 564 | |||
| 565 | (define (package-unique-version-prefix name version) | ||
| 566 | "Search among all the versions of package NAME that are available, and | ||
| 567 | return the shortest unambiguous version prefix to designate VERSION. If only | ||
| 568 | one version of the package is available, return the empty string." | ||
| 569 | (match (map package-version (find-packages-by-name name)) | ||
| 570 | ((_) | ||
| 571 | ;; A single version of NAME is available, so do not specify the version | ||
| 572 | ;; number, even if the available version doesn't match VERSION. | ||
| 573 | "") | ||
| 574 | (versions | ||
| 575 | ;; If VERSION is the latest version, don't specify any version. | ||
| 576 | ;; Otherwise return the shortest unique version prefix. Note that this | ||
| 577 | ;; is based on the currently available packages so the result may vary | ||
| 578 | ;; over time. | ||
| 579 | (if (every (cut version>? version <>) | ||
| 580 | (delete version versions)) | ||
| 581 | "" | ||
| 582 | (version-unique-prefix version versions))))) | ||
