packages: Consider 'patches' by 'package-direct-sources'.

* guix/packages.scm (package-direct-sources): Return 'origin' from 'patches'.
* tests/packages.scm: Test it.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Simon Tournier 2023-03-11 17:51:10 +01:00 committed by Ludovic Courtès
parent d4b2f5eace
commit 9fb8a480d5
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 24 additions and 3 deletions

View file

@ -9,6 +9,7 @@
;;; Copyright © 2021 Chris Marusich <cmmarusich@gmail.com> ;;; Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be> ;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2022 jgart <jgart@dismail.de> ;;; Copyright © 2022 jgart <jgart@dismail.de>
;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -1239,8 +1240,13 @@ (define-syntax modify-inputs
(define (package-direct-sources package) (define (package-direct-sources package)
"Return all source origins associated with PACKAGE; including origins in "Return all source origins associated with PACKAGE; including origins in
PACKAGE's inputs." PACKAGE's inputs and patches."
`(,@(or (and=> (package-source package) list) '()) (define (expand source)
(cons
source
(filter origin? (origin-patches source))))
`(,@(or (and=> (package-source package) expand) '())
,@(filter-map (match-lambda ,@(filter-map (match-lambda
((_ (? origin? orig) _ ...) ((_ (? origin? orig) _ ...)
orig) orig)

View file

@ -3,6 +3,7 @@
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -418,12 +419,15 @@ (define read-at
(let* ((o (dummy-origin)) (let* ((o (dummy-origin))
(u (dummy-origin)) (u (dummy-origin))
(i (dummy-origin)) (i (dummy-origin))
(j (dummy-origin (patches (list o))))
(a (dummy-package "a")) (a (dummy-package "a"))
(b (dummy-package "b" (inputs (list a i)))) (b (dummy-package "b" (inputs (list a i))))
(c (package (inherit b) (source o))) (c (package (inherit b) (source o)))
(d (dummy-package "d" (d (dummy-package "d"
(build-system trivial-build-system) (build-system trivial-build-system)
(source u) (inputs (list c))))) (source u) (inputs (list c))))
(e (dummy-package "e" (source j)))
(f (package (inherit e) (inputs (list u)))))
(test-assert "package-direct-sources, no source" (test-assert "package-direct-sources, no source"
(null? (package-direct-sources a))) (null? (package-direct-sources a)))
(test-equal "package-direct-sources, #f source" (test-equal "package-direct-sources, #f source"
@ -437,6 +441,17 @@ (define read-at
(and (= (length (pk 's-sources s)) 2) (and (= (length (pk 's-sources s)) 2)
(member o s) (member o s)
(member i s)))) (member i s))))
(test-assert "package-direct-sources, with patches"
(let ((s (package-direct-sources e)))
(and (= (length (pk 's-sources s)) 2)
(member o s)
(member j s))))
(test-assert "package-direct-sources, with patches and inputs"
(let ((s (package-direct-sources f)))
(and (= (length (pk 's-sources s)) 3)
(member o s)
(member j s)
(member u s))))
(test-assert "package-transitive-sources" (test-assert "package-transitive-sources"
(let ((s (package-transitive-sources d))) (let ((s (package-transitive-sources d)))
(and (= (length (pk 'd-sources s)) 3) (and (= (length (pk 'd-sources s)) 3)