From: Michael Pratt Date: Sun, 22 May 2022 10:10:56 +0000 (-0400) Subject: prereq-build: allow host command symlinks to update X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f75204036c;p=openwrt%2Fstaging%2Fsvanheule.git prereq-build: allow host command symlinks to update This makes the prereq stage update the symlinks installed into staging_dir/host/bin by rearrainging the way they are verified. Before, seeing or installing a symlink would result in a successful exit code, and not installing a symlink would result is a failed exit code. However, that is not able to account for the difference between existing good and bad links, or whether the link would be the same if it was reinstalled, because the check can match the program to a different path. Instead, let a success exit code represent identifying an existing symlink as exactly the same as what would be installed if it did not exist, and let a fail exit code represent needing to install the symlink or not having a match to the check criteria. The failing exit code is caught by a new second attempt for all of the check-* targets which will then indicate to the user that there was an update by having a success exit code when the check is run again and the link is the same. When there is nothing to update, the checks will run only once. This relies on the ls command to be POSIX-conformant with long format: "path/to/link -> target/of/link" Also, make sure the symlink is executable, not just a file, and the directory only needs to be created once. Fixes: #12610 Signed-off-by: Michael Pratt --- diff --git a/include/prereq.mk b/include/prereq.mk index d34539ec30..89660d323d 100644 --- a/include/prereq.mk +++ b/include/prereq.mk @@ -30,6 +30,8 @@ define Require printf "Checking '$(1)'... " if $(NO_TRACE_MAKE) -f $(firstword $(MAKEFILE_LIST)) check-$(1) >/dev/null 2>/dev/null; then \ echo 'ok.'; \ + elif $(NO_TRACE_MAKE) -f $(firstword $(MAKEFILE_LIST)) check-$(1) >/dev/null 2>/dev/null; then \ + echo 'updated.'; \ else \ echo 'failed.'; \ echo "$(PKG_NAME): $(strip $(2))" >> $(TMP_DIR)/.prereq-error; \ @@ -107,7 +109,7 @@ endef # 3+: candidates define SetupHostCommand define Require/$(1) - [ -f "$(STAGING_DIR_HOST)/bin/$(strip $(1))" ] && exit 0; \ + mkdir -p "$(STAGING_DIR_HOST)/bin"; \ for cmd in $(call QuoteHostCommand,$(3)) $(call QuoteHostCommand,$(4)) \ $(call QuoteHostCommand,$(5)) $(call QuoteHostCommand,$(6)) \ $(call QuoteHostCommand,$(7)) $(call QuoteHostCommand,$(8)) \ @@ -117,9 +119,13 @@ define SetupHostCommand bin="$$$$$$$$(PATH="$(subst $(space),:,$(filter-out $(STAGING_DIR_HOST)/%,$(subst :,$(space),$(PATH))))" \ command -v "$$$$$$$${cmd%% *}")"; \ if [ -x "$$$$$$$$bin" ] && eval "$$$$$$$$cmd" >/dev/null 2>/dev/null; then \ - mkdir -p "$(STAGING_DIR_HOST)/bin"; \ + case "$$$$$$$$(ls -dl -- $(STAGING_DIR_HOST)/bin/$(strip $(1)))" in \ + *" -> $$$$$$$$bin"*) \ + [ -x "$(STAGING_DIR_HOST)/bin/$(strip $(1))" ] && exit 0 \ + ;; \ + esac; \ ln -sf "$$$$$$$$bin" "$(STAGING_DIR_HOST)/bin/$(strip $(1))"; \ - exit 0; \ + exit 1; \ fi; \ fi; \ done; \