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 C224E138C9D for ; Mon, 1 Jun 2015 17:25:30 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B1AA9E0932; Mon, 1 Jun 2015 17:25:27 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 220DBE08F5 for ; Mon, 1 Jun 2015 17:25:27 +0000 (UTC) Received: from vapier (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with SMTP id D0829340831 for ; Mon, 1 Jun 2015 17:25:25 +0000 (UTC) Date: Mon, 1 Jun 2015 13:25:24 -0400 From: Mike Frysinger To: gentoo-portage-dev@lists.gentoo.org Subject: Re: [gentoo-portage-dev] [PATCH] make PORTAGE_BIN_PATH settings relocatable Message-ID: <20150601172524.GU4496@vapier> Mail-Followup-To: gentoo-portage-dev@lists.gentoo.org References: <1433140493-3288-1-git-send-email-vapier@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="kM/PxlMMHsUUNZZW" Content-Disposition: inline In-Reply-To: <1433140493-3288-1-git-send-email-vapier@gentoo.org> X-Archives-Salt: c917e5fa-6043-4fbe-b588-5a590214424d X-Archives-Hash: e5f1abdeb77ff08432ffddb7b94f4718 --kM/PxlMMHsUUNZZW Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 01 Jun 2015 02:34, Mike Frysinger wrote: > -source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh > +if [[ -z ${PORTAGE_BIN_PATH} ]] ; then > + PORTAGE_BIN_PATH=3D$(dirname "$(dirname "$(readlink -f "$0")")") > +fi > +source "${PORTAGE_BIN_PATH}"/isolated-functions.sh for people who don't want to scan this whole thing, basically every file ge= ts a=20 change like this. two things to note: (1) i did not retain the ${VAR:-def} form because bash evaluates the defaul= t=20 value even if it doesn't use it. so when you do something like: VAR=3Dval echo "${VAR:-$(rm -rf /some/path)}" it will first run the `rm` and then expand val for the echo. the form i us= ed=20 thus avoids the runtime overhead of doing dirname/readlink unnecessarily. (2) i avoided the bash string functions like ${VAR%/*} because it splits up= =20 into multiple statements and is not as readable imo: PORTAGE_BIN_PATH=3D$(readlink -f "$0") PORTAGE_BIN_PATH=3D${PORTAGE_BIN_PATH%/*} PORTAGE_BIN_PATH=3D${PORTAGE_BIN_PATH%/*} or even worse: PORTAGE_BIN_PATH=3D$(readlink -f "$0"); PORTAGE_BIN_PATH=3D${PORTAGE_BIN_P= ATH%/*}; PORTAGE_BIN_PATH=3D${PORTAGE_BIN_PATH%/*} or also bad imo as it's still not that readable: p=3D$(readlink -f "$0"); p=3D${p%/*}; p=3D${p%/*} PORTAGE_BIN_PATH=3D${p} the dirname version might be a bit slower, but i think that's acceptable=20 considering this is the fallback case that should rarely be run (as the env= =20 var should normally be set). alternative crazy ideas: (a) just throw an error and exit when PORTAGE_BIN_PATH is not set ...=20 considering the current portage code points to a path where it is no longer= =20 installed, maybe that's ok ? the recent changes to make portage install co= pies for each python version is what broke it i think. (b) add a tool alongside it that can be `eval`-ed, although you'd still nee= d to=20 do something like: if [[ -z ${PORTAGE_BIN_PATH} ]] ; then eval $("$(dirname "$(readlink -f "$0")")/some-tool") fi and i don't think that's an improvement relative to my patch (deal with quo= ting=20 bs and such). (c) convert most things to python and use relative module imports to get at= the=20 bootstrap module. then that one would hold all the logic. (d) some other alternative ? -mike --kM/PxlMMHsUUNZZW Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJVbJWEAAoJEEFjO5/oN/WB0uoQANI5pNdtFqJBnVqw5Myd/369 hIjVgq04kfMIeiiMeD6UgFrMkRJZmUQKP3T1vR0dWlc40muwZqdIU1J47YBMUEAE asLk8ko0AnyxJ9SXvvbO4iwgrT7BOU6xQ49QH2uvYT/fvsvUgLpD2i0CMfah5MTT uw7Xi2nrzAKCY0VfLxQ7NpWx3rxbLJA8i8LRNnP+Mtad7wyv4SRiNRPmnssiUawO MwOoURJNbRV3t3Bxd9yXGHrwujOnO0ydi0u4/PS5ivqYGkRLf03yDvCO4OrNoYGi 9rCZHfx7morFKfAyIhVOREE+kaPFZJc1VdwxqSXx9+v4Ohwy/OkKBWGCqxvj2S1+ aZljsRJ/d3FIgP9VNbWr9zd9RsJ4FDIQT02fr3hMerZGMWSbRTrTGB9aEq55aVGZ Heiru7wT+R3FVVPDXBRO1P5aA0IQSF3H4w263MVXyzOoBlrFONpC8R/bB/Gpy7x0 6Mwfvhzb1D5vE+iQv+ihvVwNxjdFYwxEHR3dAaKyehj2NTVD93ZQbU98jLzOYvq7 Y7dfG/fWzxph3iSRiue+BJkpa0cu2hHnhxAORIt/r3sw4JkOZg2AFsTjMZCRt3LE ETot+QsC2PtJszoVxHUeahDNbHlId40xkxgx/JP7w9aQN7VVMXhAmqnt0kBY9jsS e9Zs9yQwRwmOrDgjrBq3 =TElZ -----END PGP SIGNATURE----- --kM/PxlMMHsUUNZZW--