[PATCH] build: replace which with Bash command built-in

Adrian Schmutzler mail at adrianschmutzler.de
Tue Dec 22 07:20:37 EST 2020


Hi,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces at lists.openwrt.org]
> On Behalf Of Petr Štetiar
> Sent: Dienstag, 22. Dezember 2020 10:47
> To: openwrt-devel at lists.openwrt.org
> Cc: Petr Štetiar <ynezz at true.cz>
> Subject: [PATCH] build: replace which with Bash command built-in
> 
> `which` utility is not shipped by default for example on recent Arch Linux and
> then any steps relying on its presence fails, like for example following
> Python3 prereq build check:
> 
>  $ python3 --version
>  Python 3.9.1
> 
>  $ make
>  /bin/sh: line 1: which: command not found
>  /bin/sh: line 1: which: command not found
>  /bin/sh: line 1: which: command not found  ...
>  Checking 'python3'... failed.
>  ...
> 
> Fix this by switching to Bash builtin `command` which should provide same
> functionality.
> 
> Fixes: FS#3525
> Signed-off-by: Petr Štetiar <ynezz at true.cz>
> ---
> 
> Other option is to check for `which` util presence in prereq-build and adding
> `which` to the list of required host build utils.
> 
>  Makefile          | 3 ++-
>  include/cmake.mk  | 2 +-
>  include/prereq.mk | 4 ++--
>  3 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 24f5955c9066..f4519e00d28d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -18,7 +18,8 @@ $(if $(findstring $(space),$(TOPDIR)),$(error ERROR: The
> path to the OpenWrt dir
> 
>  world:
> 
> -DISTRO_PKG_CONFIG:=$(shell which -a pkg-config | grep -E '\/usr' | head -n
> 1)
> +WHICH:=command -pv
> +DISTRO_PKG_CONFIG:=$(shell $(WHICH) pkg-config | grep -E '\/usr' | head
> +-n 1)

Since we have to replace 'which' everywhere anyway, I'd personally prefer to have/see the actual command in place.
$(WHICH) implies that 'which' is still used, and I don't see a reason to not just use command -pv/-v directly so everybody knows what's happening.

Best

Adrian

>  export PATH:=$(TOPDIR)/staging_dir/host/bin:$(PATH)
> 
>  ifneq ($(OPENWRT_BUILD),1)
> diff --git a/include/cmake.mk b/include/cmake.mk index
> 0a20530a16fe..ff00b5e779b5 100644
> --- a/include/cmake.mk
> +++ b/include/cmake.mk
> @@ -15,7 +15,7 @@ MAKE_PATH = $(firstword $(CMAKE_BINARY_SUBDIR)
> .)  ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
>    cmake_tool=$(TOOLCHAIN_DIR)/bin/$(1)
>  else
> -  cmake_tool=$(shell which $(1))
> +  cmake_tool=$(shell $(WHICH) $(1))
>  endif
> 
>  ifeq ($(CONFIG_CCACHE),)
> diff --git a/include/prereq.mk b/include/prereq.mk index
> 83ac21242c65..a6ee2bb637f5 100644
> --- a/include/prereq.mk
> +++ b/include/prereq.mk
> @@ -52,7 +52,7 @@ endef
> 
>  define RequireCommand
>    define Require/$(1)
> -    which $(1)
> +    $(WHICH) $(1)
>    endef
> 
>    $$(eval $$(call Require,$(1),$(2)))
> @@ -106,7 +106,7 @@ define SetupHostCommand
>  	           $(call QuoteHostCommand,$(11)) $(call
> QuoteHostCommand,$(12)); do \
>  		if [ -n "$$$$$$$$cmd" ]; then \
>  			bin="$$$$$$$$(PATH="$(subst $(space),:,$(filter-out
> $(STAGING_DIR_HOST)/%,$(subst :,$(space),$(PATH))))" \
> -				which "$$$$$$$${cmd%% *}")"; \
> +				$(WHICH) "$$$$$$$${cmd%% *}")"; \
>  			if [ -x "$$$$$$$$bin" ] && eval "$$$$$$$$cmd"
> >/dev/null 2>/dev/null; then \
>  				mkdir -p "$(STAGING_DIR_HOST)/bin"; \
>  				ln -sf "$$$$$$$$bin"
> "$(STAGING_DIR_HOST)/bin/$(strip $(1))"; \
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20201222/f6472c0a/attachment.sig>


More information about the openwrt-devel mailing list