Make include_top comments only apply to the next statement
Previously adding an include_top comment would make it apply for the rest of the file. This was confusing behavior, and could also cause extra roots to be searched in a situation like the following: \#RBC# include_top foo include $(VAR)/file.mk \#RBC# include_top bar include $(VAR)/file.mk Here the second include would have file.mk from both the foo and bar directories in its _entry dictionary. Bug: 213508006 Test: go test Change-Id: If3430594759bee1390255400fe29b43d77f7b6a6
This commit is contained in:
@@ -446,7 +446,7 @@ func newParseContext(ss *StarlarkScript, nodes []mkparser.Node) *parseContext {
|
|||||||
variables: make(map[string]variable),
|
variables: make(map[string]variable),
|
||||||
dependentModules: make(map[string]*moduleInfo),
|
dependentModules: make(map[string]*moduleInfo),
|
||||||
soongNamespaces: make(map[string]map[string]bool),
|
soongNamespaces: make(map[string]map[string]bool),
|
||||||
includeTops: []string{"vendor/google-devices"},
|
includeTops: []string{},
|
||||||
}
|
}
|
||||||
ctx.pushVarAssignments()
|
ctx.pushVarAssignments()
|
||||||
for _, item := range predefined {
|
for _, item := range predefined {
|
||||||
@@ -809,6 +809,10 @@ func (ctx *parseContext) handleSubConfig(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pathPattern[0] == "" {
|
if pathPattern[0] == "" {
|
||||||
|
if len(ctx.includeTops) == 0 {
|
||||||
|
ctx.errorf(v, "inherit-product/include statements must not be prefixed with a variable, or must include a #RBC# include_top comment beforehand giving a root directory to search.")
|
||||||
|
return
|
||||||
|
}
|
||||||
// If pattern starts from the top. restrict it to the directories where
|
// If pattern starts from the top. restrict it to the directories where
|
||||||
// we know inherit-product uses dynamically calculated path.
|
// we know inherit-product uses dynamically calculated path.
|
||||||
for _, p := range ctx.includeTops {
|
for _, p := range ctx.includeTops {
|
||||||
@@ -1671,6 +1675,13 @@ func (ctx *parseContext) handleSimpleStatement(node mkparser.Node) {
|
|||||||
default:
|
default:
|
||||||
ctx.errorf(x, "unsupported line %s", strings.ReplaceAll(x.Dump(), "\n", "\n#"))
|
ctx.errorf(x, "unsupported line %s", strings.ReplaceAll(x.Dump(), "\n", "\n#"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the includeTops after each non-comment statement
|
||||||
|
// so that include annotations placed on certain statements don't apply
|
||||||
|
// globally for the rest of the makefile was well.
|
||||||
|
if _, wasComment := node.(*mkparser.Comment); !wasComment && len(ctx.includeTops) > 0 {
|
||||||
|
ctx.includeTops = []string{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Processes annotation. An annotation is a comment that starts with #RBC# and provides
|
// Processes annotation. An annotation is a comment that starts with #RBC# and provides
|
||||||
|
@@ -1109,6 +1109,46 @@ def init(g, handle):
|
|||||||
if not _varmod_init:
|
if not _varmod_init:
|
||||||
rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"]))
|
rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"]))
|
||||||
rblf.inherit(handle, _varmod, _varmod_init)
|
rblf.inherit(handle, _varmod, _varmod_init)
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "Dynamic inherit path that lacks necessary hint",
|
||||||
|
mkname: "product.mk",
|
||||||
|
in: `
|
||||||
|
#RBC# include_top foo
|
||||||
|
$(call inherit-product,$(MY_VAR)/font.mk)
|
||||||
|
|
||||||
|
#RBC# include_top foo
|
||||||
|
|
||||||
|
# There's some space and even this comment between the include_top and the inherit-product
|
||||||
|
|
||||||
|
$(call inherit-product,$(MY_VAR)/font.mk)
|
||||||
|
|
||||||
|
$(call inherit-product,$(MY_VAR)/font.mk)
|
||||||
|
`,
|
||||||
|
expected: `#RBC# include_top foo
|
||||||
|
load("//build/make/core:product_config.rbc", "rblf")
|
||||||
|
load("//foo:font.star|init", _font_init = "init")
|
||||||
|
|
||||||
|
def init(g, handle):
|
||||||
|
cfg = rblf.cfg(handle)
|
||||||
|
_entry = {
|
||||||
|
"foo/font.mk": ("_font", _font_init),
|
||||||
|
}.get("%s/font.mk" % g.get("MY_VAR", ""))
|
||||||
|
(_varmod, _varmod_init) = _entry if _entry else (None, None)
|
||||||
|
if not _varmod_init:
|
||||||
|
rblf.mkerror("product.mk", "Cannot find %s" % ("%s/font.mk" % g.get("MY_VAR", "")))
|
||||||
|
rblf.inherit(handle, _varmod, _varmod_init)
|
||||||
|
#RBC# include_top foo
|
||||||
|
# There's some space and even this comment between the include_top and the inherit-product
|
||||||
|
_entry = {
|
||||||
|
"foo/font.mk": ("_font", _font_init),
|
||||||
|
}.get("%s/font.mk" % g.get("MY_VAR", ""))
|
||||||
|
(_varmod, _varmod_init) = _entry if _entry else (None, None)
|
||||||
|
if not _varmod_init:
|
||||||
|
rblf.mkerror("product.mk", "Cannot find %s" % ("%s/font.mk" % g.get("MY_VAR", "")))
|
||||||
|
rblf.inherit(handle, _varmod, _varmod_init)
|
||||||
|
rblf.mk2rbc_error("product.mk:11", "inherit-product/include statements must not be prefixed with a variable, or must include a #RBC# include_top comment beforehand giving a root directory to search.")
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user