Merge "Make starlark board configuration work with sdk_phone_x86_64"

This commit is contained in:
Cole Faust 2021-11-05 18:42:12 +00:00 committed by Gerrit Code Review
commit 2f1bd70c9c
5 changed files with 73 additions and 32 deletions

View file

@ -185,19 +185,44 @@ else
.KATI_READONLY := TARGET_DEVICE_DIR
endif
# Dumps all variables that match [A-Z][A-Z0-9_]* to the file at $(1)
# It is used to print only the variables that are likely to be relevant to the
# board configuration.
define dump-public-variables
$(file >$(OUT_DIR)/dump-public-variables-temp.txt,$(subst $(space),$(newline),$(.VARIABLES)))\
$(file >$(1),\
$(foreach v, $(shell grep -he "^[A-Z][A-Z0-9_]*$$" $(OUT_DIR)/dump-public-variables-temp.txt | grep -vhe "^SOONG_"),\
$(v) := $(strip $($(v)))$(newline)))
endef
# TODO(colefaust) change this if to RBC_PRODUCT_CONFIG when
# the board configuration is known to work on everything
# the product config works on.
ifndef RBC_BOARD_CONFIG
include $(board_config_mk)
else
rc := $(shell build/soong/scripts/rbc-run $(board_config_mk) \
BUILDING_GSI=$(BUILDING_GSI) >$(OUT_DIR)/rbcboardtemp.mk || echo $$?)
ifneq (,$(rc))
$(error board configuration converter failed: $(rc))
$(shell mkdir -p $(OUT_DIR)/rbc)
$(call dump-public-variables, $(OUT_DIR)/rbc/make_vars_pre_board_config.mk)
$(shell $(OUT_DIR)/soong/mk2rbc \
--mode=write -r --outdir $(OUT_DIR)/rbc \
--boardlauncher=$(OUT_DIR)/rbc/boardlauncher.rbc \
--input_variables=$(OUT_DIR)/rbc/make_vars_pre_board_config.mk \
$(board_config_mk))
ifneq ($(.SHELLSTATUS),0)
$(error board configuration converter failed: $(.SHELLSTATUS))
endif
include $(OUT_DIR)/rbcboardtemp.mk
$(shell $(OUT_DIR)/soong/rbcrun \
RBC_OUT="make,global" \
$(OUT_DIR)/rbc/boardlauncher.rbc \
>$(OUT_DIR)/rbc/rbc_board_config_results.mk)
ifneq ($(.SHELLSTATUS),0)
$(error board configuration runner failed: $(.SHELLSTATUS))
endif
include $(OUT_DIR)/rbc/rbc_board_config_results.mk
endif
ifneq (,$(and $(TARGET_ARCH),$(TARGET_ARCH_SUITE)))

View file

@ -1379,7 +1379,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)))
ifeq (,$(or $(is_asan),$(DISABLE_ARTIFACT_PATH_REQUIREMENTS),$(RBC_PRODUCT_CONFIG),$(RBC_BOARD_CONFIG)))
include $(BUILD_SYSTEM)/artifact_path_requirements.mk
endif
else

View file

