diff mbox series

[XEN] build: Replace `which` with `command -v`

Message ID 20240214143411.37957-1-anthony.perard@citrix.com (mailing list archive)
State Superseded
Headers show
Series [XEN] build: Replace `which` with `command -v` | expand

Commit Message

Anthony PERARD Feb. 14, 2024, 2:34 p.m. UTC
The `which` command is not standard, may not exist on the build host,
or may not behave as expected. It is recommanded to use `command -v`
to find out if a command exist and have it's path, and it's part of a
POSIX shell standard.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 xen/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jan Beulich Feb. 14, 2024, 3:12 p.m. UTC | #1
On 14.02.2024 15:34, Anthony PERARD wrote:
> The `which` command is not standard, may not exist on the build host,
> or may not behave as expected. It is recommanded to use `command -v`
> to find out if a command exist and have it's path, and it's part of a
> POSIX shell standard.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>  xen/Makefile | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/Makefile b/xen/Makefile
> index 21832d6402..767e47d6c7 100644
> --- a/xen/Makefile
> +++ b/xen/Makefile
> @@ -25,8 +25,8 @@ export XEN_BUILD_HOST	:= $(shell hostname)
>  endif
>  
>  # Best effort attempt to find a python interpreter, defaulting to Python 3 if
> -# available.  Fall back to just `python` if `which` is nowhere to be found.
> -PYTHON_INTERPRETER	:= $(word 1,$(shell which python3 python python2 2>/dev/null) python)
> +# available.  Fall back to just `python`.
> +PYTHON_INTERPRETER	:= $(word 1,$(shell command -v python3 || command -v python || command -v python2) python)
>  export PYTHON		?= $(PYTHON_INTERPRETER)

Shouldn't we go farther with this and also switch the use in
xen/build.mk (which looks to be the only other one I can find under
xen/ and config/)?

Jan
Jan Beulich Feb. 14, 2024, 3:21 p.m. UTC | #2
On 14.02.2024 15:34, Anthony PERARD wrote:
> The `which` command is not standard, may not exist on the build host,
> or may not behave as expected. It is recommanded to use `command -v`
> to find out if a command exist and have it's path, and it's part of a
> POSIX shell standard.

Just to mention it: It hasn't always been. In IEEE Std 1003.1-2004 it was
still an optional thing. First mention of it being non-optional looks to
be in 1003.1-2008, which is slightly newer than the oldest gcc/binutils
we presently support. Still even on the oldest systems I'm still building
Xen on every once in a while, the command form is supported. So not an
objection, merely a request to be a little more precise in the description
of v2.

Jan
Marek Marczykowski-Górecki Feb. 14, 2024, 3:21 p.m. UTC | #3
On Wed, Feb 14, 2024 at 02:34:11PM +0000, Anthony PERARD wrote:
> The `which` command is not standard, may not exist on the build host,
> or may not behave as expected. It is recommanded to use `command -v`
> to find out if a command exist and have it's path, and it's part of a
> POSIX shell standard.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

This fixes build on fedora 39:

Tested-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>

> ---
>  xen/Makefile | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/Makefile b/xen/Makefile
> index 21832d6402..767e47d6c7 100644
> --- a/xen/Makefile
> +++ b/xen/Makefile
> @@ -25,8 +25,8 @@ export XEN_BUILD_HOST	:= $(shell hostname)
>  endif
>  
>  # Best effort attempt to find a python interpreter, defaulting to Python 3 if
> -# available.  Fall back to just `python` if `which` is nowhere to be found.
> -PYTHON_INTERPRETER	:= $(word 1,$(shell which python3 python python2 2>/dev/null) python)
> +# available.  Fall back to just `python`.
> +PYTHON_INTERPRETER	:= $(word 1,$(shell command -v python3 || command -v python || command -v python2) python)
>  export PYTHON		?= $(PYTHON_INTERPRETER)
>  
>  export CHECKPOLICY	?= checkpolicy
> -- 
> Anthony PERARD
> 
>
diff mbox series

Patch

diff --git a/xen/Makefile b/xen/Makefile
index 21832d6402..767e47d6c7 100644
--- a/xen/Makefile
+++ b/xen/Makefile
@@ -25,8 +25,8 @@  export XEN_BUILD_HOST	:= $(shell hostname)
 endif
 
 # Best effort attempt to find a python interpreter, defaulting to Python 3 if
-# available.  Fall back to just `python` if `which` is nowhere to be found.
-PYTHON_INTERPRETER	:= $(word 1,$(shell which python3 python python2 2>/dev/null) python)
+# available.  Fall back to just `python`.
+PYTHON_INTERPRETER	:= $(word 1,$(shell command -v python3 || command -v python || command -v python2) python)
 export PYTHON		?= $(PYTHON_INTERPRETER)
 
 export CHECKPOLICY	?= checkpolicy