From: Cyril Roelandt <tipecaml@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCHv2] lint: add 'source' checker.
Date: Thu, 15 Jan 2015 08:52:45 +0100 [thread overview]
Message-ID: <1421308365-15655-1-git-send-email-tipecaml@gmail.com> (raw)
In-Reply-To: <1419824407-6471-1-git-send-email-tipecaml@gmail.com>
* guix/scripts/lint.scm (validate-uri?): New procedure.
(%checkers): Add 'home-page' checker
---
guix/scripts/lint.scm | 102 +++++++++++++++++++++++++++++++++-----------------
1 file changed, 68 insertions(+), 34 deletions(-)
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index 15ae213..7a0b246 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -20,6 +20,7 @@
(define-module (guix scripts lint)
#:use-module (guix base32)
+ #:use-module (guix download)
#:use-module (guix packages)
#:use-module (guix records)
#:use-module (guix ui)
@@ -31,7 +32,8 @@
#:use-module (ice-9 format)
#:use-module (web uri)
#:use-module ((guix build download)
- #:select (open-connection-for-uri))
+ #:select (maybe-expand-mirrors
+ open-connection-for-uri))
#:use-module (web request)
#:use-module (web response)
#:use-module (srfi srfi-1)
@@ -254,45 +256,53 @@ response from URI, and additional details, such as the actual HTTP response."
(_
(values 'not-http #f)))))
+(define (validate-uri uri package field)
+ "Return #t if the given URI can be reached, otherwise emit a
+warning for PACKAGE mentionning the FIELD."
+ (let-values (((status argument)
+ (probe-uri uri)))
+ (case status
+ ((http-response)
+ (unless (= 200 (response-code argument))
+ (emit-warning package
+ (format #f
+ (_ "URI ~a not reachable: ~a (~s)")
+ (uri->string uri)
+ (response-code argument)
+ (response-reason-phrase argument))
+ field)))
+ ((getaddrinfo-error)
+ (emit-warning package
+ (format #f
+ (_ "URI ~a domain not found: ~a")
+ (uri->string uri)
+ (gai-strerror (car argument)))
+ field))
+ ((system-error)
+ (emit-warning package
+ (format #f
+ (_ "URI ~a unreachable: ~a")
+ (uri->string uri)
+ (strerror
+ (system-error-errno
+ (cons status argument))))
+ field))
+ ((invalid-http-response gnutls-error)
+ ;; Probably a misbehaving server; ignore.
+ #f)
+ ((not-http) ;nothing we can do
+ #f)
+ (else
+ (error "internal linter error" status)))
+ #t))
+
(define (check-home-page package)
"Emit a warning if PACKAGE has an invalid 'home-page' field, or if that
'home-page' is not reachable."
(let ((uri (and=> (package-home-page package) string->uri)))
(cond
((uri? uri)
- (let-values (((status argument)
- (probe-uri uri)))
- (case status
- ((http-response)
- (unless (= 200 (response-code argument))
- (emit-warning package
- (format #f
- (_ "home page ~a not reachable: ~a (~s)")
- (uri->string uri)
- (response-code argument)
- (response-reason-phrase argument))
- 'home-page)))
- ((getaddrinfo-error)
- (emit-warning package
- (format #f
- (_ "home page domain not found: ~a")
- (gai-strerror (car argument)))
- 'package))
- ((system-error)
- (emit-warning package
- (format #f
- (_ "home page unreachable: ~a")
- (strerror
- (system-error-errno
- (cons status argument))))
- 'home-page))
- ((invalid-http-response gnutls-error)
- ;; Probably a misbehaving server; ignore.
- #f)
- ((not-http) ;nothing we can do
- #f)
- (else
- (error "internal home-page linter error" status)))))
+ (validate-uri uri package 'home-page))
((not (package-home-page package))
(unless (or (string-contains (package-name package) "bootstrap")
(string=? (package-name package) "ld-wrapper"))
@@ -375,6 +385,26 @@ descriptions maintained upstream."
(location->string loc) (package-full-name package)
(fill-paragraph (escape-quotes upstream) 77 7)))))))
+(define (check-source package)
+ "Emit a warning if PACKAGE has an invalid 'source' field, or if that
+'source' is not reachable."
+ (let ((origin (package-source package)))
+ (when (and origin
+ (eqv? (origin-method origin) url-fetch))
+ (let* ((strings (origin-uri origin))
+ (uris (if (list? strings)
+ (map string->uri strings)
+ (list (string->uri strings)))))
+ (for-each
+ (match-lambda
+ ((? uri? uri)
+ (validate-uri uri package 'source))
+ (_ (error "internal linter error")))
+ (concatenate (map (lambda (uri)
+ (maybe-expand-mirrors uri %mirrors))
+ uris)))))))
+
+
\f
;;;
;;; List of checkers.
@@ -403,6 +433,10 @@ descriptions maintained upstream."
(description "Validate home-page URLs")
(check check-home-page))
(lint-checker
+ (name 'source)
+ (description "Validate source URLs")
+ (check check-source))
+ (lint-checker
(name 'synopsis)
(description "Validate package synopses")
(check check-synopsis-style))))
--
1.8.4.rc3
next prev parent reply other threads:[~2015-01-15 7:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-28 17:02 New home-page checker for ‘guix lint’ Ludovic Courtès
2014-12-29 3:08 ` Cyril Roelandt
2014-12-29 3:40 ` [PATCH] lint: add 'source' checker Cyril Roelandt
2014-12-29 13:05 ` David Thompson
2014-12-29 14:23 ` Ludovic Courtès
2015-01-03 2:43 ` Cyril Roelandt
2015-01-03 19:11 ` Ludovic Courtès
2014-12-29 20:32 ` Ludovic Courtès
2015-01-15 7:52 ` Cyril Roelandt [this message]
2015-01-15 21:58 ` [PATCHv2] " Ludovic Courtès
2015-01-23 9:56 ` Ludovic Courtès
2015-01-25 17:43 ` Cyril Roelandt
2014-12-29 14:18 ` New home-page checker for ‘guix lint’ Ludovic Courtès
2014-12-29 20:27 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1421308365-15655-1-git-send-email-tipecaml@gmail.com \
--to=tipecaml@gmail.com \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.