public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org,Jan Chren <dev.rindeal@gmail.com>
Cc: Jan Chren <dev.rindeal@gmail.com>
Subject: Re: [gentoo-dev] [PATCH] flag-o-matic.eclass: bugfix for get-flag()
Date: Sun, 15 May 2016 17:59:24 +0200	[thread overview]
Message-ID: <65DB30FD-2B31-45B6-B34D-021544C0E9D6@gentoo.org> (raw)
In-Reply-To: <1463319089-18877-1-git-send-email-dev.rindeal@gmail.com>

Dnia 15 maja 2016 15:31:29 CEST, Jan Chren <dev.rindeal@gmail.com> napisał(a):
>- fix case:
>  - `CFLAGS='-O1 -O2'`
>  - `get-flag '-O*'`
>  - before `-O1`
>  - now `-O2`
>- fix case:
>  - `CFLAGS='-W1,-O1'`
>  - `get-flag '-O*'`
>  - before `-W1,O1`
>  - now return 1
>
>`get-flag march` == "i686" syntax still works.

Could you add appropriate test cases, in the tests subdirectory?

>---
> eclass/flag-o-matic.eclass | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
>diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
>index e0b19e9..f670320 100644
>--- a/eclass/flag-o-matic.eclass
>+++ b/eclass/flag-o-matic.eclass
>@@ -535,7 +535,7 @@ strip-unsupported-flags() {
> # @DESCRIPTION:
> # Find and echo the value for a particular flag.  Accepts shell globs.
> get-flag() {
>-	local f var findflag="$1"
>+	local var findflag="${1}"
> 
> 	# this code looks a little flaky but seems to work for
> 	# everything we want ...
>@@ -543,11 +543,16 @@ get-flag() {
> 	# `get-flag -march` == "-march=i686"
> 	# `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}=}"
>+		# reverse loop
>+		set -- ${!var}
>+		local i=$#

You are using $ with and without braces inconsistently. Please stick to one form.

>+		while [ $i -gt 0 ] ; do

Please use [[ ]] for conditionals. It has some nice bash magic that makes them whitespace-safe.

>+			local f="${!i}"
>+			if [ "${f#-${findflag#-}}" != "${f}" ] ; then

I know the original code sucked as well but could you replace this with more readable [[ ${f} == -${findflag#-}* ]] or alike (note: not tested).

>+				printf "%s\n" "${f#-${findflag}=}"

It may be a good idea to add a short explanation why you can't use echo here, as a comment.

> 				return 0
> 			fi
>+			((i--))
> 		done
> 	done
> 	return 1


-- 
Best regards,
Michał Górny (by phone)


  reply	other threads:[~2016-05-15 15:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-15 13:31 [gentoo-dev] [PATCH] flag-o-matic.eclass: bugfix for get-flag() Jan Chren
2016-05-15 15:59 ` Michał Górny [this message]
2016-05-15 19:35   ` rindeal
2016-05-15 19:41     ` Michał Górny
2016-05-15 20:19       ` rindeal
2016-05-15 23:23     ` Ulrich Mueller
2016-05-16 12:17       ` rindeal
2016-05-20  3:15         ` Mike Frysinger
2016-06-05 12:13         ` rindeal
2016-05-16  6:23     ` [gentoo-dev] " Ryan Hill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=65DB30FD-2B31-45B6-B34D-021544C0E9D6@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=dev.rindeal@gmail.com \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox