Merge "Prevent duplicate entries in ctx.include_tops" am: 7febef761a

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1931259

Change-Id: I5c73e05d1ea0cd8e327f16e9bd3f5e45e1b5b0f0
This commit is contained in:
Cole Faust 2021-12-22 17:18:21 +00:00 committed by Automerger Merge Worker
commit 948837f71d
2 changed files with 41 additions and 0 deletions

View file

@ -1629,6 +1629,13 @@ func (ctx *parseContext) maybeHandleAnnotation(cnode *mkparser.Comment) {
return
}
if p, ok := maybeTrim(annotation, "include_top"); ok {
// Don't allow duplicate include tops, because then we will generate
// invalid starlark code. (duplicate keys in the _entry dictionary)
for _, top := range ctx.includeTops {
if top == p {
return
}
}
ctx.includeTops = append(ctx.includeTops, p)
return
}

View file

@ -1075,6 +1075,40 @@ def init(g, handle):
if not _varmod_init:
rblf.mkerror("cannot")
rblf.inherit(handle, _varmod, _varmod_init)
`,
},
{
desc: "Dynamic inherit with duplicated hint",
mkname: "product.mk",
in: `
MY_PATH:=foo
#RBC# include_top vendor/foo1
$(call inherit-product,$(MY_PATH)/cfg.mk)
#RBC# include_top vendor/foo1
$(call inherit-product,$(MY_PATH)/cfg.mk)
`,
expected: `load("//build/make/core:product_config.rbc", "rblf")
load("//vendor/foo1:cfg.star|init", _cfg_init = "init")
def init(g, handle):
cfg = rblf.cfg(handle)
g["MY_PATH"] = "foo"
#RBC# include_top vendor/foo1
_entry = {
"vendor/foo1/cfg.mk": ("_cfg", _cfg_init),
}.get("%s/cfg.mk" % g["MY_PATH"])
(_varmod, _varmod_init) = _entry if _entry else (None, None)
if not _varmod_init:
rblf.mkerror("cannot")
rblf.inherit(handle, _varmod, _varmod_init)
#RBC# include_top vendor/foo1
_entry = {
"vendor/foo1/cfg.mk": ("_cfg", _cfg_init),
}.get("%s/cfg.mk" % g["MY_PATH"])
(_varmod, _varmod_init) = _entry if _entry else (None, None)
if not _varmod_init:
rblf.mkerror("cannot")
rblf.inherit(handle, _varmod, _varmod_init)
`,
},
{