Add support for and/or in mk2rbc

Bug: 262303006
Test: go test
Change-Id: I04130648084775c0828e95cd18a82e348c3f09eb
This commit is contained in:
Cole Faust
2022-12-12 17:38:01 -08:00
parent 18ac53b4d0
commit d2daabfa02
3 changed files with 100 additions and 0 deletions

View File

@@ -1627,6 +1627,38 @@ def init(g, handle):
g["MY_VAR_3"] = (cfg).get(g["MY_VAR_2"], (g).get(g["MY_VAR_2"], ""))
g["MY_VAR_4"] = rblf.mk2rbc_error("product.mk:5", "cannot handle invoking foo")
g["MY_VAR_5"] = rblf.mk2rbc_error("product.mk:6", "reference is too complex: $(MY_VAR_2) bar")
`,
},
{
desc: "Conditional functions",
mkname: "product.mk",
in: `
B := foo
X := $(or $(A))
X := $(or $(A),$(B))
X := $(or $(A),$(B),$(C))
X := $(and $(A))
X := $(and $(A),$(B))
X := $(and $(A),$(B),$(C))
X := $(or $(A),$(B)) Y
D := $(wildcard *.mk)
X := $(or $(B),$(D))
`,
expected: `load("//build/make/core:product_config.rbc", "rblf")
def init(g, handle):
cfg = rblf.cfg(handle)
g["B"] = "foo"
g["X"] = g.get("A", "")
g["X"] = g.get("A", "") or g["B"]
g["X"] = g.get("A", "") or g["B"] or g.get("C", "")
g["X"] = g.get("A", "")
g["X"] = g.get("A", "") and g["B"]
g["X"] = g.get("A", "") and g["B"] and g.get("C", "")
g["X"] = "%s Y" % g.get("A", "") or g["B"]
g["D"] = rblf.expand_wildcard("*.mk")
g["X"] = rblf.mk2rbc_error("product.mk:12", "Expected all arguments to $(or) or $(and) to have the same type, found \"string\" and \"list\"")
`,
},
}