public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: tlaronde@polynum.com
To: Pedro Falcato <pedro.falcato@gmail.com>
Cc: Rebecca Cran <quic_rcran@quicinc.com>, devel@edk2.groups.io
Subject: Re: [edk2-devel] edksetup.sh: fix for non POSIX whereis(1)
Date: Tue, 22 Nov 2022 18:07:29 +0100	[thread overview]
Message-ID: <Y30B0QiQZQUCKDhH@polynum.com> (raw)
In-Reply-To: <CAKbZUD2c8vFaoeuZziVho5+fRH9mMNf49u_Bt_Qn_FppVh9rGA@mail.gmail.com>

Le Tue, Nov 22, 2022 at 04:31:14PM +0000, Pedro Falcato a écrit :
> On Tue, Nov 22, 2022 at 4:26 PM <tlaronde@polynum.com> wrote:
> 
> > Le Tue, Nov 22, 2022 at 08:40:30AM -0700, Rebecca Cran a écrit :
> > > On 11/21/22 15:22, Pedro Falcato wrote:
> > >
> > > > I kind of dislike your solution. Does NetBSD ship /bin/which by
> > default?
> > > > I think replacing whereis with "which -a" would be a lot better.
> > > > I don't think there's a 100% standard way to do this in POSIX, as which
> > > > isn't POSIX either, and your solution seems... hacky?
> > >
> > >
> > > "command" seems to be the POSIX way to do this?
> > > https://pubs.opengroup.org/onlinepubs/9699919799/
> > >
> > > Though "whereis python3" shows the following on my system:
> > >
> > > python3: /usr/bin/python3.9-config /usr/bin/python3.9 /usr/bin/python3
> > > /usr/lib/python3.9 /usr/lib/python3 /etc/python3.9 /etc/python3
> > > /usr/local/lib/python3.9 /usr/include/python3.9 /usr/share/python3
> > > /usr/share/man/man1/python3.1.gz
> > >
> > > "which -a python3" returns:
> > >
> > > /usr/bin/python3
> > > /bin/python3
> > >
> > > And "command -p -v" returns:
> > >
> > > /bin/python3
> > >
> > > I don't know if we need all the results from "whereis"?
> >
> > The problem is when one does not know which exact version of python
> > is here and how, exactly, the command is named.
> >
> > whereis(1) returns whatever command with python3 as prefix, while
> > command or "which -a" will return only exactly python3. If, on the
> > system, python is fully version qualified (as is the case with
> > pkgsrc, the opt packages framework, used on NetBSD):
> >
> > which -a python3
> >
> > will return nothing, since, it is python3.9 for example on the OS.
> >
> 
> Sorry, what? This sounds so broken. How can a script shebang ever work?
> 
> For Sane(tm) systems, I propose command -v python3 + $(command -v python3)
> -c 'import sys; print(sys.version.split(" ")[0])',
> which gives us the path to the Python 3 interpreter + the path in a
> relatively easy, simple way.
> I think this could work mostly everywhere but apparently NetBSD since you
> don't provide python3? Which makes little sense in my head.
> 

NetBSD (as other OSes) does not provide python in base. It is available
as an add-on. And the add-on framework on NetBSD allows to install
several versions of Python (since there seems to be so many of them...)
and in order to do that, the binary is not called "python", neither
"python3" but "python3.9" or "python3.10". And since one can
concurrently install different versions, there is no symbolic or
hardlink python3 to a preferred python 3 series binary.

As I have already said, edk2setup.sh allows to manipulate the
environment and, for example, allows to set explicitely the env var
PYTHON_COMMAND. So I know how to circumvent the problem. 

But, since the script uses whereis(1), the Linux version, that does
take "python3" as a prefix and searches for "python3*" (in more than the
directories in PATH in fact), I have simply made so that the current
behavior, intended(?), work on NetBSD too or on any system without
whereis(1) or with a whereis(1) that does not behave as the Linux one.

If you want to nuke whereis and use a POSIX2 utility instead, I'm
perfectly fine: I will have to make other adjustements for NetBSD (not
in edk2setup.sh) and I'm writing documentation on how-to, so I can
circumvent this elsewhere.
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C

      reply	other threads:[~2022-11-22 17:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21 13:09 edksetup.sh: fix for non POSIX whereis(1) tlaronde
2022-11-21 22:22 ` [edk2-devel] " Pedro Falcato
2022-11-22  8:14   ` tlaronde
2022-11-22 15:40   ` Rebecca Cran
2022-11-22 16:22     ` Pedro Falcato
2022-11-22 16:26     ` tlaronde
2022-11-22 16:31       ` Pedro Falcato
2022-11-22 17:07         ` tlaronde [this message]

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-list 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=Y30B0QiQZQUCKDhH@polynum.com \
    --to=devel@edk2.groups.io \
    /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