diff options
| author | Ludovic Courtès <ludovic.courtes@inria.fr> | 2021-08-11 15:54:59 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2021-08-11 16:35:28 +0200 |
| commit | 373e7ac4f9d510d3a58fcdbe9ec2d67eb426336b (patch) | |
| tree | 5f8b69cfa8b7a458fd7f13f50a771e1ec306f855 | |
| parent | 168d107abf5608e6a1bfb37ee3448c4087856602 (diff) | |
transformations: 'with-patch' works on non-origin sources.
Fixes <https://issues.guix.gnu.org/49697>.
Reported by Philippe Swartvagher <philippe.swartvagher@inria.fr>.
* guix/transformations.scm (patched-source): New procedure.
(transform-package-patches)[package-with-extra-patches]: Use it
when (package-source p) is not an origin.
* tests/transformations.scm ("options->transformation, with-commit +
with-patch"): New test.
| -rw-r--r-- | guix/transformations.scm | 45 | ||||
| -rw-r--r-- | tests/transformations.scm | 30 |
2 files changed, 65 insertions, 10 deletions
diff --git a/guix/transformations.scm b/guix/transformations.scm index b0c09a0c926..5122baa403c 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm | |||
| @@ -460,19 +460,46 @@ to the same package but with #:strip-binaries? #f in its 'arguments' field." | |||
| 460 | (rewrite obj) | 460 | (rewrite obj) |
| 461 | obj))) | 461 | obj))) |
| 462 | 462 | ||
| 463 | (define (patched-source name source patches) | ||
| 464 | "Return a file-like object with the given NAME that applies PATCHES to | ||
| 465 | SOURCE. SOURCE must itself be a file-like object of any type, including | ||
| 466 | <git-checkout>, <local-file>, etc." | ||
| 467 | (define patch | ||
| 468 | (module-ref (resolve-interface '(gnu packages base)) 'patch)) | ||
| 469 | |||
| 470 | (computed-file name | ||
| 471 | (with-imported-modules '((guix build utils)) | ||
| 472 | #~(begin | ||
| 473 | (use-modules (guix build utils)) | ||
| 474 | |||
| 475 | (setenv "PATH" #+(file-append patch "/bin")) | ||
| 476 | |||
| 477 | ;; XXX: Assume SOURCE is a directory. This is true in | ||
| 478 | ;; most practical cases, where it's a <git-checkout>. | ||
| 479 | (copy-recursively #+source #$output) | ||
| 480 | (chdir #$output) | ||
| 481 | (for-each (lambda (patch) | ||
| 482 | (invoke "patch" "-p1" "--batch" | ||
| 483 | "-i" patch)) | ||
| 484 | '(#+@patches)))))) | ||
| 485 | |||
| 463 | (define (transform-package-patches specs) | 486 | (define (transform-package-patches specs) |
| 464 | "Return a procedure that, when passed a package, returns a package with | 487 | "Return a procedure that, when passed a package, returns a package with |
| 465 | additional patches." | 488 | additional patches." |
| 466 | (define (package-with-extra-patches p patches) | 489 | (define (package-with-extra-patches p patches) |
| 467 | (if (origin? (package-source p)) | 490 | (let ((patches (map (lambda (file) |
| 468 | (package/inherit p | 491 | (local-file file)) |
| 469 | (source (origin | 492 | patches))) |
| 470 | (inherit (package-source p)) | 493 | (if (origin? (package-source p)) |
| 471 | (patches (append (map (lambda (file) | 494 | (package/inherit p |
| 472 | (local-file file)) | 495 | (source (origin |
| 473 | patches) | 496 | (inherit (package-source p)) |
| 474 | (origin-patches (package-source p))))))) | 497 | (patches (append patches |
| 475 | p)) | 498 | (origin-patches (package-source p))))))) |
| 499 | (package/inherit p | ||
| 500 | (source (patched-source (string-append (package-full-name p "-") | ||
| 501 | "-source") | ||
| 502 | (package-source p) patches)))))) | ||
| 476 | 503 | ||
| 477 | (define (coalesce-alist alist) | 504 | (define (coalesce-alist alist) |
| 478 | ;; Coalesce multiple occurrences of the same key in ALIST. | 505 | ;; Coalesce multiple occurrences of the same key in ALIST. |
diff --git a/tests/transformations.scm b/tests/transformations.scm index 902bd45a6a4..3417c994ec4 100644 --- a/tests/transformations.scm +++ b/tests/transformations.scm | |||
| @@ -29,7 +29,10 @@ | |||
| 29 | #:use-module (guix build-system) | 29 | #:use-module (guix build-system) |
| 30 | #:use-module (guix build-system gnu) | 30 | #:use-module (guix build-system gnu) |
| 31 | #:use-module (guix transformations) | 31 | #:use-module (guix transformations) |
| 32 | #:use-module ((guix gexp) #:select (local-file? local-file-file)) | 32 | #:use-module ((guix gexp) |
| 33 | #:select (local-file? local-file-file | ||
| 34 | computed-file? computed-file-gexp | ||
| 35 | gexp-input-thing)) | ||
| 33 | #:use-module (guix ui) | 36 | #:use-module (guix ui) |
| 34 | #:use-module (guix utils) | 37 | #:use-module (guix utils) |
| 35 | #:use-module (guix git) | 38 | #:use-module (guix git) |
| @@ -400,6 +403,31 @@ | |||
| 400 | (map local-file-file | 403 | (map local-file-file |
| 401 | (origin-patches (package-source dep))))))))) | 404 | (origin-patches (package-source dep))))))))) |
| 402 | 405 | ||
| 406 | (test-equal "options->transformation, with-commit + with-patch" | ||
| 407 | '(#t #t) | ||
| 408 | (let* ((patch (search-patch "glibc-locales.patch")) | ||
| 409 | (commit "f8934ec94df5868ee8baf1fb0f8ed0f24e7e91eb") | ||
| 410 | (t (options->transformation | ||
| 411 | ;; Note: options are applied in reverse order, so | ||
| 412 | ;; 'with-patch' comes on top. | ||
| 413 | `((with-patch . ,(string-append "guile-gcrypt=" patch)) | ||
| 414 | (with-commit | ||
| 415 | . ,(string-append "guile-gcrypt=" commit)))))) | ||
| 416 | (let ((new (t (@ (gnu packages gnupg) guile-gcrypt)))) | ||
| 417 | (match (package-source new) | ||
| 418 | ((? computed-file? source) | ||
| 419 | (let* ((gexp (computed-file-gexp source)) | ||
| 420 | (inputs (map gexp-input-thing | ||
| 421 | ((@@ (guix gexp) gexp-inputs) gexp)))) | ||
| 422 | (list (any (lambda (input) | ||
| 423 | (and (git-checkout? input) | ||
| 424 | (string=? commit (git-checkout-commit input)))) | ||
| 425 | inputs) | ||
| 426 | (any (lambda (input) | ||
| 427 | (and (local-file? input) | ||
| 428 | (string=? (local-file-file input) patch))) | ||
| 429 | inputs)))))))) | ||
| 430 | |||
| 403 | (test-equal "options->transformation, with-latest" | 431 | (test-equal "options->transformation, with-latest" |
| 404 | "42.0" | 432 | "42.0" |
| 405 | (mock ((guix upstream) %updaters | 433 | (mock ((guix upstream) %updaters |
