support/scripts: move merged-usr errors message into check-merged-usr.sh

By moving the loop over the overlays into the script, we can generate
better error messages about how and why a skeleton or a specific overlay
is improperly setup for merged-usr.

We can also now rely on its exit code to decide whether the skeleton or
the overlays are properly setup, rather than stash the stdout/stderr to
a Makefile variable and test the emptiness thereof.

Introduce a --type option to pass the type of root to verify, for better
error reporting. This will incidentally be usefull in a future commit,
when we need to take different actions based on whether the root is a
skeleton or an overlay.

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Romain Naour <romain.naour@smile.fr>
This commit is contained in:
Yann E. MORIN
2025-09-01 11:01:16 +02:00
committed by Romain Naour
parent 74b29f34ba
commit 1187c34d88
3 changed files with 64 additions and 37 deletions
+4 -11
View File
@@ -782,17 +782,10 @@ endif
# For a merged /usr, ensure that /lib, /bin and /sbin and their /usr
# counterparts are appropriately setup as symlinks ones to the others.
ifeq ($(BR2_ROOTFS_MERGED_USR),y)
$(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \
@$(call MESSAGE,"Sanity check in overlay $(d)")$(sep) \
$(Q)not_merged_dirs="$$(support/scripts/check-merged-usr.sh $(d))"; \
test -n "$$not_merged_dirs" && { \
echo "ERROR: The overlay in $(d) is not" \
"using a merged /usr for the following directories:" \
$$not_merged_dirs; \
exit 1; \
} || true$(sep))
@$(call MESSAGE,"Sanity check in overlays $(call qstrip,$(BR2_ROOTFS_OVERLAY))")
support/scripts/check-merged-usr.sh \
--type overlay \
$(call qstrip,$(BR2_ROOTFS_OVERLAY))
endif # merged /usr
$(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \
+9 -12
View File
@@ -26,17 +26,16 @@ endif
# For a merged /usr, ensure that /lib, /bin and /sbin and their /usr
# counterparts are appropriately setup as symlinks ones to the others.
ifeq ($(BR2_ROOTFS_MERGED_USR),y)
SKELETON_CUSTOM_NOT_MERGED_USR_DIRS = \
$(shell support/scripts/check-merged-usr.sh $(SKELETON_CUSTOM_PATH))
define SKELETON_CUSTOM_NOT_MERGED_USR_DIRS
support/scripts/check-merged-usr.sh \
--type skeleton \
$(SKELETON_CUSTOM_PATH)
endef
endif # merged /usr
ifeq ($(BR2_PACKAGE_SKELETON_CUSTOM)$(BR_BUILDING),yy)
ifneq ($(SKELETON_CUSTOM_NOT_MERGED_USR_DIRS),)
$(error The custom skeleton in $(SKELETON_CUSTOM_PATH) is not \
using a merged /usr for the following directories: \
$(SKELETON_CUSTOM_NOT_MERGED_USR_DIRS))
endif
endif
define SKELETON_CUSTOM_CONFIGURE_CMDS
$(SKELETON_CUSTOM_NOT_MERGED_USR_DIRS)
endef
# The target-dir-warning file and the lib{32,64} symlinks are the only
# things we customise in the custom skeleton.
@@ -49,9 +48,7 @@ define SKELETON_CUSTOM_INSTALL_TARGET_CMDS
endef
# For the staging dir, we don't really care what we install, but we
# need the /lib and /usr/lib appropriately setup. Since we ensure,
# above, that they are correct in the skeleton, we can simply copy the
# skeleton to staging.
# need the /lib and /usr/lib appropriately setup.
define SKELETON_CUSTOM_INSTALL_STAGING_CMDS
$(call SYSTEM_RSYNC,$(SKELETON_CUSTOM_PATH),$(STAGING_DIR))
$(call SYSTEM_USR_SYMLINKS_OR_DIRS,$(STAGING_DIR))
+51 -14
View File
@@ -11,16 +11,48 @@
# /usr/sbin/
#
# Input:
# $1: the root directory (skeleton, overlay) to check
# --type TYPE the type of root to check: 'skeleton' or 'overlay'
# $*: the root directories (skeleton, overlays) to check
# Output:
# stdout: the list of non-compliant paths (empty if compliant).
# stdout: the list of non-compliant paths (empty if compliant).
# Exit code:
# 0: in case of success (stdout will be empty)
# !0: if any path is improperly merged
# 0: in case of success (stdout will be empty)
# !0: if any path is improperly merged
#
# The directory to check for merged-usr
root="${1}"
opts="type:"
ARGS="$(getopt -n check-merged -o "" -l "${opts}" -- "${@}")" || exit 1
eval set -- "${ARGS}"
type=
while :; do
case "${1}" in
(--type)
type="${2}"
shift 2
;;
(--)
shift
break
;;
esac
done
report_error() {
local type="${1}"
local root="${2}"
local fmt="${3}"
shift 3
if ${first}; then
printf "The %s in %s is not properly setup:\n" \
"${type}" "${root}"
fi
first=false
# shellcheck disable=SC2059 # fmt *is* a format string
printf " - ${fmt}" "${@}"
is_success=false
}
# Extract the inode numbers for all of those directories. In case any is
# a symlink, we want to get the inode of the pointed-to directory, so we
@@ -42,19 +74,24 @@ is_valid_merged() {
}
test_merged() {
local root="${1}"
local dir1="${2}"
local dir2="${3}"
local type="${1}"
local root="${2}"
local dir1="${3}"
local dir2="${4}"
if ! is_valid_merged "${root}" "${dir1}" "${dir2}"; then
printf '%s\n' "${dir1}"
is_success=false
report_error "${type}" "${root}" \
'%s should be missing, or be a relative symlink to %s\n' \
"${dir1}" "${dir2}"
fi
}
is_success=true
test_merged "${root}" "/lib" "/usr/lib"
test_merged "${root}" "/bin" "/usr/bin"
test_merged "${root}" "/sbin" "/usr/sbin"
for root; do
first=true
test_merged "${type}" "${root}" "/lib" "/usr/lib"
test_merged "${type}" "${root}" "/bin" "/usr/bin"
test_merged "${type}" "${root}" "/sbin" "/usr/sbin"
done
${is_success}