Simplify and correct variable assignments

- Remove asgnMaybeAppend, it was only used to indicate
  that the asignment needs a setDefault. But really, all
  types of variable assignments need setDefault if they're
  self-referential.
- Remove local_append/local_set_default because there was
  no implementation for them written in product_config.rbc
  anyways.
- Correct productConfigVariable.emitDefined using the global
  variables instead of the product config variables.
- Emit setDefaults for all types of assignments if they're
  self referential.

Bug: 222737841
Test: go test
Change-Id: I06a0f90f16d5900049d473281e6d5ef5e93e67da
This commit is contained in:
Cole Faust
2022-03-09 16:00:17 -08:00
parent ce73506a85
commit e2a37988ff
4 changed files with 88 additions and 45 deletions

View File

@@ -898,6 +898,43 @@ def init(g, handle):
cfg["PRODUCT_LIST1"] += ["c"]
rblf.setdefault(handle, "PRODUCT_LIST2")
cfg["PRODUCT_LIST2"] += ["c"]
`,
},
{
desc: "assigment setdefaults",
mkname: "product.mk",
in: `
# All of these should have a setdefault because they're self-referential and not defined before
PRODUCT_LIST1 = a $(PRODUCT_LIST1)
PRODUCT_LIST2 ?= a $(PRODUCT_LIST2)
PRODUCT_LIST3 += a
# Now doing them again should not have a setdefault because they've already been set
PRODUCT_LIST1 = a $(PRODUCT_LIST1)
PRODUCT_LIST2 ?= a $(PRODUCT_LIST2)
PRODUCT_LIST3 += a
`,
expected: `# All of these should have a setdefault because they're self-referential and not defined before
load("//build/make/core:product_config.rbc", "rblf")
def init(g, handle):
cfg = rblf.cfg(handle)
rblf.setdefault(handle, "PRODUCT_LIST1")
cfg["PRODUCT_LIST1"] = (["a"] +
cfg.get("PRODUCT_LIST1", []))
if cfg.get("PRODUCT_LIST2") == None:
rblf.setdefault(handle, "PRODUCT_LIST2")
cfg["PRODUCT_LIST2"] = (["a"] +
cfg.get("PRODUCT_LIST2", []))
rblf.setdefault(handle, "PRODUCT_LIST3")
cfg["PRODUCT_LIST3"] += ["a"]
# Now doing them again should not have a setdefault because they've already been set
cfg["PRODUCT_LIST1"] = (["a"] +
cfg["PRODUCT_LIST1"])
if cfg.get("PRODUCT_LIST2") == None:
cfg["PRODUCT_LIST2"] = (["a"] +
cfg["PRODUCT_LIST2"])
cfg["PRODUCT_LIST3"] += ["a"]
`,
},
{