[PATCH] Add 'compiler-for-target' checker

  • Open
  • quality assurance status badge
Details
One participant
  • Maxime Devos
Owner
unassigned
Submitted by
Maxime Devos
Severity
normal
M
M
Maxime Devos wrote on 9 Apr 2021 17:50
(address . guix-patches@gnu.org)
5b5860a8002b66818f6619bbe3c1a4a0f19d6246.camel@telenet.be
Hi Guix,

This patch series adds a linter that detects "CC=gcc" and "CXX=g++"
in #:make-flags in the arguments field of a package. This is incorrect
when cross-compiling; ,(string-append "CC=" (cc-for-target)) or similar
should be used instead.

Patch #1: detect "CC=gcc".
Patch #2: detect "CXX=g++".

Some complaints from the checker:
$ ./pre-inst-env guix lint -c "compiler-for-target"
Toggle quote (11 lines)
> gnu/packages/admin.scm:3138:5: sunxi-tools@1.4.2: should use 'cc-for-target'
> gnu/packages/admin.scm:2969:5: cbatticon@1.6.10: should use 'cc-for-target'
> gnu/packages/assembly.scm:230:5: dev86@0.16.21: should use 'cc-for-target'
> gnu/packages/audio.scm:4870:4: lv2toweb@0.4: should use 'cc-for-target'
> gnu/packages/audio.scm:1134:5: swh-plugins-lv2@1.0.16: should use 'cc-for-target'
> gnu/packages/base.scm:1290:5: tzdata@2021a: should use 'cc-for-target'
> gnu/packages/bioinformatics.scm:10977:5: paml@4.9e: should use 'cc-for-target'
> gnu/packages/bioinformatics.scm:1677:5: bowtie1@1.3.0: should use 'cc-for-target'
> gnu/packages/bioinformatics.scm:4885:5: mash@2.1: should use 'cc-for-target'
> [...]

"make && make check TESTS=tests/lint.scm" succeeds.

Greetings,
Maxime.
From c28c9383afeea102f43aa40ea466bba4e32516bf Mon Sep 17 00:00:00 2001
From: Maxime Devos <maximedevos@telenet.be>
Date: Fri, 9 Apr 2021 17:17:01 +0200
Subject: [PATCH 2/2] lint: Extend 'compiler-for-target' to detect CXX=g++.

* guix/lint.scm (check-compiler-for-target): Detect "CXX=g++".
* tests/lint.scm
("compiler-for-target: no warnings (cxx-for-target)")
("compiler-for-target: warning (hardcoded CC=g++)"): New test cases.
---
guix/lint.scm | 33 +++++++++++++++++++++++----------
tests/lint.scm | 19 ++++++++++++++++++-
2 files changed, 41 insertions(+), 11 deletions(-)

Toggle diff (90 lines)
diff --git a/guix/lint.scm b/guix/lint.scm
index bf9acb40be..1f32ff8393 100644
--- a/guix/lint.scm
+++ b/guix/lint.scm
@@ -1366,16 +1366,29 @@ host compiler."
;; support all patterns.
(make-flags/evaluated
(false-if-exception
- (evaluate-argument make-flags package)))
- (cc (any (lambda (x)
- (and (string-prefix? "CC=" x)
- (substring x 3)))
- make-flags/evaluated)))
- (and cc (string=? cc "gcc")
- (list
- (make-warning package
- (G_ "should use 'cc-for-target'")
- #:field 'arguments))))
+ (evaluate-argument make-flags package))))
+ (let ((cc (any (lambda (x)
+ (and (string-prefix? "CC=" x)
+ (substring x 3)))
+ make-flags/evaluated))
+ (cxx (any (lambda (x)
+ (and (string-prefix? "CXX=" x)
+ (substring x 4)))
+ make-flags/evaluated)))
+ ;; GNU's C compiler
+ `(,@(if (and cc (string=? cc "gcc"))
+ (list
+ (make-warning package
+ (G_ "should use 'cc-for-target'")
+ #:field 'arguments))
+ '())
+ ;; GNU's C++ compiler
+ ,@(if (and cxx (string=? cxx "g++"))
+ (list
+ (make-warning package
+ (G_ "should use 'cxx-for-target'")
+ #:field 'arguments))
+ '()))))
'()))
(package-arguments package))))
diff --git a/tests/lint.scm b/tests/lint.scm
index bda12063bc..7aa17f060a 100644
--- a/tests/lint.scm
+++ b/tests/lint.scm
@@ -40,7 +40,7 @@
#:use-module (guix swh)
#:use-module ((guix gexp) #:select (local-file))
#:use-module ((guix utils) #:select (call-with-temporary-directory
- cc-for-target))
+ cc-for-target cxx-for-target))
#:use-module ((guix import hackage) #:select (%hackage-url))
#:use-module ((guix import stackage) #:select (%stackage-url))
#:use-module (gnu packages)
@@ -1117,6 +1117,14 @@
(arguments
`(#:make-flags (list ,(string-append "CC=" (cc-for-target))))))))
+(test-equal "compiler-for-target: no warnings (cxx-for-target)"
+ '()
+ (check-compiler-for-target
+ (package
+ (inherit (dummy-package "x"))
+ (arguments
+ `(#:make-flags (list ,(string-append "CXX=" (cxx-for-target))))))))
+
(test-equal "compiler-for-target: warning (hardcoded CC=gcc)"
"should use 'cc-for-target'"
(single-lint-warning-message
@@ -1126,6 +1134,15 @@
(arguments
`(#:make-flags '("CC=gcc")))))))
+(test-equal "compiler-for-target: warning (hardcoded CC=g++)"
+ "should use 'cxx-for-target'"
+ (single-lint-warning-message
+ (check-compiler-for-target
+ (package
+ (inherit (dummy-package "x"))
+ (arguments
+ `(#:make-flags '("CXX=g++")))))))
+
(test-end "lint")
;; Local Variables:
--
2.31.1
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYHB3xBccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7kYDAQCe6v4C2RMis6ixzb7zMQHkNsta
h2bQctVYOmmjwFQUVAD/SoFAj9Zb7keSZxJ3F7i560/CU2Dtxdw9oLZ/IZUMJQA=
=VOFP
-----END PGP SIGNATURE-----


?