summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-08-11 17:17:45 +0200
committerMichał Górny <mgorny@gentoo.org>2017-08-25 15:53:15 +0200
commitae9870d9f6b1394ede86176443770b36d7e60ac1 (patch)
tree5f533b8f8651d035ac7cb0f0a6111148dfc13533 /eclass
parentflag-o-matic.eclass: test-flag-PROG, refactor to reduce duplication (diff)
downloadgentoo-ae9870d9f6b1394ede86176443770b36d7e60ac1.tar.gz
gentoo-ae9870d9f6b1394ede86176443770b36d7e60ac1.tar.bz2
gentoo-ae9870d9f6b1394ede86176443770b36d7e60ac1.zip
flag-o-matic.eclass: test-flag-PROG, ignore unused args in clang
By default, clang considers unused arguments as error when -Werror is used. Since flag tests are performed without linking, this causes all tests for linker flags to fail inadvertently and all those flags are stripped as a result. While the correctness of passing unused flags is doubtful, silently stripping them in a few random packages is certainly not the solution to the problem, and also makes the results differ between gcc and clang. To account for that, use clang's -Qunused-arguments option to silence unused argument warnings. To avoid wasting time on testing the compiler, just try passing -Qunused-arguments every time a flag check fails. If clang is not used, the additional call will fail just the same as the previous one (either because of the original flag or because of -Qunused-arguments), so the result will be the same.
Diffstat (limited to 'eclass')
-rw-r--r--eclass/flag-o-matic.eclass9
-rwxr-xr-xeclass/tests/flag-o-matic.sh5
2 files changed, 13 insertions, 1 deletions
diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
index 0393a30b74c3..79866e04a483 100644
--- a/eclass/flag-o-matic.eclass
+++ b/eclass/flag-o-matic.eclass
@@ -441,7 +441,14 @@ test-flag-PROG() {
cmdline+=( "${flag}" -c -o /dev/null /dev/null )
fi
- "${cmdline[@]}" </dev/null &>/dev/null
+ if ! "${cmdline[@]}" </dev/null &>/dev/null; then
+ # -Werror makes clang bail out on unused arguments as well;
+ # try to add -Qunused-arguments to work-around that
+ # other compilers don't support it but then, it's failure like
+ # any other
+ cmdline+=( -Qunused-arguments )
+ "${cmdline[@]}" </dev/null &>/dev/null
+ fi
}
# @FUNCTION: test-flag-CC
diff --git a/eclass/tests/flag-o-matic.sh b/eclass/tests/flag-o-matic.sh
index 92c68b82c3c9..5e7ee354bf33 100755
--- a/eclass/tests/flag-o-matic.sh
+++ b/eclass/tests/flag-o-matic.sh
@@ -143,6 +143,11 @@ tbegin "test-flags-CC (gcc-valid but clang-invalid flags)"
out=$(CC=clang test-flags-CC -finline-limit=1200)
[[ $? -ne 0 && -z ${out} ]]
ftend
+
+tbegin "test-flags-CC (unused flags w/clang)"
+out=$(CC=clang test-flags-CC -Wl,-O1)
+[[ $? -eq 0 && ${out} == "-Wl,-O1" ]]
+ftend
fi
texit