From 2e8bb7989edbb0998cd8bc70a51c06b857d54bd4 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Mon, 21 Mar 2022 16:43:49 -0700 Subject: [PATCH] Add artifact path requirement support to Starlark Artifact path requirements requires setting some new variables, and also dumping the state of the product config variables after evaluating partial products that set artifact path requirements. Bug: 188079133 Test: Removed the code that disabled artifacts path requirements from the rbc dashboard script, and verified that it was still green for aosp_arm64 Change-Id: I228e35285d788f4c83aa695c0f28b7c7db02544c --- core/main.mk | 2 +- core/product_config.mk | 5 ++++- core/product_config.rbc | 32 +++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/core/main.mk b/core/main.mk index a9628dc723..f6da679ef7 100644 --- a/core/main.mk +++ b/core/main.mk @@ -1351,7 +1351,7 @@ else ifdef FULL_BUILD # Verify the artifact path requirements made by included products. is_asan := $(if $(filter address,$(SANITIZE_TARGET)),true) - ifeq (,$(or $(is_asan),$(DISABLE_ARTIFACT_PATH_REQUIREMENTS),$(RBC_PRODUCT_CONFIG),$(RBC_BOARD_CONFIG))) + ifeq (,$(or $(is_asan),$(DISABLE_ARTIFACT_PATH_REQUIREMENTS))) include $(BUILD_SYSTEM)/artifact_path_requirements.mk endif else diff --git a/core/product_config.mk b/core/product_config.mk index 95b390f059..939a02206a 100644 --- a/core/product_config.mk +++ b/core/product_config.mk @@ -263,7 +263,10 @@ endif # Import all or just the current product makefile # Quick check $(check-all-products) -ifeq ($(SKIP_ARTIFACT_PATH_REQUIREMENT_PRODUCTS_CHECK),) +# This step was already handled in the RBC product configuration. +# Since the equivalent starlark code will not add the partial products to +# the PRODUCTS variable, it's ok for them to be set before check-all-products +ifeq ($(RBC_PRODUCT_CONFIG)$(SKIP_ARTIFACT_PATH_REQUIREMENT_PRODUCTS_CHECK),) # Import all the products that have made artifact path requirements, so that we can verify # the artifacts they produce. # These are imported after check-all-products because some of them might not be real products. diff --git a/core/product_config.rbc b/core/product_config.rbc index 888ff501d4..60105d444b 100644 --- a/core/product_config.rbc +++ b/core/product_config.rbc @@ -157,6 +157,13 @@ def _product_configuration(top_pcm_name, top_pcm, input_variables_init): handle = __h_new() pcm(globals, handle) + if handle.artifact_path_requirements: + globals["PRODUCTS."+name+".mk.ARTIFACT_PATH_REQUIREMENTS"] = handle.artifact_path_requirements + globals["PRODUCTS."+name+".mk.ARTIFACT_PATH_ALLOWED_LIST"] = handle.artifact_path_allowed_list + globals["PRODUCTS."+name+".mk.ARTIFACT_PATH_REQUIREMENT_IS_RELAXED"] = "true" if handle.artifact_path_requirement_is_relaxed[0] else "" + globals.setdefault("ARTIFACT_PATH_REQUIREMENT_PRODUCTS", []) + globals["ARTIFACT_PATH_REQUIREMENT_PRODUCTS"] += [name+".mk"] + # Now we know everything about this PCM, record it in 'configs'. children = handle.inherited_modules if _options.trace_modules: @@ -211,6 +218,10 @@ def _product_configuration(top_pcm_name, top_pcm, input_variables_init): _percolate_inherited(configs, pcm_name, cfg, children_names) configs[pcm_name] = pcm, cfg, children_names, True + if (pcm_name + ".mk") in globals.get("ARTIFACT_PATH_REQUIREMENT_PRODUCTS", []): + for var, val in cfg.items(): + globals["PRODUCTS."+pcm_name+".mk."+var] = val + # Copy product config variables from the cfg dictionary to the # PRODUCTS.. global variables. for var, val in configs[top_pcm_name][1].items(): @@ -419,7 +430,10 @@ def __h_new(): return struct( cfg = dict(), inherited_modules = dict(), - default_list_value = list() + default_list_value = list(), + artifact_path_requirements = list(), + artifact_path_allowed_list = list(), + artifact_path_requirement_is_relaxed = [False], # as a list so that we can reassign it ) def __h_cfg(handle): @@ -564,13 +578,17 @@ def _notdir(paths): """ return " ".join([__base(w) for w in __words(paths)]) -def _require_artifacts_in_path(paths, allowed_paths): - """TODO.""" - pass +def _require_artifacts_in_path(handle, paths, allowed_paths): + """Equivalent to require-artifacts-in-path in Make.""" + handle.artifact_path_requirements.clear() + handle.artifact_path_requirements.extend(__words(paths)) + handle.artifact_path_allowed_list.clear() + handle.artifact_path_allowed_list.extend(__words(allowed_paths)) -def _require_artifacts_in_path_relaxed(paths, allowed_paths): - """TODO.""" - pass +def _require_artifacts_in_path_relaxed(handle, paths, allowed_paths): + """Equivalent to require-artifacts-in-path-relaxed in Make.""" + _require_artifacts_in_path(handle, paths, allowed_paths) + handle.artifact_path_requirement_is_relaxed[0] = True def _expand_wildcard(pattern): """Expands shell wildcard pattern."""