summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-04-12 23:14:19 +0200
committerLudovic Courtès <ludo@gnu.org>2015-04-13 00:02:59 +0200
commit002c57c6f7d51077e4796106177456ebb564e25a (patch)
treee0f1d13fbc7481bac013b9c1c7426dbe056e6317
parent866f469eddb6a28cfdbc3b2eec3d3a6a241f7168 (diff)
downloadguix-002c57c6f7d51077e4796106177456ebb564e25a.tar.gz
lint: Add a 'derivation' checker.
* guix/scripts/lint.scm (check-derivation): New procedure.
  (%checkers): Add 'derivation' checker.
* tests/lint.scm ("derivation: invalid arguments"): New test.
-rw-r--r--guix/scripts/lint.scm27
-rw-r--r--tests/lint.scm10
2 files changed, 37 insertions, 0 deletions
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index 699311a6a9..cced1bda66 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -19,6 +19,7 @@
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (guix scripts lint)
+  #:use-module (guix store)
   #:use-module (guix base32)
   #:use-module (guix download)
   #:use-module (guix ftp-client)
@@ -32,6 +33,8 @@
   #:use-module (ice-9 regex)
   #:use-module (ice-9 format)
   #:use-module (web uri)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:use-module ((guix build download)
                 #:select (maybe-expand-mirrors
                           open-connection-for-uri))
@@ -49,6 +52,7 @@
             check-inputs-should-be-native
             check-patch-file-names
             check-synopsis-style
+            check-derivation
             check-home-page
             check-source))
 
@@ -440,6 +444,25 @@ descriptions maintained upstream."
              (append-map (cut maybe-expand-mirrors <> %mirrors)
                          uris))))))
 
+(define (check-derivation package)
+  "Emit a warning if we fail to compile PACKAGE to a derivation."
+  (catch #t
+    (lambda ()
+      (guard (c ((nix-protocol-error? c)
+                 (emit-warning package
+                               (format #f (_ "failed to create derivation: ~a")
+                                       (nix-protocol-error-message c))))
+                ((message-condition? c)
+                 (emit-warning package
+                               (format #f (_ "failed to create derivation: ~a")
+                                       (condition-message c)))))
+        (with-store store
+          (package-derivation store package))))
+    (lambda args
+      (emit-warning package
+                    (format #f (_ "failed to create derivation: ~s~%")
+                            args)))))
+
 
 
 ;;;
@@ -473,6 +496,10 @@ descriptions maintained upstream."
      (description "Validate source URLs")
      (check       check-source))
    (lint-checker
+     (name        'derivation)
+     (description "Report failure to compile a package to a derivation")
+     (check       check-derivation))
+   (lint-checker
      (name        'synopsis)
      (description "Validate package synopses")
      (check       check-synopsis-style))))
diff --git a/tests/lint.scm b/tests/lint.scm
index ab89a58ae6..2807eba1cc 100644
--- a/tests/lint.scm
+++ b/tests/lint.scm
@@ -319,6 +319,16 @@ requests."
          (check-patch-file-names pkg)))
      "patch not found")))
 
+(test-assert "derivation: invalid arguments"
+  (->bool
+   (string-contains
+    (with-warnings
+      (let ((pkg (dummy-package "x"
+                   (arguments
+                    '(#:imported-modules (invalid-module))))))
+        (check-derivation pkg)))
+    "failed to create derivation")))
+
 (test-assert "home-page: wrong home-page"
   (->bool
    (string-contains