guix: Add lint-checker for packages which should be no inputs at all.

Also refactor some common code into a new function.

Examples for these pacakges are python(2)-setuptools and python(2)-pip, which
are installed together with python itself.

* guix/scripts/lint.scm (warn-if-package-has-input): New procedure.
  (check-inputs-should-be-native package): Use it; rename and clean-up
  variables. (check-inputs-should-not-be-an-input-at-all): New procedure.
  (%checkers) Add it.
* doc/guix.texi (Python Modules): Document it.
* tests/lint.scm: ("inputs: python-setuptools should not be an input at all
  (input)", "inputs: python-setuptools should not be an input at all
  (native-input)" "inputs: python-setuptools should not be an input at all
  (propagated-input)"): Add tests.
This commit is contained in:
Hartmut Goebel 2016-09-28 11:36:35 +02:00
parent 15e57f5762
commit 891a843d51
No known key found for this signature in database
GPG Key ID: 634A8DFFD3F631DF
3 changed files with 81 additions and 19 deletions

View File

@ -13602,7 +13602,8 @@ following check list to determine which dependency goes where.
@item @item
We currently package Python 2 with @code{setuptools} and @code{pip} We currently package Python 2 with @code{setuptools} and @code{pip}
installed like Python 3.4 has per default. Thus you don't need to installed like Python 3.4 has per default. Thus you don't need to
specify either of these as an input. specify either of these as an input. @command{guix lint} will warn you
if you do.
@item @item
Python dependencies required at run time go into Python dependencies required at run time go into

View File

@ -4,6 +4,7 @@
;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org> ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org> ;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org>
;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -59,6 +60,7 @@
#:export (guix-lint #:export (guix-lint
check-description-style check-description-style
check-inputs-should-be-native check-inputs-should-be-native
check-inputs-should-not-be-an-input-at-all
check-patch-file-names check-patch-file-names
check-synopsis-style check-synopsis-style
check-derivation check-derivation
@ -228,19 +230,11 @@ by two spaces; possible infraction~p at ~{~a~^, ~}")
(format #f (_ "invalid description: ~s") description) (format #f (_ "invalid description: ~s") description)
'description)))) 'description))))
(define (check-inputs-should-be-native package) (define (warn-if-package-has-input linted inputs-to-check input-names message)
;; Emit a warning if some inputs of PACKAGE are likely to belong to its ;; Emit a warning MESSAGE if some of the inputs named in INPUT-NAMES are
;; native inputs. ;; contained in INPUTS-TO-CHECK, which are assumed to be inputs of package
(let ((linted package) ;; LINTED.
(inputs (package-inputs package)) (match inputs-to-check
(native-inputs
'("pkg-config"
"extra-cmake-modules"
"glib:bin"
"intltool"
"itstool"
"qttools")))
(match inputs
(((labels packages . outputs) ...) (((labels packages . outputs) ...)
(for-each (lambda (package output) (for-each (lambda (package output)
(when (package? package) (when (package? package)
@ -249,13 +243,42 @@ by two spaces; possible infraction~p at ~{~a~^, ~}")
(if (> (length output) 0) (if (> (length output) 0)
(string-append ":" (car output)) (string-append ":" (car output))
"")))) ""))))
(when (member input native-inputs) (when (member input input-names)
(emit-warning linted (emit-warning linted
(format #f (_ "'~a' should probably \ (format #f (_ message) input)
be a native input") 'inputs-to-check)))))
input) packages outputs))))
'inputs)))))
packages outputs))))) (define (check-inputs-should-be-native package)
;; Emit a warning if some inputs of PACKAGE are likely to belong to its
;; native inputs.
(let ((message "'~a' should probably be a native input")
(inputs (package-inputs package))
(input-names
'("pkg-config"
"extra-cmake-modules"
"glib:bin"
"intltool"
"itstool"
"qttools")))
(warn-if-package-has-input package inputs input-names message)))
(define (check-inputs-should-not-be-an-input-at-all package)
;; Emit a warning if some inputs of PACKAGE are likely to should not be
;; an input at all.
(let ((message "'~a' should probably not be an input at all")
(inputs (package-inputs package))
(input-names
'("python-setuptools"
"python2-setuptools"
"python-pip"
"python2-pip")))
(warn-if-package-has-input package (package-inputs package)
input-names message)
(warn-if-package-has-input package (package-native-inputs package)
input-names message)
(warn-if-package-has-input package (package-propagated-inputs package)
input-names message)))
(define (package-name-regexp package) (define (package-name-regexp package)
"Return a regexp that matches PACKAGE's name as a word at the beginning of a "Return a regexp that matches PACKAGE's name as a word at the beginning of a
@ -844,6 +867,10 @@ them for PACKAGE."
(name 'inputs-should-be-native) (name 'inputs-should-be-native)
(description "Identify inputs that should be native inputs") (description "Identify inputs that should be native inputs")
(check check-inputs-should-be-native)) (check check-inputs-should-be-native))
(lint-checker
(name 'inputs-should-not-be-input)
(description "Identify inputs that should be inputs at all")
(check check-inputs-should-not-be-an-input-at-all))
(lint-checker (lint-checker
(name 'patch-file-names) (name 'patch-file-names)
(description "Validate file names and availability of patches") (description "Validate file names and availability of patches")

View File

@ -3,6 +3,7 @@
;;; Copyright © 2014, 2015, 2016 Eric Bavier <bavier@member.fsf.org> ;;; Copyright © 2014, 2015, 2016 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org> ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -33,6 +34,7 @@
#:use-module (gnu packages) #:use-module (gnu packages)
#:use-module (gnu packages glib) #:use-module (gnu packages glib)
#:use-module (gnu packages pkg-config) #:use-module (gnu packages pkg-config)
#:use-module (gnu packages python)
#:use-module (web server) #:use-module (web server)
#:use-module (web server http) #:use-module (web server http)
#:use-module (web response) #:use-module (web response)
@ -354,6 +356,38 @@ string) on HTTP requests."
(check-inputs-should-be-native pkg))) (check-inputs-should-be-native pkg)))
"'glib:bin' should probably be a native input"))) "'glib:bin' should probably be a native input")))
(test-assert
"inputs: python-setuptools should not be an input at all (input)"
(->bool
(string-contains
(with-warnings
(let ((pkg (dummy-package "x"
(inputs `(("python-setuptools" ,python-setuptools))))))
(check-inputs-should-not-be-an-input-at-all pkg)))
"'python-setuptools' should probably not be an input at all")))
(test-assert
"inputs: python-setuptools should not be an input at all (native-input)"
(->bool
(string-contains
(with-warnings
(let ((pkg (dummy-package "x"
(native-inputs
`(("python-setuptools" ,python-setuptools))))))
(check-inputs-should-not-be-an-input-at-all pkg)))
"'python-setuptools' should probably not be an input at all")))
(test-assert
"inputs: python-setuptools should not be an input at all (propagated-input)"
(->bool
(string-contains
(with-warnings
(let ((pkg (dummy-package "x"
(propagated-inputs
`(("python-setuptools" ,python-setuptools))))))
(check-inputs-should-not-be-an-input-at-all pkg)))
"'python-setuptools' should probably not be an input at all")))
(test-assert "patches: file names" (test-assert "patches: file names"
(->bool (->bool
(string-contains (string-contains