From c28c9383afeea102f43aa40ea466bba4e32516bf Mon Sep 17 00:00:00 2001 From: Maxime Devos 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(-) 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