@ -81,7 +81,7 @@ $(products_graph): PRIVATE_PRODUCTS := $(all_products)
$(products_graph): PRIVATE_PRODUCTS_FILTER := $(products_list)
$(products_graph): $(this_makefile)
ifeq (,$(RBC_PRODUCT_CONFIG)$(RBC_NO_PRODUCT_GRAPH))
ifeq (,$(RBC_PRODUCT_CONFIG)$(RBC_NO_PRODUCT_GRAPH)$(RBC_BOARD_CONFIG))
@echo Product graph DOT: $@ for $(PRIVATE_PRODUCTS_FILTER)
$(hide) echo 'digraph {' > $@.in
$(hide) echo 'graph [ ratio=.5 ];' >> $@.in
@ -148,7 +148,7 @@ $(call product-debug-filename, $(p)): \
$(hide) cat $$< | build/make/tools/product_debug.py > $$@
endef
ifeq (,$(RBC_PRODUCT_CONFIG)$(RBC_NO_PRODUCT_GRAPH))
ifeq (,$(RBC_PRODUCT_CONFIG)$(RBC_NO_PRODUCT_GRAPH)$(RBC_BOARD_CONFIG))
product_debug_files:=
$(foreach p,$(all_products), \
$(eval $(call transform-product-debug, $(p))) \
@ -164,4 +164,4 @@ else
.PHONY: product-graph
@echo RBC_PRODUCT_CONFIG and RBC_NO_PRODUCT_GRAPH should be unset to generate product graph
false
endif
endif

View file

@ -206,10 +206,10 @@ endif
ifndef RBC_PRODUCT_CONFIG
$(call import-products, $(current_product_makefile))
else
rc := $(shell build/soong/scripts/rbc-run $(current_product_makefile) \
>$(OUT_DIR)/rbctemp.mk || echo $$?)
ifneq (,$(rc))
$(error product configuration converter failed: $(rc))
$(shell build/soong/scripts/rbc-run $(current_product_makefile) \
>$(OUT_DIR)/rbctemp.mk)
ifneq ($(.SHELLSTATUS),0)
$(error product configuration converter failed: $(.SHELLSTATUS))
endif
include $(OUT_DIR)/rbctemp.mk
PRODUCTS += $(current_product_makefile)

View file

@ -17,7 +17,7 @@ load("//build/make/core:envsetup.rbc", _envsetup_init = "init")
"""Runtime functions."""
_soong_config_namespaces_key = "$SOONG_CONFIG_NAMESPACES"
def _global_init(version_info):
def _init_globals(version_info):
"""Returns dict created from the runtime environment."""
globals = dict()
@ -50,7 +50,8 @@ def _global_init(version_info):
def __print_attr(attr, value):
if not value:
# Allow using empty strings to clear variables, but not None values
if value == None:
return
if type(value) == "list":
if _options.rearrange:
@ -74,21 +75,24 @@ def _printvars(state):
__print_attr(attr, val)
if _options.print_globals:
print()
for attr, val in sorted(globals.items()):
if attr == _soong_config_namespaces_key:
__print_attr("SOONG_CONFIG_NAMESPACES", val.keys())
for nsname, nsvars in sorted(val.items()):
# Define SOONG_CONFIG_<ns> for Make, othewise
# it cannot be added to .KATI_READONLY list
if _options.format == "make":
print("SOONG_CONFIG_" + nsname, ":=", " ".join(nsvars.keys()))
for var, val in sorted(nsvars.items()):
if val:
__print_attr("SOONG_CONFIG_%s_%s" % (nsname, var), val)
else:
print("SOONG_CONFIG_%s_%s :=" % (nsname, var))
elif attr not in globals_base or globals_base[attr] != val:
__print_attr(attr, val)
_printglobals(globals, globals_base)
def _printglobals(globals, globals_base):
for attr, val in sorted(globals.items()):
if attr == _soong_config_namespaces_key:
__print_attr("SOONG_CONFIG_NAMESPACES", val.keys())
for nsname, nsvars in sorted(val.items()):
# Define SOONG_CONFIG_<ns> for Make, othewise
# it cannot be added to .KATI_READONLY list
if _options.format == "make":
print("SOONG_CONFIG_" + nsname, ":=", " ".join(nsvars.keys()))
for var, val in sorted(nsvars.items()):
if val:
__print_attr("SOONG_CONFIG_%s_%s" % (nsname, var), val)
else:
print("SOONG_CONFIG_%s_%s :=" % (nsname, var))
elif attr not in globals_base or globals_base[attr] != val:
__print_attr(attr, val)
def __printvars_rearrange_list(value_list):
"""Rearrange value list: return only distinct elements, maybe sorted."""
@ -109,7 +113,7 @@ def _product_configuration(top_pcm_name, top_pcm, version_info):
# PCM means "Product Configuration Module", i.e., a Starlark file
# whose body consists of a single init function.
globals_base = _global_init(version_info)
globals_base = _init_globals(version_info)
globals = dict(**globals_base)
config_postfix = [] # Configs in postfix order
@ -203,6 +207,16 @@ def _product_configuration(top_pcm_name, top_pcm, version_info):
return (globals, configs[top_pcm_name][1], globals_base)
def _board_configuration(board_config_init, input_variables_init):
globals = {}
h = __h_new()
input_variables_init(globals, h)
globals_base = dict(**globals)
board_config_init(globals, h)
return (globals, h[1], globals_base)
def _substitute_inherited(configs, pcm_name, cfg):
"""Substitutes inherited values in all the attributes.
@ -645,7 +659,7 @@ rblf = struct(
filter = _filter,
filter_out = _filter_out,
find_and_copy = _find_and_copy,
global_init = _global_init,
init_globals = _init_globals,
inherit = _inherit,
indirect = _indirect,
mkinfo = _mkinfo,
@ -655,7 +669,9 @@ rblf = struct(
mkstrip = _mkstrip,
mksubst = _mksubst,
printvars = _printvars,
printglobals = _printglobals,
product_configuration = _product_configuration,
board_configuration = _board_configuration,
product_copy_files_by_pattern = _product_copy_files_by_pattern,
require_artifacts_in_path = _require_artifacts_in_path,
require_artifacts_in_path_relaxed = _require_artifacts_in_path_relaxed,