From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id ENc6KTKA42QEIwEASxT56A (envelope-from ) for ; Mon, 21 Aug 2023 17:18:10 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id SGbxKDKA42RpJQAA9RJhRA (envelope-from ) for ; Mon, 21 Aug 2023 17:18:10 +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 33AE56303E for ; Mon, 21 Aug 2023 17:18:10 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r23 header.b=NCMvepd2; 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-Seal: i=1; s=key1; d=yhetil.org; t=1692631090; a=rsa-sha256; cv=none; b=g7DPnF/FjJnYRd1Bu7eOaCPcPXVyrBl+Aou9Snh4t3lGAQLTHgFWkY/piybDKUm1cZBWAt G+cJc63N82/f9j1SZSaZk0An3bWWTI6bdz6QXGUHPZWXTNNga9hWSKt7fZDNCmG7MSzwMx kBZkhSwjH0f/n6dLhPAx7eePzT134MnsnkncVsiANApDxwCyBaktqyJUlKKaGykE6jP0J+ OdYoPdC5a9chyK4f4dvei18T+l1GkzX6B44zozhNOzHhqwDJ0+xaieHpLde3VWK8Gof395 qnDKJVc6ditJbYCIcoDf5YBWAy4AkVPkNTKZlGqwyaZxdlOCil5R1Yqp2IiOqA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r23 header.b=NCMvepd2; 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=1692631090; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=zlx5C3dDcZfFO8DKkpNhYLDe5H/0rx2AuXtnlq5lGE8=; b=Qm+PWaG1lTMmKd3YXoLfg0XpqkrzInbrWmnzaZ5mXc8yMWK4rc4Tklc2lrk8tAJY5JPkL/ ytYMf/qxYoKVOPnC11Mp0N9y2h0eiVCCqLmsNDrUUhGWCxqwkfwW25PkykW4TSvqWq8pDG e9kTtLYRnpbMNMFEyBsBn2w8CxpCFpktxXnVIIViLL8QKRe4chLOA8MX2zXgGo0NWkJUyI mTYlLV69VrOOWHn0IDQ9phVkKU6891Issb3u+xWTGWTkC5ptmhhtqMLjMMCOK3Ltbk1VkD KycMsk3vnsbNi0iq/iyNjWY/mQXf7ujFibZzJ4VIw2yUgqJA4zZ8hoCFYFgWNg== 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 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=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+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-Scanner: mx0.migadu.com X-Spam-Score: -2.70 X-Migadu-Queue-Id: 33AE56303E X-Migadu-Spam-Score: -2.70 X-TUID: v942G2azav8s "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(-) 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" '() base-commit: 707682ac75a81f41a478c2c51672ca49b98fa6eb prerequisite-patch-id: b6e78e4ce45fc555f83ef70ba4b158046f750dc3 -- 2.41.0