prereq-build: allow host command symlinks to update
authorMichael Pratt <mcpratt@pm.me>
Sun, 22 May 2022 10:10:56 +0000 (06:10 -0400)
committerPetr Štetiar <ynezz@true.cz>
Sun, 21 May 2023 17:39:22 +0000 (19:39 +0200)
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 <mcpratt@pm.me>
include/prereq.mk

index d34539ec3043f7c00d5dca9abd11cde883574b5c..89660d323d9b82858ffda8498255522ed84b7aaa 100644 (file)
@@ -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; \