From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id oMjXGclh42StegAASxT56A (envelope-from ) for ; Mon, 21 Aug 2023 15:08:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id YLy/Gclh42QcwQAA9RJhRA (envelope-from ) for ; Mon, 21 Aug 2023 15:08:25 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D1C1846D52 for ; Mon, 21 Aug 2023 15:08:24 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r23 header.b=YEPKGKPX; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1692623305; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=ZlZr805h7G8MCH3S30uHPQFsdh1w4iiyortay6hsQZ8=; b=hDzvp2ISldKrPB+8JP/x6RWgjMAiT0HSeocxLd3KN4VxX4wXIFoQFcyxqzhcRI17+PsIm1 FnLnbvqaXZj/FRVdfv86bJaCVA1rVbh/SUIJgNYaetFKl/WLTUxhsHL2AEgPPGMz2iWUXU TzSOtuTrrCsJPFAb12Qeg2mE+Kv9lj/C1IpCKHWqXE/1LtE7a2Qv4cz+nUL/oaCYcUdS6k 1+w7HuW8trAti5p5IZw1T5mO8zhQmADPffIex96njBSKPWAMbfYiWmog46N3P6fFlu6mRt 8zAI2dI+Rl8bj42Zbu3hQngeJrksZQnwUreJNp1fufpIzUVfdM8S/b9gSyk8eg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1692623305; a=rsa-sha256; cv=none; b=Qic7rIbNWgiY9ffIh8Hs7pDbSqIQezITTy+6hz133qb/P27chZfOqX8tLk24/icfJ7pHw/ MXOWC43e7GNWvX2OK95AdhRxMAs6KG1TafJ8Z6ildQo4uWVCz+xbcMG5IaAJ0nzQn8oB2k wHBxn6ARUDAIrvn888dDU2wIRezMvMReZx/rTJHXFoWrHUqFt9TXFZz6/Hz08+l5DHh7ut bY+oHqAGqn9mqAAJq4WhEsZ4Dmxr3U0grB5+nUp6SYXu6jPaXD+6U/aVt3FsGIy18cpMqN GkncZTDq1RGIdUd+bTk0r4d2N1ZuX3talQVwHGjdznOgw4A4K2B4xYfzf+0Vpw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r23 header.b=YEPKGKPX; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qY4dZ-0007aP-CQ; Mon, 21 Aug 2023 09:08:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qY4dX-0007a0-HH for guix-patches@gnu.org; Mon, 21 Aug 2023 09:08:03 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qY4dW-0002sQ-UJ; Mon, 21 Aug 2023 09:08:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qY4dW-000479-2T; Mon, 21 Aug 2023 09:08:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65426] [PATCH] lint: Check that (cc-for-target) and friends are used. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Mon, 21 Aug 2023 13:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65426 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65426@debbugs.gnu.org Cc: Maxime Devos , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.169262327315799 (code B ref -1); Mon, 21 Aug 2023 13:08:01 +0000 Received: (at submit) by debbugs.gnu.org; 21 Aug 2023 13:07:53 +0000 Received: from localhost ([127.0.0.1]:55837 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qY4dM-00046l-GB for submit@debbugs.gnu.org; Mon, 21 Aug 2023 09:07:53 -0400 Received: from lists.gnu.org ([2001:470:142::17]:45956) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qY4dI-00046X-P0 for submit@debbugs.gnu.org; Mon, 21 Aug 2023 09:07:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qY4d5-0007QT-Qf for guix-patches@gnu.org; Mon, 21 Aug 2023 09:07:38 -0400 Received: from baptiste.telenet-ops.be ([2a02:1800:120:4::f00:13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qY4d1-0002nr-Ab for guix-patches@gnu.org; Mon, 21 Aug 2023 09:07:35 -0400 Received: from localhost.localdomain ([IPv6:2a02:1811:8c09:9d00:5dba:d409:33f7:a16]) by baptiste.telenet-ops.be with bizsmtp id cD7Q2A00420ykKC01D7RV9; Mon, 21 Aug 2023 15:07:25 +0200 From: Maxime Devos Date: Mon, 21 Aug 2023 15:07:20 +0200 Message-ID: <79bb8251f2c668c1af68b6fc5362149e3987f7e5.1692623240.git.maximedevos@telenet.be> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r23; t=1692623245; bh=ZlZr805h7G8MCH3S30uHPQFsdh1w4iiyortay6hsQZ8=; h=From:To:Cc:Subject:Date; b=YEPKGKPXRepEHZs0HI/D1qwEvOrNiepYnZzirDWzqwZGruZxfJ2MQTtIFnWWO9z0v de6k9/nQKBvu9L+oxlB3Id6ChBhj7jp0dK+pP1ZuOX61ORb0gkv00nkdrVUqyrlQiF 2Mjx3fniCxMfFFanGzI+QZFAQD1oAbKUN1eMznTrRSWnsWUM07b3s8H5iXbgfJMhsf cLjkaXOkSFb2XMrfItcGVV3rUi/OUCZhBLaz/Hm0vJ2Nn3U375UpMAXcwbjhCV0kSu 0DIK1X9EmRlz8RfUdr9fNA0397QrKi2RiGvKzyWRQXjutAdUDBkUd0PSdQUMWKqJNT gtw+NHlT1Tn0g== Received-SPF: pass client-ip=2a02:1800:120:4::f00:13; envelope-from=maximedevos@telenet.be; helo=baptiste.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -2.70 X-Spam-Score: -2.70 X-Migadu-Queue-Id: D1C1846D52 X-Migadu-Scanner: mx1.migadu.com X-TUID: ROOwsX7PTaAB "CC=gcc" is almost always incorrect; people often just don't notice the incorrectness because they are compiling natively. I don't know of any packages in Guix where "CC=gcc" is correct. "guix style" partially made things worse, so I partially ignored it. * guix/lint.scm (check-compiler-for-target): New linter. * tests/lint.scm ("compiler-for-target: unconditional CC=gcc is unacceptable") ("compiler-for-target: looks through G-expressions") ("compiler-for-target: (cc-for-target) is acceptable"): Test it. (Remove before applying) I was cross-compiling something (libical), which failed, so I wrote a linter to prevent a class of cross-compilation problems. I accidentally tested for some other class of cross-compilation problems, but whatever, this is still useful. p.s.: Does anyone know any Git documentation in the scissors stuff? --- guix/lint.scm | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- tests/lint.scm | 23 ++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/guix/lint.scm b/guix/lint.scm index d173563e51..a517b96a88 100644 --- a/guix/lint.scm +++ b/guix/lint.scm @@ -12,7 +12,7 @@ ;;; Copyright © 2020 Chris Marusich ;;; Copyright © 2020 Timothy Sample ;;; Copyright © 2021 Xinglu Chen -;;; Copyright © 2021, 2022 Maxime Devos +;;; Copyright © 2021-2023 Maxime Devos ;;; Copyright © 2021 Brice Waegeneire ;;; ;;; This file is part of GNU Guix. @@ -114,6 +114,7 @@ (define-module (guix lint) check-profile-collisions check-haskell-stackage check-tests-true + check-compiler-for-target lint-warning lint-warning? @@ -311,6 +312,49 @@ (define (check-tests-true package) #:field 'arguments)) '())) +(define (check-compiler-for-target package) + "Check that cross-compilers are used when cross-compiling, by inspecting +#:make-flags." + (define (make-compiler-warning variable=value) + (define =-index (string-index variable=value #\=)) + (define variable (substring variable=value 0 =-index)) + (define value (substring variable=value (+ =-index 1))) + (make-warning package + (G_ "'~0@*~a' should be set to '~1@*~a' instead of '~2@*~a'") + (list variable + (match variable + ("AR" "(ar-for-target)") + ("AS" "(as-for-target)") + ("CC" "(cc-for-target)") + ("CXX" "(cxx-for-target)") + ("LD" "(ld-for-target)") + ("PKG_CONFIG" "(pkg-config-for-target)")) + value) + #:field 'arguments)) + (define (find-incorrect-compilers l) + (match l + ((or "AR=ar" + "AS=as" + ;; 'cc' doesn't actually exist in Guix, but if it did, + ;; it would be incorrect to use it w.r.t. cross-compilation. + "CC=cc" "CC=gcc" "CC=clang" + "CXX=g++" + "LD=ld" + "PKG_CONFIG=pkg-config") + (list (make-compiler-warning l))) + ((x . y) + (append (find-incorrect-compilers x) + (find-incorrect-compilers y))) + (_ '()))) + (parameterize ((%current-target-system "aarch64-linux-gnu")) + (apply (lambda* (#:key make-flags #:allow-other-keys) + (define make-flags/sexp + (if (gexp? make-flags/sexp) + (gexp->approximate-sexp make-flags) + make-flags)) + (find-incorrect-compilers make-flags/sexp)) + (package-arguments package)))) + (define (properly-starts-sentence? s) (string-match "^[(\"'`[:upper:][:digit:]]" s)) @@ -1864,6 +1908,10 @@ (define %local-checkers (name 'tests-true) (description "Check if tests are explicitly enabled") (check check-tests-true)) + (lint-checker + (name 'compiler-for-target) + (description "Check that cross-compilers are used when cross-compiling") + (check check-compiler-for-target)) (lint-checker (name 'description) (description "Validate package descriptions") diff --git a/tests/lint.scm b/tests/lint.scm index b91bd053c5..45359d3783 100644 --- a/tests/lint.scm +++ b/tests/lint.scm @@ -10,7 +10,7 @@ ;;; Copyright © 2020 Timothy Sample ;;; Copyright © 2020 Tobias Geerinckx-Rice ;;; Copyright © 2021 Xinglu Chen -;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021, 2023 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -342,6 +342,27 @@ (define (warning-contains? str warnings) `(#:tests? ,(not (%current-target-system))))))) (check-tests-true pkg))) +(test-equal "compiler-for-target: unconditional CC=gcc is unacceptable" + "'CC' should be set to '(cc-for-target)' instead of 'gcc'" + (single-lint-warning-message + (check-compiler-for-target + (dummy-package "x" (arguments '(#:make-flags '("CC=gcc"))))))) + + +(test-equal "compiler-for-target: looks through G-expressions" + "'CC' should be set to '(cc-for-target)' instead of 'gcc'" + (single-lint-warning-message + (check-compiler-for-target + (dummy-package "x" (arguments '(#:make-flags #~'("CC=gcc"))))))) + +(test-equal "compiler-for-target: (cc-for-target) is acceptable" + '() + (check-compiler-for-target + (dummy-package "x" + (arguments + (list #:make-flags + #~(list (string-append "CC=" (cc-for-target)))))))) + ;; The emacs-build-system sets #:tests? #f by default. (test-equal "tests-true: #:tests? #t acceptable for emacs packages" '() base-commit: 707682ac75a81f41a478c2c51672ca49b98fa6eb prerequisite-patch-id: b6e78e4ce45fc555f83ef70ba4b158046f750dc3 -- 2.41.0