Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/tests/, eclass/
Date: Fri, 25 Aug 2017 13:53:25
Message-Id: 1503669195.ae9870d9f6b1394ede86176443770b36d7e60ac1.mgorny@gentoo
1 commit: ae9870d9f6b1394ede86176443770b36d7e60ac1
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri Aug 11 15:17:45 2017 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Fri Aug 25 13:53:15 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ae9870d9
7
8 flag-o-matic.eclass: test-flag-PROG, ignore unused args in clang
9
10 By default, clang considers unused arguments as error when -Werror is
11 used. Since flag tests are performed without linking, this causes all
12 tests for linker flags to fail inadvertently and all those flags
13 are stripped as a result.
14
15 While the correctness of passing unused flags is doubtful, silently
16 stripping them in a few random packages is certainly not the solution
17 to the problem, and also makes the results differ between gcc and clang.
18 To account for that, use clang's -Qunused-arguments option to silence
19 unused argument warnings.
20
21 To avoid wasting time on testing the compiler, just try passing
22 -Qunused-arguments every time a flag check fails. If clang is not used,
23 the additional call will fail just the same as the previous one (either
24 because of the original flag or because of -Qunused-arguments), so
25 the result will be the same.
26
27 eclass/flag-o-matic.eclass | 9 ++++++++-
28 eclass/tests/flag-o-matic.sh | 5 +++++
29 2 files changed, 13 insertions(+), 1 deletion(-)
30
31 diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
32 index 0393a30b74c..79866e04a48 100644
33 --- a/eclass/flag-o-matic.eclass
34 +++ b/eclass/flag-o-matic.eclass
35 @@ -441,7 +441,14 @@ test-flag-PROG() {
36 cmdline+=( "${flag}" -c -o /dev/null /dev/null )
37 fi
38
39 - "${cmdline[@]}" </dev/null &>/dev/null
40 + if ! "${cmdline[@]}" </dev/null &>/dev/null; then
41 + # -Werror makes clang bail out on unused arguments as well;
42 + # try to add -Qunused-arguments to work-around that
43 + # other compilers don't support it but then, it's failure like
44 + # any other
45 + cmdline+=( -Qunused-arguments )
46 + "${cmdline[@]}" </dev/null &>/dev/null
47 + fi
48 }
49
50 # @FUNCTION: test-flag-CC
51
52 diff --git a/eclass/tests/flag-o-matic.sh b/eclass/tests/flag-o-matic.sh
53 index 92c68b82c3c..5e7ee354bf3 100755
54 --- a/eclass/tests/flag-o-matic.sh
55 +++ b/eclass/tests/flag-o-matic.sh
56 @@ -143,6 +143,11 @@ tbegin "test-flags-CC (gcc-valid but clang-invalid flags)"
57 out=$(CC=clang test-flags-CC -finline-limit=1200)
58 [[ $? -ne 0 && -z ${out} ]]
59 ftend
60 +
61 +tbegin "test-flags-CC (unused flags w/clang)"
62 +out=$(CC=clang test-flags-CC -Wl,-O1)
63 +[[ $? -eq 0 && ${out} == "-Wl,-O1" ]]
64 +ftend
65 fi
66
67 texit