From patchwork Mon Aug 21 13:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: M X-Patchwork-Id: 53073 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 4DBD127BBEA; Mon, 21 Aug 2023 15:01:28 +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 2616127BBE2 for ; Mon, 21 Aug 2023 15:01:27 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qY5Sr-0003xr-QW; Mon, 21 Aug 2023 10:01: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 1qY5Sp-0003wk-Ll for guix-patches@gnu.org; Mon, 21 Aug 2023 10:01:04 -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 1qY5Sp-0004Pi-9r; Mon, 21 Aug 2023 10:01:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qY5So-0008Rv-Jx; Mon, 21 Aug 2023 10:01:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65426] [PATCH v2] lint: Check that (cc-for-target) and friends are used. References: <79bb8251f2c668c1af68b6fc5362149e3987f7e5.1692623240.git.maximedevos@telenet.be> In-Reply-To: <79bb8251f2c668c1af68b6fc5362149e3987f7e5.1692623240.git.maximedevos@telenet.be> 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 14:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 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-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 65426-submit@debbugs.gnu.org id=B65426.169262643432416 (code B ref 65426); Mon, 21 Aug 2023 14:01:02 +0000 Received: (at 65426) by debbugs.gnu.org; 21 Aug 2023 14:00:34 +0000 Received: from localhost ([127.0.0.1]:57354 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qY5SL-0008Qm-96 for submit@debbugs.gnu.org; Mon, 21 Aug 2023 10:00:33 -0400 Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]:46736) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qY5SI-0008QT-C0 for 65426@debbugs.gnu.org; Mon, 21 Aug 2023 10:00:31 -0400 Received: from localhost.localdomain ([IPv6:2a02:1811:8c09:9d00:5dba:d409:33f7:a16]) by andre.telenet-ops.be with bizsmtp id cE0L2A00S20ykKC01E0LbZ; Mon, 21 Aug 2023 16:00:20 +0200 From: Maxime Devos Date: Mon, 21 Aug 2023 15:59:53 +0200 Message-ID: <025525cb01ccce0a9e7a07bc9338423961eaa355.1692626393.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=1692626420; bh=zlx5C3dDcZfFO8DKkpNhYLDe5H/0rx2AuXtnlq5lGE8=; h=From:To:Cc:Subject:Date; b=NCMvepd206WioxtSuto+yOjqr0+Mz4FGxTa7fVtPvt5Rs73U0SpEdjWxdSsyLbxwu Hy71ALYsca7Gg5XoWAJwMuMhRxBQVnHx4BjfIICby7Q0/rOrqFA8AqCxSp6ozjizQE ZYMWvcjPbr82DOXxG7wA5031PWtYyG5B5U/Bd6JbIr4zTMeiUg09Oc+w2IJdIanpLR I8nnIu+rY0QyGtYDCKwepHhgjszZOVrqi9Bc4ZdNJxJfZ92+4576Tnan5ZOJV19j7c e7ka6jRYoqU/6I28k9rXb7oIgB8O4o5iI7p4D6NO1yxHGzsWMBs+4MfSHdmnRq2APN WxtvRUePfbQPw== 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. For an exception, see tzdata. "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") ("compiler-for-target: CC=gcc is acceptable when target=#false"): Test it. (Remove before applying) I forgot the 'tzdata' case in the previous version, even though I added the #:target #false myself IIRC ... I also fixed a spacing error. --- guix/lint.scm | 56 +++++++++++++++++++++++++++++++++++++++++++++++++- tests/lint.scm | 32 ++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) base-commit: 707682ac75a81f41a478c2c51672ca49b98fa6eb prerequisite-patch-id: b6e78e4ce45fc555f83ef70ba4b158046f750dc3 diff --git a/guix/lint.scm b/guix/lint.scm index d173563e51..7ccf52dec1 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,55 @@ (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 (target 'not-set) + make-flags #:allow-other-keys) + (define make-flags/sexp + (if (gexp? make-flags/sexp) + (gexp->approximate-sexp make-flags) + make-flags)) + ;; Some packages like 'tzdata' are never cross-compiled; + ;; the compilers are only used to build tools for + ;; compiling the rest of the package. + (if (eq? target '#false) + '() + (find-incorrect-compilers make-flags/sexp))) + (package-arguments package)))) + (define (properly-starts-sentence? s) (string-match "^[(\"'`[:upper:][:digit:]]" s)) @@ -1864,6 +1914,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..a52a82237b 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,36 @@ (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)))))))) + +(test-equal "compiler-for-target: CC=gcc is acceptable when target=#false" + '() + (check-compiler-for-target + ;; This (dummy) package consists purely of architecture-independent data. + (dummy-package "tzdata" + (arguments + (list #:target #false + #:make-flags #~(list "CC=gcc")))))) + ;; The emacs-build-system sets #:tests? #f by default. (test-equal "tests-true: #:tests? #t acceptable for emacs packages" '()