Skip to content

Commit 5027dba

Browse files
authored
fix: Add useful debug message when files are missing from config (#15499)
Improve error messages when image config files reference missing files (PackageLists, scripts, AdditionalFiles, etc.). Previously, if a referenced file was missing, Make would fail with a confusing message about having no rule to build the validation flag. If the missing file was in a non-existent directory, realpath would also print unhelpful errors before the actual failure. This was caused by Make's pattern rule matching behavior. The validation rules is $(STATUS_FLAGS_DIR)/validate-image-config%.flag:, which matches the variable validate-config = $(STATUS_FLAGS_DIR)/validate-image-config-$(config_name).flag The rule had config_other_files = $(if $(CONFIG_FILE),$(call shell_real_build_only, $(SCRIPTS_DIR)/get_config_deps.sh $(CONFIG_FILE)),) as a dependency. If one of those calculated files was missing, then make would consider the pattern matched rule un-usable, and would try to find an alternate rule that did have all its dependencies. Unfortunately, we only have one pattern match rule, so we must ensure that all the dependencies we list are either real files, or valid make targets, so make won't skip it.
1 parent 3a73707 commit 5027dba

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

toolkit/scripts/get_config_deps.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ do
4444
then
4545
echo "$filename"
4646
else
47-
echo $(realpath "$config_base_dir/$filename")
47+
# Use -m to canonicalize paths even if they don't exist
48+
# This allows the Makefile to detect missing files and provide a helpful error
49+
echo $(realpath -m "$config_base_dir/$filename")
4850
fi
4951
done

toolkit/scripts/imggen.mk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ fetch-external-image-packages: $(image_external_package_cache_summary)
9494
# Validate the selected config file if any changes occur in the image config base directory.
9595
# Changes to files located outside the base directory will not be detected.
9696
validate-image-config: $(validate-config)
97+
98+
# Validate that all config dependencies exist before Make tries to process them as prerequisites
99+
# If we don't do this, Make will error out with a less-than-helpful message about having no rule to make
100+
# the validation flag (since its a pattern match and if a dependency is missing, it can't match the pattern)
101+
# Skip this check for printvar targets so users can still debug with the suggested command
102+
ifneq ($(CONFIG_FILE),)
103+
ifeq ($(filter printvar-%,$(MAKECMDGOALS)),)
104+
config_missing_files = $(filter-out $(wildcard $(config_other_files)),$(config_other_files))
105+
ifneq ($(config_missing_files),)
106+
$(error $(newline)$(newline)ERROR: Image configuration '$(CONFIG_FILE)' missing files:$(newline)$(newline)$(foreach file,$(config_missing_files), - $(file)$(newline))$(newline)Run this command to see all expected files:$(newline) make printvar-config_other_files CONFIG_FILE=$(CONFIG_FILE) --quiet$(newline))
107+
endif
108+
endif
109+
endif
110+
97111
$(STATUS_FLAGS_DIR)/validate-image-config%.flag: $(go-imageconfigvalidator) $(depend_CONFIG_FILE) $(CONFIG_FILE) $(config_other_files)
98112
$(if $(CONFIG_FILE),,$(error Must set CONFIG_FILE=))
99113
$(go-imageconfigvalidator) \

toolkit/scripts/utils.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ build_arch := $(shell uname -m)
1515

1616
no_repo_acl = $(STATUS_FLAGS_DIR)/no_repo_acl.flag
1717

18+
# Define newline for use in error messages and output formatting
19+
define newline
20+
21+
22+
endef
23+
1824
######## MISC. MAKEFILE Functions ########
1925

2026
# Creates a folder if it doesn't exist. Also sets the timestamp to 0 if it is

0 commit comments

Comments
 (0)