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 | |
| 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.
| -rw-r--r-- | gnu/packages.scm | 21 | ||||
| -rw-r--r-- | guix/scripts/package.scm | 20 | ||||
| -rw-r--r-- | tests/packages.scm | 13 |
3 files changed, 36 insertions, 18 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))))) | ||
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 9699c70c6db..22ee8a2485e 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm | |||
| @@ -334,24 +334,8 @@ Alternately, see @command{guix package --search-paths -p ~s}.") | |||
| 334 | "Search among all the versions of ENTRY's package that are available, and | 334 | "Search among all the versions of ENTRY's package that are available, and |
| 335 | return the shortest unambiguous version prefix for this package. If only one | 335 | return the shortest unambiguous version prefix for this package. If only one |
| 336 | version of ENTRY's package is available, return the empty string." | 336 | version of ENTRY's package is available, return the empty string." |
| 337 | (let ((name (manifest-entry-name entry))) | 337 | (package-unique-version-prefix (manifest-entry-name entry) |
| 338 | (match (map package-version (find-packages-by-name name)) | 338 | (manifest-entry-version entry))) |
| 339 | ((_) | ||
| 340 | ;; A single version of NAME is available, so do not specify the | ||
| 341 | ;; version number, even if the available version doesn't match ENTRY. | ||
| 342 | "") | ||
| 343 | (versions | ||
| 344 | ;; If ENTRY uses the latest version, don't specify any version. | ||
| 345 | ;; Otherwise return the shortest unique version prefix. Note that | ||
| 346 | ;; this is based on the currently available packages, which could | ||
| 347 | ;; differ from the packages available in the revision that was used | ||
| 348 | ;; to build MANIFEST. | ||
| 349 | (let ((current (manifest-entry-version entry))) | ||
| 350 | (if (every (cut version>? current <>) | ||
| 351 | (delete current versions)) | ||
| 352 | "" | ||
| 353 | (version-unique-prefix (manifest-entry-version entry) | ||
| 354 | versions))))))) | ||
| 355 | 339 | ||
| 356 | (define* (export-manifest manifest | 340 | (define* (export-manifest manifest |
| 357 | #:optional (port (current-output-port))) | 341 | #:optional (port (current-output-port))) |
diff --git a/tests/packages.scm b/tests/packages.scm index 710eace6dc6..6cbc34ba0b6 100644 --- a/tests/packages.scm +++ b/tests/packages.scm | |||
| @@ -1923,6 +1923,19 @@ | |||
| 1923 | (package-location (specification->package "guile@2")) | 1923 | (package-location (specification->package "guile@2")) |
| 1924 | (specification->location "guile@2")) | 1924 | (specification->location "guile@2")) |
| 1925 | 1925 | ||
| 1926 | (test-equal "package-unique-version-prefix, gcc@8" | ||
| 1927 | "8" | ||
| 1928 | (let ((gcc (specification->package "gcc-toolchain@8"))) | ||
| 1929 | (package-unique-version-prefix (package-name gcc) | ||
| 1930 | (package-version gcc)))) | ||
| 1931 | |||
| 1932 | (test-equal "package-unique-version-prefix, grep" | ||
| 1933 | "" | ||
| 1934 | (let ((grep (specification->package "grep"))) | ||
| 1935 | (package-unique-version-prefix (package-name grep) | ||
| 1936 | (package-version grep)))) | ||
| 1937 | |||
| 1938 | |||
| 1926 | (test-eq "this-package-input, exists" | 1939 | (test-eq "this-package-input, exists" |
| 1927 | hello | 1940 | hello |
| 1928 | (package-arguments | 1941 | (package-arguments |
