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 37BDF138262 for ; Fri, 20 May 2016 03:16:06 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4D92014283; Fri, 20 May 2016 03:15:58 +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 172B721C04E for ; Fri, 20 May 2016 03:15:57 +0000 (UTC) Received: from vapier.lan (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with SMTP id A85AA340A9C for ; Fri, 20 May 2016 03:15:55 +0000 (UTC) Date: Thu, 19 May 2016 23:15:55 -0400 From: Mike Frysinger To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] [PATCH] flag-o-matic.eclass: bugfix for get-flag() Message-ID: <20160520031555.GW26300@vapier.lan> Mail-Followup-To: gentoo-dev@lists.gentoo.org References: <1463319089-18877-1-git-send-email-dev.rindeal@gmail.com> <65DB30FD-2B31-45B6-B34D-021544C0E9D6@gentoo.org> <22329.1243.790672.211591@a1i15.kph.uni-mainz.de> 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-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="+F2yqQIdYdj7GirX" Content-Disposition: inline In-Reply-To: X-Archives-Salt: 65d74530-46f5-4206-b39d-b65b623aba0f X-Archives-Hash: 003e7e3089995e41cdca100c71e7ed12 --+F2yqQIdYdj7GirX Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On 16 May 2016 14:17, rindeal wrote: > So this is what it looks like now: still missing tests. see eclass/tests/flag-o-matic.sh. > - local f var findflag="$1" > - > - # this code looks a little flaky but seems to work for > - # everything we want ... > - # for example, if CFLAGS="-march=i686": > - # `get-flag -march` == "-march=i686" > - # `get-flag march` == "i686" > + local var pattern="${1}" drop the braces for builtin vars > for var in $(all-flag-vars) ; do > - for f in ${!var} ; do > - if [ "${f/${findflag}}" != "${f}" ] ; then > - printf "%s\n" "${f/-${findflag}=}" > + local i flags=( ${!var} ) > + for (( i=${#flags[@]}-1; i>=0; i-- )) ; do omitting spaces doesn't make code faster, it just makes it unreadable. for (( i = ${#flags[@]} - 1; i >= 0; --i )) ; do stick a comment above this for loop explaining why we walk backwards. > + local needle="-${pattern#-}" # force dash on avoid inline comments and make them complete sentences. # Make sure we anchor to the leading dash. local needle="-${pattern#-}" > + local haystack="${flags[i]%%=*}" # we're comparing flags, not values it's a bit easier to read if you unpack the flag explicitly. local flag=${flags[i]} > + if [[ ${haystack##${needle}} == '' ]] ; then use a -z test instead of comparing to '' -mike --+F2yqQIdYdj7GirX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXPoFrAAoJEEFjO5/oN/WB3V8QANuNko+1A/3H6Jga3sGPHsqo Xyz1bUEZAHrizbYjeco5qHbqv1NlB7DY8wdsfPQl4ivi2uInTvLSa0hbU3YKVC9r ehRh91NoiQEtGaC1EfpDFt/ly3PApExAYXnyxOZ/U4T0dhEGtxXlkbZEVYGpDwsY O8DzPw4N33IdYMJQL28uxU8hvvR1zWSSTzN3w6f3WHb4MEkWJ0GZ5/wAK8KDBiLS M1J8hF91mcrv3j2rwQK3MLz2ElJfDSwPOwinmUH4DBpXxJ1zmztw6aIP8tfBrDej kkUbtXV2X5/qT/7McDwn0g+AZ9cUTR+0k7rpEBMQ1L7eMQwJXdpkDnZ1+jtLFvM3 mVj5WLupUNro4Cv70PiOoCHrp/2/JGhXq7jq8tv3rw6RAynndKvqoYmNR1SvtOEA vX4l/OOCkFwU0XZI4keYusk98TWE2YCK8uTqPq1D/fQzGBs5RT2wRVuYiQtPBkSX RixBlosUF7xlcaE97TFw1qNqABHbnPin+FxuX45kWIl3QxQRw/GFJtbk8t7s9oMR 2q5MnnJxTek9/Wag1kXOWggm3tVWnvNWlPt1Ir+bHrnoTRbtDHIVPhkTXSCWnBxq EeyYS8M9y+oTsIYx9Ge8rjV9uXcWyXYJMBw3026Il2U6+pw3X3RqeYIJpLCGXWem MB21SLVjNSU08i+5U1b/ =xMWX -----END PGP SIGNATURE----- --+F2yqQIdYdj7GirX--