build: Replace `which` with `command -v`
PATCH 1/1 build: Replace `which` with `command -v`
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.
--- xen/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/Makefile +2 -2
@@ -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
Signature · 1 line
Anthony PERARD
Quoted 15 lines · Anthony PERARD
The
whichcommand is not standard, may not exist on the build host, or may not behave as expected. It is recommanded to usecommand -vto 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 <[email protected]>--- xen/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/Makefile +0
-0
xen/Makefile export XEN_BUILD_HOST := $(shell hostname) · line 30
Quoted 8 lines
xen/Makefile +2
-2@@ -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
Quoted 4 lines · Anthony PERARD
The
whichcommand is not standard, may not exist on the build host, or may not behave as expected. It is recommanded to usecommand -vto 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
Quoted 6 lines · Anthony PERARD
The
whichcommand is not standard, may not exist on the build host, or may not behave as expected. It is recommanded to usecommand -vto 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 <[email protected]>
This fixes build on fedora 39:
Quoted 23 lines
--- xen/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/Makefile +2
-2@@ -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 ?= checkpolicySignature · 1 line
Anthony PERARD
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab