mirror of
https://github.com/gentoo-mirror/gentoo.git
synced 2026-09-24 04:59:14 -07:00
flag-o-matic.eclass: make get-flag match whole flags
Existing use implies a desire to: - treat leading "-" as optional - query the value of a "flag" - query the entire arg of a "-flag" or "-flag=" or really anything other than "flag" where CFLAGS has "-flag=*" But unfortunately we also do odd things like match `get-flag -g` to retrieve -grecord-gcc-switches or -fno-gnu-keywords etc. It's a rough substring match and really we want to match flag *names*. It is also a bit awkward to do "-flag=" and then trim off the flag name by hand. Update the algorithm to allow for this. Given it's a big change to usability, require users to opt in to the new algorithm by migrating their ebuilds to EAPI 9 and testing there. They could have been relying on what I called a bug. Some things that will definitely break, but I cannot conceive of why one would do it: - FLAGS="-fno-gnu-keywords"; get-flag -g Gross misuse. - FLAGS="-flto-incremental=/path"; get-flag "-flto-inc*=" omitting the = works fine, what is the goal here??? Acked-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
This commit is contained in:
@@ -853,9 +853,24 @@ get-flag() {
|
||||
# `get-flag march` == "i686"
|
||||
for var in $(all-flag-vars) ; do
|
||||
for f in ${!var} ; do
|
||||
if [ "${f/${findflag}}" != "${f}" ] ; then
|
||||
printf "%s\n" "${f/-${findflag}=}"
|
||||
return 0
|
||||
if [[ ${EAPI} = [78] && -z "${_FLAG_O_MATIC_TESTS_FAKE_EAPI_NINE}" ]]; then
|
||||
if [[ "${f/${findflag}}" != "${f}" ]] ; then
|
||||
printf "%s\n" "${f/-${findflag}=}"
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
# Print RHS for "flag" (no leading "-")
|
||||
if [[ "${f#-${findflag}=}" != "${f}" ]] ; then
|
||||
printf "%s\n" "${f#-${findflag}=}"
|
||||
return 0
|
||||
fi
|
||||
# Print full match for any of:
|
||||
# "-flag" with leading "-"
|
||||
# "flag" without leading "-" that has no unmatched succeeding =value
|
||||
if [[ ${f} = -${findflag#-} || ${f%=*} = ${findflag} ]] ; then
|
||||
printf "%s\n" "${f}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
@@ -151,6 +151,40 @@ out=$(test-flags-CC -finvalid-flag)
|
||||
[[ $? -ne 0 && -z ${out} ]]
|
||||
ftend
|
||||
|
||||
tbegin "get-flag (EAPI 7 substring args)"
|
||||
CFLAGS="-frecord-gcc-switches -g"
|
||||
CXXFLAGS=""
|
||||
LDFLAGS=""
|
||||
out=$(get-flag -g)
|
||||
[[ ${out} = -frecord-gcc-switches ]]
|
||||
ftend
|
||||
|
||||
tbegin "get-flag (EAPI 9 exact match)"
|
||||
CFLAGS="-frecord-gcc-switches -g"
|
||||
CXXFLAGS=""
|
||||
LDFLAGS=""
|
||||
out=$(_FLAG_O_MATIC_TESTS_FAKE_EAPI_NINE=1 get-flag -g)
|
||||
[[ ${out} = -g ]]
|
||||
ftend
|
||||
|
||||
tbegin "get-flag (EAPI 7 values)"
|
||||
CFLAGS="-flto-incremental=/path -flto=4"
|
||||
CXXFLAGS=""
|
||||
LDFLAGS=""
|
||||
out=$(get-flag flto)
|
||||
[[ ${out} = -flto-incremental=/path ]]
|
||||
ftend
|
||||
|
||||
tbegin "get-flag (EAPI 9 values)"
|
||||
CFLAGS="-flto-incremental=/path -flto=4"
|
||||
CXXFLAGS=""
|
||||
LDFLAGS=""
|
||||
out=$(_FLAG_O_MATIC_TESTS_FAKE_EAPI_NINE=1 get-flag flto)
|
||||
[[ ${out} = 4 ]]
|
||||
ftend
|
||||
|
||||
|
||||
|
||||
if type -P clang >/dev/null ; then
|
||||
tbegin "test-flags-CC (valid flags w/clang)"
|
||||
out=$(CC=clang test-flags-CC -O3)
|
||||
|
||||
Reference in New Issue
Block a user