From dfd373fa0c1c658f6da678272c32176b1e4cbf9f Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 8 Nov 2024 16:44:09 +0100 Subject: [PATCH] depot/build: check bin against src if REBUILD= When using the depot/build tool with the 'REBUILD=' argument as done by the run tool's --depot-auto-update feature, the depot/build tool now checks that an existing bin archive was indeed created via the src and api archives present in the depot for the given version. This addresses consistency issues when switching between different git branches that refer to the same depot versions but with different content. Fixes #5379 --- tool/depot/build | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tool/depot/build b/tool/depot/build index 3594dcf448..7c26d2a904 100755 --- a/tool/depot/build +++ b/tool/depot/build @@ -159,9 +159,39 @@ execute_generated_build_mk_file: $(BUILD_MK_FILE) $(VERBOSE)$(MAKE) $(if $(VERBOSE),--quiet) -f $(BUILD_MK_FILE) \ -C $(DEPOT_DIR) VERBOSE=$(VERBOSE) +# +# Utilities to check consistency of bin archives with their src and used APIS +# +_eq = $(and $(findstring x$(1),x$(2)), $(findstring x$(2),x$(1))) +_libapi = $(if $(wildcard $(DEPOT_DIR)/$1/api),$(call file_content,$(DEPOT_DIR)/$1/api),) +_apis_of_src = $(call _libapi,$1) $(call file_content,$(DEPOT_DIR)/$1/used_apis) +_api_archives_of_src = $(addprefix $(call archive_user,$1)/api/,$(call _apis_of_src,$1)) +_api_hashes = $(foreach A,$(call _api_archives_of_src,$1),$(call file_content,$(DEPOT_DIR)/$A.hash)) +_src_hash = $(call file_content,$(DEPOT_DIR)/$1.hash) +_src_and_api_hashes = $(call _src_hash,$1) $(call _api_hashes,$1) +_src_of_bin = $(call archive_user,$1)/src/$(call bin_archive_recipe,$1)/$(call bin_archive_version,$1) +_bin_ingredient_hashes = $(call _src_and_api_hashes,$(call _src_of_bin,$1)) +_bin_hashes = $(call file_content,$(DEPOT_DIR)/$1.hash) +_bin_exists = $(wildcard $(DEPOT_DIR)/$1) +_bin_inconsistent = $(if $(call _bin_exists,$1),\ + $(if $(call _eq,$(call _bin_ingredient_hashes,$1),$(call _bin_hashes,$1)),,$1)) + ifneq ($(REBUILD),) execute_generated_build_mk_file: wipe_existing_archives +else +INCONSISTENT_BIN_ARCHIVES = $(strip $(foreach I,${ARCHIVES(bin)},$(call _bin_inconsistent,$I))) +ifneq ($(INCONSISTENT_BIN_ARCHIVES),) +execute_generated_build_mk_file: report_bin_src_inconsistencies endif +endif # REBUILD + +report_bin_src_inconsistencies: + @( \ + echo -e "\nError: the following bin archives do not match their src and apis:\n"; \ + for i in $(INCONSISTENT_BIN_ARCHIVES); do echo -e " $$i"; done; \ + echo -e "\nYou may consider removing those binary archives from the depot.\n" \ + ) + @false $(MAKECMDGOALS): execute_generated_build_mk_file @true