Hi Guix,

(In response to bug#47027, but opened as a new bug.)

On Wed, 2021-03-17 at 21:52 +0100, Ludovic Courtès wrote:
> Hi,
> 
> Maxime Devos <maximede...@telenet.be> skribis:
> [...]
> > Shouldn't the "guile" input be included in the native-inputs
> > as well (perhaps only native-inputs suffices), for cross-compilation?
> 
> Yes it should, good point.

FWIW, I tried to write a linter to catch these kind of issues.
(If there's a "guile" input, then there usually should also be
a "guile" native-input.)  Currently, it has too many false positives
for my taste.  I most likely won't be working on it in the near future
though.  (Preliminary patch attached)

> ./pre-int-env guix lint -t "check-inputs-should-also-be-native"

(Output attached)

Some suspicious things:
* guile-config & others are missing a "guile" in the native-inputs
* clipmenu & others use "wrap-script" to define wrapper scripts
  (in this case "guile" does not have to be in native-inputs).
  The "wrap-script" procedure from (guix build utils) uses the
  "which" procedure to determine where guile is located ...
  but this is incorrect when cross-compiling!

  (It is possible to override the "guile" binary used with a
  keyword argument).

  (I assume inputs in "inputs" do not contribute to the $PATH
  in a cross-compilation environment; only "native-inputs" should
  contribute to $PATH)

  idk if it is feasible or if there are complications, but
  IMHO the inputs in "inputs" shouldn't contribute to $PATH
  at all (not even when not cross-compilation), only inputs
  in $PATH.

There seems to be plenty of low-hanging cross-compilation fruit here!

Greetings,
Maxime
From c4798e6154275a2de41c1d5a35bc723091d4e1a4 Mon Sep 17 00:00:00 2001
From: Maxime Devos <maximede...@telenet.be>
Date: Wed, 17 Mar 2021 22:56:26 +0100
Subject: [PATCH] lint: Check whether guile should be in native-inputs.

TODO less false positives (or negatives?)
TODO proper message

* guix/lint.scm
  (check-inputs-should-also-be-native): ???
  (%local-checkers)[inputs-should-also-be-native]: New ???.
---
 guix/lint.scm | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/guix/lint.scm b/guix/lint.scm
index 311bc94cc3..d0cde23665 100644
--- a/guix/lint.scm
+++ b/guix/lint.scm
@@ -11,6 +11,7 @@
 ;;; Copyright © 2018, 2019 Arun Isaac <arunis...@systemreboot.net>
 ;;; Copyright © 2020 Chris Marusich <cmmarus...@gmail.com>
 ;;; Copyright © 2020 Timothy Sample <samp...@ngyro.com>
+;;; Copyright © 2021 Maxime Devos <maximede...@telenet.be>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -75,6 +76,7 @@
   #:use-module (ice-9 rdelim)
   #:export (check-description-style
             check-inputs-should-be-native
+            check-inputs-should-also-be-native
             check-inputs-should-not-be-an-input-at-all
             check-patch-file-names
             check-patch-headers
@@ -347,6 +349,36 @@ of a package, and INPUT-NAMES, a list of package specifications such as
             #:field 'inputs))
          (package-input-intersection inputs input-names))))
 
+#|
+(define (suspect-input->native-names package)
+  ;; Guile's compiled .go code is architecture
+  `(,@(if (string-prefix? "guile" (package-name package))
+         '("guile")
+         '()))
+|#
+
+(define (check-inputs-should-also-be-native package)
+  ;; Emit a warning if some inputs of PACKAGE are likely to belong to its
+  ;; native inputs as well.
+  (guard (c ((package-cross-build-system-error? c) '()))
+    (let ((inputs (package-inputs package))
+          (native-inputs
+           ;; Pretend we're cross-compiling,
+           ;; as some packages only add the "guile" input
+           ;; to native-inputs when %current-target-system is not #f.
+           (parameterize ((%current-target-system (%current-system)))
+             (package-native-inputs package)))
+          (input-names
+           '("guile")))
+      (filter-map (lambda (input)
+                    (and (not (assoc input native-inputs))
+                         (make-warning
+                          package
+                          (G_ "'~a' should probably also be a native input")
+                          (list input)
+                          #:field 'inputs)))
+                  (package-input-intersection inputs input-names)))))
+
 (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.
@@ -1449,6 +1481,10 @@ them for PACKAGE."
      (name        'description)
      (description "Validate package descriptions")
      (check       check-description-style))
+   (lint-checker
+     (name        'inputs-should-also-be-native)
+     (description "Identify inputs that should aso be native inputs")
+     (check        check-inputs-should-also-be-native))
    (lint-checker
      (name        'inputs-should-be-native)
      (description "Identify inputs that should be native inputs")
-- 
2.30.2

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to