summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHerman Rimm <[email protected]>2025-01-21 22:43:01 +0100
committerLudovic Courtès <[email protected]>2025-02-09 18:20:41 +0100
commit6ad2e407ebb6bf87bc30cc30d1b6f9d688a17854 (patch)
tree0699ac3990f381456fbb653f381a18c373b54fa6
parent0950b726f231a2eae3133e56aac15a935ace057e (diff)
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 <[email protected]>
-rw-r--r--guix/scripts/style.scm13
-rw-r--r--tests/guix-style.sh10
2 files changed, 15 insertions, 8 deletions
diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm
index 4b704ddfb7..6f07f6c3b9 100644
--- a/guix/scripts/style.scm
+++ b/guix/scripts/style.scm
@@ -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))
diff --git a/tests/guix-style.sh b/tests/guix-style.sh
index 9333139435..703e148b69 100644
--- a/tests/guix-style.sh
+++ b/tests/guix-style.sh
@@ -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.