Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44a151e2 authored by Greg Kaiser's avatar Greg Kaiser Committed by Automerger Merge Worker
Browse files

Merge "Add rbc implementation of clear_var_list" am: 14b12d9e

parents ca9fbbaa 14b12d9e
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -830,6 +830,37 @@ def _product_copy_files_by_pattern(src, dest, s):
    return [ __mkpatsubst_word(parsed_percent, parsed_src, x) + ":" + __mkpatsubst_word(parsed_percent, parsed_dest, x) for x in words]


__zero_values = {
    "string": "",
    "list": [],
    "int": 0,
    "float": 0,
    "bool": False,
    "dict": {},
    "NoneType": None,
    "tuple": (),
}
def __zero_value(x):
    t = type(x)
    if t in __zero_values:
        return __zero_values[t]
    else:
        fail("Unknown type: "+t)


def _clear_var_list(g, h, var_list):
    cfg = __h_cfg(h)
    for v in __words(var_list):
        # Set these variables to their zero values rather than None
        # or removing them from the dictionary because if they were
        # removed entirely, ?= would set their value, when it would not
        # after a make-based clear_var_list call.
        if v in g:
            g[v] = __zero_value(g[v])
        if v in cfg:
            cfg[v] = __zero_value(cfg[v])


def __get_options():
    """Returns struct containing runtime global settings."""
    settings = dict(
@@ -873,6 +904,7 @@ rblf = struct(
    addsuffix = _addsuffix,
    board_platform_in = _board_platform_in,
    board_platform_is = _board_platform_is,
    clear_var_list = _clear_var_list,
    copy_files = _copy_files,
    copy_if_exists = _copy_if_exists,
    cfg = __h_cfg,
+10 −0
Original line number Diff line number Diff line
@@ -162,6 +162,16 @@ assert_eq(
assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals)
assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base)

g = {"FOO": "a", "BAR": "c", "BAZ": "e"}
cfg = {"FOO": "b", "BAR": "d", "BAZ": "f"}
rblf.clear_var_list(g, struct(cfg=cfg), "FOO BAR")
assert_eq("", g["FOO"])
assert_eq("", cfg["FOO"])
assert_eq("", g["BAR"])
assert_eq("", cfg["BAR"])
assert_eq("e", g["BAZ"])
assert_eq("f", cfg["BAZ"])

test_single_value_inheritance()
test_artifact_path_requirements()
test_prefixed_sort_order()