From 0311d5b383003600ac43d3a9bfdec0ad3c398db2 Mon Sep 17 00:00:00 2001 From: Eric Bavier Date: Sun, 23 Aug 2015 18:00:45 -0500 Subject: [PATCH] guix: lint: Check for version-only origin file names. * guix/scripts/lint.scm (check-source): Emit warning if source filename contains only the version of the package. * tests/lint.scm ("source: filename", "source: filename v", "source: filename valid"): New tests. * doc/guix.texi (Invoking guix lint): Mention file name check. Offending packages updated. --- doc/guix.texi | 3 +- gnu/packages/algebra.scm | 1 + gnu/packages/audio.scm | 2 ++ gnu/packages/bioinformatics.scm | 1 + gnu/packages/python.scm | 1 + gnu/packages/telephony.scm | 3 +- gnu/packages/textutils.scm | 1 + guix/scripts/lint.scm | 68 ++++++++++++++++++++++++++--------------- tests/lint.scm | 43 ++++++++++++++++++++++++++ 9 files changed, 96 insertions(+), 27 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index f05376e..153af45 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -4133,7 +4133,8 @@ Identify inputs that should most likely be native inputs. @item source @itemx home-page Probe @code{home-page} and @code{source} URLs and report those that are -invalid. +invalid. Check that the source file name contains something other than +just the version number. @item formatting Warn about obvious source code formatting issues: trailing white space, diff --git a/gnu/packages/algebra.scm b/gnu/packages/algebra.scm index 3f23ec9..03019f8 100644 --- a/gnu/packages/algebra.scm +++ b/gnu/packages/algebra.scm @@ -386,6 +386,7 @@ cosine/ sine transforms or DCT/DST).") (method url-fetch) (uri (string-append "https://bitbucket.org/eigen/eigen/get/" version ".tar.bz2")) + (file-name (string-append name "-" version ".tar.bz2")) (sha256 (base32 "1yf27mfq1x38wlsghkvpjgs8xd5rvbbikf1wyj2l3qw8h6w6qvjz")) diff --git a/gnu/packages/audio.scm b/gnu/packages/audio.scm index 1537f33..d28fa09 100644 --- a/gnu/packages/audio.scm +++ b/gnu/packages/audio.scm @@ -1135,6 +1135,7 @@ aimed at audio/musical applications.") (string-append "https://bitbucket.org/breakfastquay/rubberband/get/v" version ".tar.bz2")) + (file-name (string-append name "-" version ".tar.bz2")) (sha256 (base32 "05amrbrxx0da3w7m237q51799r8xgs4ffqabi2qv06hq8dpcj386")))) @@ -1689,6 +1690,7 @@ synthesizer written in C++.") (method url-fetch) (uri (string-append "https://github.com/Themaister/RSound/archive/v" version ".tar.gz")) + (file-name (string-append name "-" version ".tar.gz")) (sha256 (base32 "1wzs40c0k5zpkmm5ffl6c17xmr399sxli7ys0fbb9ib0fd334knx")))) (build-system gnu-build-system) diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm index 7a50a85..e98e028 100644 --- a/gnu/packages/bioinformatics.scm +++ b/gnu/packages/bioinformatics.scm @@ -608,6 +608,7 @@ multiple sequence alignments.") (uri (string-append "https://github.com/YeoLab/clipper/archive/" version ".tar.gz")) + (file-name (string-append name "-" version ".tar.gz")) (sha256 (base32 "1q7jpimsqln7ic44i8v2rx2haj5wvik8hc1s2syd31zcn0xk1iyq")) diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm index 940efec..0f7a482 100644 --- a/gnu/packages/python.scm +++ b/gnu/packages/python.scm @@ -2444,6 +2444,7 @@ and is very extensible.") (uri (string-append "https://github.com/scikit-learn/scikit-learn/archive/" version ".tar.gz")) + (file-name (string-append name "-" version ".tar.gz")) (sha256 (base32 "140skabifgc7lvvj873pnzlwx0ni6q8qkrsyad2ccjb3h8rxzkih")))) diff --git a/gnu/packages/telephony.scm b/gnu/packages/telephony.scm index f0d5dff..ee8b2cb 100644 --- a/gnu/packages/telephony.scm +++ b/gnu/packages/telephony.scm @@ -192,7 +192,8 @@ internet.") (source (origin (method url-fetch) (uri (string-append "https://github.com/cisco/libsrtp/archive/v" - version ".tar.gz")) + version ".tar.gz")) + (file-name (string-append name "-" version ".tar.gz")) (sha256 (base32 "1njf62f6sazz2q7qc4j495v1pga385whkmxxyr8hfz1ragiyzqc6")))) diff --git a/gnu/packages/textutils.scm b/gnu/packages/textutils.scm index 08b1b64..c7cb243 100644 --- a/gnu/packages/textutils.scm +++ b/gnu/packages/textutils.scm @@ -72,6 +72,7 @@ handy front-end to the library.") (method url-fetch) (uri (string-append "https://github.com/nijel/enca/archive/" version ".tar.gz")) + (file-name (string-append name "-" version ".tar.gz")) (sha256 (base32 "1xik00x0yvhswsw2isnclabhv536xk1s42cf5z54gfbpbhc7ni8l")))) (build-system gnu-build-system) diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm index 14ac8cb..443103f 100644 --- a/guix/scripts/lint.scm +++ b/guix/scripts/lint.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014 Cyril Roelandt -;;; Copyright © 2014 Eric Bavier +;;; Copyright © 2014, 2015 Eric Bavier ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. @@ -20,6 +20,7 @@ (define-module (guix scripts lint) #:use-module (guix store) + #:use-module (guix derivations) #:use-module (guix base32) #:use-module (guix download) #:use-module (guix ftp-client) @@ -466,31 +467,48 @@ descriptions maintained upstream." uris)) '())) + (define (origin-version-name? origin) + ;; Return #t if the source file name contains only a version; indicates + ;; that the origin needs a 'file-name' field. + (let ((filename (store-path-package-name + (with-store store + (derivation->output-path + (package-source-derivation store origin))))) + (version (package-version package))) + (or (string-prefix? version filename) + ;; Common in many projects is for the filename to start with a "v" + ;; followed by the version, e.g. "v3.2.0.tar.gz". + (string-prefix? (string-append "v" version) filename)))) + (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))))) - - ;; Just make sure that at least one of the URIs is valid. - (call-with-values - (lambda () (try-uris uris)) - (lambda (success? warnings) - ;; When everything fails, report all of WARNINGS, otherwise don't - ;; report anything. - ;; - ;; XXX: Ideally we'd still allow warnings to be raised if *some* - ;; URIs are unreachable, but distinguish that from the error case - ;; where *all* the URIs are unreachable. - (unless success? - (emit-warning package - (_ "all the source URIs are unreachable:") - 'source) - (for-each (lambda (warning) - (display warning (guix-warning-port))) - (reverse warnings))))))))) + (when origin + (if (eqv? (origin-method origin) url-fetch) + (let* ((strings (origin-uri origin)) + (uris (if (list? strings) + (map string->uri strings) + (list (string->uri strings))))) + + ;; Just make sure that at least one of the URIs is valid. + (call-with-values + (lambda () (try-uris uris)) + (lambda (success? warnings) + ;; When everything fails, report all of WARNINGS, otherwise don't + ;; report anything. + ;; + ;; XXX: Ideally we'd still allow warnings to be raised if *some* + ;; URIs are unreachable, but distinguish that from the error case + ;; where *all* the URIs are unreachable. + (unless success? + (emit-warning package + (_ "all the source URIs are unreachable:") + 'source) + (for-each (lambda (warning) + (display warning (guix-warning-port))) + (reverse warnings))))))) + (if (origin-version-name? origin) + (emit-warning package + (_ "the source filename should contain the package name") + 'source))))) (define (check-derivation package) "Emit a warning if we fail to compile PACKAGE to a derivation." diff --git a/tests/lint.scm b/tests/lint.scm index 5d56420..0973741 100644 --- a/tests/lint.scm +++ b/tests/lint.scm @@ -392,6 +392,49 @@ requests." (check-home-page pkg)))) "not reachable: 404"))) +(test-assert "source: filename" + (->bool + (string-contains + (with-warnings + (let ((pkg (dummy-package "x" + (version "3.2.1") + (source + (origin + (method url-fetch) + (uri "http://www.example.com/3.2.1.tar.gz") + (sha256 %null-sha256)))))) + (check-source pkg))) + "filename should contain the package name"))) + +(test-assert "source: filename v" + (->bool + (string-contains + (with-warnings + (let ((pkg (dummy-package "x" + (version "3.2.1") + (source + (origin + (method url-fetch) + (uri "http://www.example.com/v3.2.1.tar.gz") + (sha256 %null-sha256)))))) + (check-source pkg))) + "filename should contain the package name"))) + +(test-assert "source: filename valid" + (not + (->bool + (string-contains + (with-warnings + (let ((pkg (dummy-package "x" + (version "3.2.1") + (source + (origin + (method url-fetch) + (uri "http://www.example.com/x-3.2.1.tar.gz") + (sha256 %null-sha256)))))) + (check-source pkg))) + "filename should contain the package name")))) + (test-skip (if %http-server-socket 0 1)) (test-equal "source: 200" "" -- 2.4.3