Eli Schwartz <[email protected]> writes: > 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???
Could you add tests too please? The change LGTM but give parona a chance to comment on it as he'd mentioned it to me as well. Ionen may or may not have comments too as he suffered with this before in ffmpeg, I think. > > Signed-off-by: Eli Schwartz <[email protected]> > --- > eclass/flag-o-matic.eclass | 23 +++++++++++++++++++---- > 1 file changed, 19 insertions(+), 4 deletions(-) > > diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass > index 1c9abe1280b6..f512702d0800 100644 > --- a/eclass/flag-o-matic.eclass > +++ b/eclass/flag-o-matic.eclass > @@ -1,4 +1,4 @@ > -# Copyright 1999-2025 Gentoo Authors > +# Copyright 1999-2026 Gentoo Authors > # Distributed under the terms of the GNU General Public License v2 > > # @ECLASS: flag-o-matic.eclass > @@ -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] ]]; 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
signature.asc
Description: PGP signature
