scripts: style: Sort more kinds of package definitions.

* guix/scripts/style.scm (order-packages): Match comments before package
S-exp. and its fields.  Match in let.  Match package/inherit.
* tests/guix-style.sh: Add pkg-baz variable and package/inherit to test.

Change-Id: I48a5976930501c20415b5413966b5294958bc23b
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Herman Rimm 2025-01-21 22:43:01 +01:00 committed by Ludovic Courtès
parent 0950b726f2
commit 6ad2e407eb
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 15 additions and 8 deletions

View file

@ -503,13 +503,14 @@ top-level package definitions in alphabetical order. Packages which
share a name are placed with versions in descending order."
(define (package-fields pkg)
(match pkg
((('define-public _ expr) _ ...)
((('define-public pkg _ ... (or ('let _ expr) expr)) _ ...)
(match expr
((or ('package _ ('name name) ('version version) _ ...)
('package ('name name) ('version version) _ ...))
(values name version))
(_ (values #f #f))))
(_ (values #f #f))))
(((or 'package 'package/inherit) fields ...)
(let ((name (and=> (assoc-ref fields 'name) first))
(version (and=> (assoc-ref fields 'version) first)))
(values name version)))
(_ (and (values #f #f)))))
(_ (and (values #f #f)))))
(define (package>? lst1 lst2)
(let-values (((name1 version1) (package-fields lst1))

View file

@ -65,10 +65,16 @@ cat > "$tmpfile" <<EOF
(name "bar")
(version "2")))
(define-public pkg-baz
(let ()
(package
(name "baz")
(version "2"))))
;; The comment below belongs to the foo package.
(define-public pkg
(package
(name "bar")
(package/inherit pkg-baz
(name "baz")
(version "1")))
;; Incomplete package definitions in alphabetical order.