From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 0A1BC1381F1 for ; Sun, 15 May 2016 15:59:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C3BBB234013; Sun, 15 May 2016 15:59:42 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C93A923400E for ; Sun, 15 May 2016 15:59:41 +0000 (UTC) Received: from [10.199.131.92] (public-gprs386358.centertel.pl [37.47.140.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id E3C56340C30; Sun, 15 May 2016 15:59:38 +0000 (UTC) User-Agent: K-9 Mail for Android In-Reply-To: <1463319089-18877-1-git-send-email-dev.rindeal@gmail.com> References: <1463319089-18877-1-git-send-email-dev.rindeal@gmail.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Subject: Re: [gentoo-dev] [PATCH] flag-o-matic.eclass: bugfix for get-flag() From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= Date: Sun, 15 May 2016 17:59:24 +0200 To: gentoo-dev@lists.gentoo.org,Jan Chren CC: Jan Chren Message-ID: <65DB30FD-2B31-45B6-B34D-021544C0E9D6@gentoo.org> X-Archives-Salt: ba8285eb-21f4-4908-9185-c63b2662a375 X-Archives-Hash: 575063ae19690fdce636f07645476973 Dnia 15 maja 2016 15:31:29 CEST, Jan Chren 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)