Make clear_var_list set nonexistant variables to empty strings

Make's clear-var-list causes the variables to exist as empty strings.
Mimic that functionality in starlark for the variable diff and ?=.

Bug: 262303006
Test: ./out/rbcrun ./build/make/tests/run.rbc
Change-Id: I5f9c8cf342d875b1022c5c74906e59fa68fcd6c9
This commit is contained in:
Cole Faust 2022-12-13 13:02:10 -08:00
parent 14b12d9e31
commit 44de6d8f7a
2 changed files with 6 additions and 1 deletions

View file

@ -860,6 +860,10 @@ def _clear_var_list(g, h, var_list):
if v in cfg: if v in cfg:
cfg[v] = __zero_value(cfg[v]) cfg[v] = __zero_value(cfg[v])
if v not in cfg and v not in g:
# Cause the variable to appear set like the make version does
g[v] = ""
def __get_options(): def __get_options():
"""Returns struct containing runtime global settings.""" """Returns struct containing runtime global settings."""

View file

@ -164,13 +164,14 @@ assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base)
g = {"FOO": "a", "BAR": "c", "BAZ": "e"} g = {"FOO": "a", "BAR": "c", "BAZ": "e"}
cfg = {"FOO": "b", "BAR": "d", "BAZ": "f"} cfg = {"FOO": "b", "BAR": "d", "BAZ": "f"}
rblf.clear_var_list(g, struct(cfg=cfg), "FOO BAR") rblf.clear_var_list(g, struct(cfg=cfg), "FOO BAR NEWVAR")
assert_eq("", g["FOO"]) assert_eq("", g["FOO"])
assert_eq("", cfg["FOO"]) assert_eq("", cfg["FOO"])
assert_eq("", g["BAR"]) assert_eq("", g["BAR"])
assert_eq("", cfg["BAR"]) assert_eq("", cfg["BAR"])
assert_eq("e", g["BAZ"]) assert_eq("e", g["BAZ"])
assert_eq("f", cfg["BAZ"]) assert_eq("f", cfg["BAZ"])
assert_eq("", g.get("NEWVAR"))
test_single_value_inheritance() test_single_value_inheritance()
test_artifact_path_requirements() test_artifact_path_requirements()