Implement add_soong_namespace and add_soong_config_var_value functions
Bug: 193540681 Test: rbcrun build/make/tests/run.rbc Change-Id: I129136e83d2d00ef5b64d3aab07b98719198dcfe
This commit is contained in:
@@ -16,6 +16,7 @@ load("//build/make/core:envsetup.rbc", _envsetup_init = "init")
|
||||
|
||||
"""Runtime functions."""
|
||||
|
||||
_soong_config_namespaces_key = "$SOONG_CONFIG_NAMESPACES"
|
||||
def _global_init():
|
||||
"""Returns dict created from the runtime environment."""
|
||||
globals = dict()
|
||||
@@ -29,6 +30,7 @@ def _global_init():
|
||||
globals[k] = getattr(rblf_cli, k)
|
||||
|
||||
globals.setdefault("PRODUCT_SOONG_NAMESPACES", [])
|
||||
globals.setdefault(_soong_config_namespaces_key, {})
|
||||
_envsetup_init(globals)
|
||||
|
||||
# Variables that should be defined.
|
||||
@@ -74,7 +76,12 @@ def _printvars(globals, cfg):
|
||||
if _options.print_globals:
|
||||
print()
|
||||
for attr, val in sorted(globals.items()):
|
||||
if attr not in _globals_base:
|
||||
if attr == _soong_config_namespaces_key:
|
||||
__print_attr("SOONG_CONFIG_NAMESPACES", val.keys())
|
||||
for nsname, nsvars in sorted(val.items()):
|
||||
for var, val in sorted(nsvars.items()):
|
||||
__print_attr("SOONG_CONFIG_%s_%s" % (nsname, var), val)
|
||||
elif attr not in _globals_base:
|
||||
__print_attr(attr, val)
|
||||
|
||||
def __printvars_rearrange_list(value_list):
|
||||
@@ -268,6 +275,20 @@ def _indirect(pcm_name):
|
||||
"""Returns configuration item for the inherited module."""
|
||||
return (pcm_name,)
|
||||
|
||||
def _add_soong_config_namespace(g, nsname):
|
||||
"""Adds given namespace."""
|
||||
|
||||
# A value cannot be updated, so we need to create a new dictionary
|
||||
old = g[_soong_config_namespaces_key]
|
||||
g[_soong_config_namespaces_key] = dict([(k,v) for k,v in old.items()] + [(nsname, {})])
|
||||
|
||||
def _add_soong_config_var_value(g, nsname, var, value):
|
||||
"""Defines a variable and adds it to the given namespace."""
|
||||
ns = g[_soong_config_namespaces_key].get(nsname)
|
||||
if ns == None:
|
||||
fail("no such namespace: " + nsname)
|
||||
ns[var] = value
|
||||
|
||||
def _addprefix(prefix, string_or_list):
|
||||
"""Adds prefix and returns a list.
|
||||
|
||||
@@ -523,6 +544,8 @@ def __get_options():
|
||||
# Settings used during debugging.
|
||||
_options = __get_options()
|
||||
rblf = struct(
|
||||
add_soong_config_namespace = _add_soong_config_namespace,
|
||||
add_soong_config_var_value = _add_soong_config_var_value,
|
||||
addprefix = _addprefix,
|
||||
addsuffix = _addsuffix,
|
||||
copy_if_exists = _copy_if_exists,
|
||||
|
@@ -22,6 +22,12 @@
|
||||
### include $(LOCAL_PATH)/include1.mk
|
||||
### PRODUCT_PACKAGES += dev_after
|
||||
### PRODUCT_COPY_FILES += $(call find-copy-subdir-files,audio_platform_info*.xml,device/google/redfin/audio,$(TARGET_COPY_OUT_VENDOR)/etc) xyz
|
||||
### $(call add_soong_namespace,NS1)
|
||||
### $(call add_soong_config_var_value,NS1,v1,abc)
|
||||
### $(call add_soong_config_var_value,NS1,v2,def)
|
||||
### $(call add_soong_namespace,NS2)
|
||||
### $(call add_soong_config_var_value,NS2,v3,abc)
|
||||
### $(call add_soong_config_var_value,NS2,v3,xyz)
|
||||
|
||||
load("//build/make/core:product_config.rbc", "rblf")
|
||||
load(":part1.rbc", _part1_init = "init")
|
||||
@@ -40,3 +46,10 @@ def init(g, handle):
|
||||
cfg["PRODUCT_PACKAGES"] += ["dev_after"]
|
||||
cfg["PRODUCT_COPY_FILES"] += (rblf.find_and_copy("audio_platform_info*.xml", "device/google/redfin/audio", "||VENDOR-PATH-PH||/etc") +
|
||||
["xyz"])
|
||||
rblf.add_soong_config_namespace(g, "NS1")
|
||||
rblf.add_soong_config_var_value(g, "NS1", "v1", "abc")
|
||||
rblf.add_soong_config_var_value(g, "NS1", "v2", "def")
|
||||
rblf.add_soong_config_namespace(g, "NS2")
|
||||
rblf.add_soong_config_var_value(g, "NS2", "v3", "abc")
|
||||
rblf.add_soong_config_var_value(g, "NS2", "v3", "xyz")
|
||||
|
||||
|
@@ -63,3 +63,17 @@ assert_eq(
|
||||
},
|
||||
{ k:v for k, v in sorted(config.items()) }
|
||||
)
|
||||
|
||||
ns = globals["$SOONG_CONFIG_NAMESPACES"]
|
||||
assert_eq(
|
||||
{
|
||||
"NS1": {
|
||||
"v1": "abc",
|
||||
"v2": "def"
|
||||
},
|
||||
"NS2": {
|
||||
"v3": "xyz"
|
||||
}
|
||||
},
|
||||
{k:v for k, v in sorted(ns.items()) }
|
||||
)
|
||||
|
Reference in New Issue
Block a user