genode/tool/depot/mk/content_env_missing_ports.mk
Norman Feske 595660fb84 tool/depot: sanity check for presence of port hash
If a content.mk file wrongly refers to a non-existing directory in a
call of the 'port_dir' function, the 'content_env_missing_ports.mk' gets
stuck while invoking 'cat' without argument, which makes such mistakes
difficult to diagnose. This patch adds a sanity check for the existence
of the port hash file at the specified location before attempting to
'cat' the hash-file content.
2023-04-17 14:48:30 +02:00

70 lines
2.1 KiB
Makefile

#
# \brief Environment for content.mk files when determining missing ports
# \author Martin Stein
# \date 2019-05-12
#
# GENODE_DIR - root directory of the Genode source tree
# CONTRIB_DIR - directory for 3rd-party code
# CONTENT_MK - content.mk file to process
# REP_DIR - repository directory of the content.mk file
# MISSING_PORTS_FILE - file to write the names of missing ports to
# VERBOSE - verbosity
#
#
# Functions for disabling and re-enabling evaluation of $(shell ...)
#
ORIGINAL_SHELL := $(SHELL)
enable_shell = $(eval SHELL:=$(ORIGINAL_SHELL))
disable_shell = $(eval SHELL:=true)
#
# Disable shell calls so the content.mk file will not evaluate something like
# $(shell find $(PORT_DIR) ...) while 'PORT_DIR' is empty because we have
# overridden the port_dir function.
#
$(disable_shell)
#
# Check for the existance of a port's hash file
#
# \param $1 path to hash file
#
# This check may fail whenever a 'port_dir' call in a content.mk file refers to
# a wrong repository.
#
_assert_hash_exists = $(if $(wildcard $1).hash,,\
$(error missing hash file for port '$(notdir $1)'\
(expected at $1)))
#
# If a port is missing, append its name to the missing ports file
#
_assert = $(if $1,$1,$(shell echo $2 >> $(MISSING_PORTS_FILE)))
#
# Utility to query the port directory for a given path to a port description.
#
# Example:
#
# $(call port_dir,$(GENODE_DIR)/repos/libports/ports/libpng)
#
_port_hash = $(_assert_hash_exists)$(shell cat $(call _assert,$(wildcard $1.hash),$(notdir $1)))
_port_dir = $(wildcard $(CONTRIB_DIR)/$(notdir $1)-$(call _port_hash,$1))
port_dir = $(call enable_shell)$(call _assert,$(call _port_dir,$1),$(notdir $1))$(call disable_shell)
#
# Prevent the evaluation of mirror_from_rep_dir in content.mk
#
mirror_from_rep_dir = $(error mirror_from_rep_dir called outside of target)
#
# Prevent the evaluation of the first target in the content.mk file
#
prevent_execution_of_content_targets:
#
# Include the content.mk file to evaluate all calls to the port_dir function
#
include $(CONTENT_MK)