[OpenWrt-Devel] [PATCH] prereq: fixes checks that prefix env vars (ex:git)

Luiz Angelo Daros de Luca luizluca at gmail.com
Sat Mar 5 15:54:54 EST 2016


If a prereq-build command check defines a command env var (ex: MANPAGER=cat git ...)
prereq SetupHostCommand breaks. This is because it looks for the binary using which on
the first space-separated item (which might be the env var definition)

This patch replaces bash substitution by a sed regex that removes both env parameters and
command args.
---
 include/prereq.mk | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/prereq.mk b/include/prereq.mk
index 6cb590e..839b663 100644
--- a/include/prereq.mk
+++ b/include/prereq.mk
@@ -92,8 +92,11 @@ define SetupHostCommand
 	           $(call QuoteHostCommand,$(7)) $(call QuoteHostCommand,$(8)) \
 			   $(call QuoteHostCommand,$(9)); do \
 		if [ -n "$$$$$$$$cmd" ]; then \
+			regex_rm_vars='s/^(\w+=(\['\'\"]']|'\''[^'\'']*'\''|"[^"]*"|[^ ]*(\\ )?)* )*//'; \
+			regex_rm_args='s/[[:space:]].*//'; \
+			regex_clean_cmd="$$$$$$$$regex_rm_vars;$$$$$$$$regex_rm_args"; \
 			bin="$$$$$$$$(PATH="$(subst $(space),:,$(filter-out $(STAGING_DIR_HOST)/%,$(subst :,$(space),$(PATH))))" \
-				which "$$$$$$$${cmd%% *}")"; \
+				which "$$$$$$$$(echo $$$$$$$$cmd | sed -re "$$$$$$$$regex_clean_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))"; \
-- 
2.5.0
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list