guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/08: style: Make 'safe' policy less conservative.


From: guix-commits
Subject: 01/08: style: Make 'safe' policy less conservative.
Date: Thu, 4 May 2023 11:08:36 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 68fa28b3c3f6cca4485575b6dfa418be656443e7
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu May 4 16:41:40 2023 +0200

    style: Make 'safe' policy less conservative.
    
    Previously, a mere (arguments '(#:tests? #f)) would lead
    
      guix style -S inputs --input-simplification=safe
    
    to bail out.  It now recognizes such trivial argument lists and
    proceeds.
    
    * guix/scripts/style.scm (trivial-package-arguments?): New procedure.
    (simplify-package-inputs): Use it in the 'safe case instead of 'null?'.
    * tests/style.scm ("input labels, 'safe' policy, trivial arguments"):
    New test.
---
 guix/scripts/style.scm | 15 +++++++++++++--
 tests/style.scm        | 22 +++++++++++++++++++++-
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm
index 8e89a58948..00c7d3f90c 100644
--- a/guix/scripts/style.scm
+++ b/guix/scripts/style.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2021-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2021-2023 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -242,6 +242,17 @@ doing it."
             (location-line loc)
             (location-column loc)))
 
+(define (trivial-package-arguments? package)
+  "Return true if PACKAGE has zero arguments or only \"trivial\" arguments
+guaranteed not to refer to input labels."
+  (let loop ((arguments (package-arguments package)))
+    (match arguments
+      (()
+       #t)
+      (((? keyword?) value rest ...)
+       (and (or (boolean? value) (number? value) (string? value))
+            (loop rest))))))
+
 (define* (simplify-package-inputs package
                                   #:key (policy 'silent)
                                   (edit-expression edit-expression))
@@ -276,7 +287,7 @@ PACKAGE."
                             ;; If PACKAGE has no arguments, labels are known
                             ;; to have no effect: this is a "safe" change, but
                             ;; it may change the derivation.
-                            (if (null? (package-arguments package))
+                            (if (trivial-package-arguments? package)
                                 (const #t)
                                 label-matches?))
                            ('always
diff --git a/tests/style.scm b/tests/style.scm
index 6aab2c3785..f141a57d7f 100644
--- a/tests/style.scm
+++ b/tests/style.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2021-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2021-2023 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -234,6 +234,26 @@
       (list (package-inputs (@ (my-packages) my-coreutils))
             (read-package-field (@ (my-packages) my-coreutils) 'inputs)))))
 
+(test-equal "input labels, 'safe' policy, trivial arguments"
+  (list `(("gmp" ,gmp) ("mpfr" ,mpfr))
+        "\
+      (inputs (list gmp mpfr))\n")
+  (call-with-test-package '((inputs `(("GMP" ,gmp) ("Mpfr" ,mpfr)))
+                            (arguments            ;"trivial" arguments
+                             '(#:tests? #f
+                               #:test-target "whatever")))
+    (lambda (directory)
+      (define file
+        (string-append directory "/my-packages.scm"))
+
+      (system* "guix" "style" "-L" directory "my-coreutils"
+               "-S" "inputs"
+               "--input-simplification=safe")
+
+      (load file)
+      (list (package-inputs (@ (my-packages) my-coreutils))
+            (read-package-field (@ (my-packages) my-coreutils) 'inputs)))))
+
 (test-equal "input labels, 'safe' policy, nothing changed"
   (list `(("GMP" ,gmp) ("ACL" ,acl))
         "\



reply via email to

[Prev in Thread] Current Thread [Next in Thread]