From patchwork Mon Aug 21 13:07:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: M X-Patchwork-Id: 53069 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 02A0B27BBEA; Mon, 21 Aug 2023 14:08:26 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BDEBE27BBE2 for ; Mon, 21 Aug 2023 14:08:24 +0100 (BST) 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 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches "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(-) base-commit: 707682ac75a81f41a478c2c51672ca49b98fa6eb prerequisite-patch-id: b6e78e4ce45fc555f83ef70ba4b158046f750dc3 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" '()