public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: Re: [gentoo-portage-dev] [PATCH] make PORTAGE_BIN_PATH settings relocatable
Date: Mon, 1 Jun 2015 13:25:24 -0400	[thread overview]
Message-ID: <20150601172524.GU4496@vapier> (raw)
In-Reply-To: <1433140493-3288-1-git-send-email-vapier@gentoo.org>

[-- Attachment #1: Type: text/plain, Size: 2266 bytes --]

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=$(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 gets a 
change like this.

two things to note:

(1) i did not retain the ${VAR:-def} form because bash evaluates the default 
value even if it doesn't use it.  so when you do something like:
	VAR=val
	echo "${VAR:-$(rm -rf /some/path)}"
it will first run the `rm` and then expand val for the echo.  the form i used 
thus avoids the runtime overhead of doing dirname/readlink unnecessarily.

(2) i avoided the bash string functions like ${VAR%/*} because it splits up 
into multiple statements and is not as readable imo:
	PORTAGE_BIN_PATH=$(readlink -f "$0")
	PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*}
	PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*}
or even worse:
	PORTAGE_BIN_PATH=$(readlink -f "$0"); PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*}; PORTAGE_BIN_PATH=${PORTAGE_BIN_PATH%/*}
or also bad imo as it's still not that readable:
	p=$(readlink -f "$0"); p=${p%/*}; p=${p%/*}
	PORTAGE_BIN_PATH=${p}
the dirname version might be a bit slower, but i think that's acceptable 
considering this is the fallback case that should rarely be run (as the env 
var should normally be set).

alternative crazy ideas:

(a) just throw an error and exit when PORTAGE_BIN_PATH is not set ... 
considering the current portage code points to a path where it is no longer 
installed, maybe that's ok ?  the recent changes to make portage install copies
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 need to 
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 quoting 
bs and such).

(c) convert most things to python and use relative module imports to get at the 
bootstrap module.  then that one would hold all the logic.

(d) some other alternative ?
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-06-01 17:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01  6:34 [gentoo-portage-dev] [PATCH] make PORTAGE_BIN_PATH settings relocatable Mike Frysinger
2015-06-01 17:25 ` Mike Frysinger [this message]
2015-06-01 18:01   ` Tim Harder
2015-06-02  4:31     ` Mike Frysinger
2015-06-02  5:27       ` Tim Harder
2015-06-01 18:49   ` Zac Medico
2015-06-02 15:34     ` Mike Frysinger
2015-06-10 15:45 ` [gentoo-portage-dev] [PATCH] require PORTAGE_{BIN,PYM}_PATH not be cleared Mike Frysinger
2015-06-10 18:31   ` Zac Medico
2015-06-11  6:44     ` Brian Dolbec
2015-06-11  9:57   ` Mike Frysinger

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=20150601172524.GU4496@vapier \
    --to=vapier@gentoo.org \
    --cc=gentoo-portage-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