Merge "Remove RBC hints from generated starlark" am: bde9ace392
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1965598 Change-Id: I6f2790841d3363e1d51f39ff0961e915f98ab234
This commit is contained in:
@@ -1733,8 +1733,9 @@ func (ctx *parseContext) parseMakeString(node mkparser.Node, mk *mkparser.MakeSt
|
|||||||
func (ctx *parseContext) handleSimpleStatement(node mkparser.Node) {
|
func (ctx *parseContext) handleSimpleStatement(node mkparser.Node) {
|
||||||
switch x := node.(type) {
|
switch x := node.(type) {
|
||||||
case *mkparser.Comment:
|
case *mkparser.Comment:
|
||||||
ctx.maybeHandleAnnotation(x)
|
if !ctx.maybeHandleAnnotation(x) {
|
||||||
ctx.insertComment("#" + x.Comment)
|
ctx.insertComment("#" + x.Comment)
|
||||||
|
}
|
||||||
case *mkparser.Assignment:
|
case *mkparser.Assignment:
|
||||||
ctx.handleAssignment(x)
|
ctx.handleAssignment(x)
|
||||||
case *mkparser.Variable:
|
case *mkparser.Variable:
|
||||||
@@ -1764,8 +1765,8 @@ func (ctx *parseContext) handleSimpleStatement(node mkparser.Node) {
|
|||||||
|
|
||||||
// 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
|
||||||
// a conversion hint -- say, where to look for the dynamically calculated inherit/include
|
// a conversion hint -- say, where to look for the dynamically calculated inherit/include
|
||||||
// paths.
|
// paths. Returns true if the comment was a successfully-handled annotation.
|
||||||
func (ctx *parseContext) maybeHandleAnnotation(cnode *mkparser.Comment) {
|
func (ctx *parseContext) maybeHandleAnnotation(cnode *mkparser.Comment) bool {
|
||||||
maybeTrim := func(s, prefix string) (string, bool) {
|
maybeTrim := func(s, prefix string) (string, bool) {
|
||||||
if strings.HasPrefix(s, prefix) {
|
if strings.HasPrefix(s, prefix) {
|
||||||
return strings.TrimSpace(strings.TrimPrefix(s, prefix)), true
|
return strings.TrimSpace(strings.TrimPrefix(s, prefix)), true
|
||||||
@@ -1774,21 +1775,21 @@ func (ctx *parseContext) maybeHandleAnnotation(cnode *mkparser.Comment) {
|
|||||||
}
|
}
|
||||||
annotation, ok := maybeTrim(cnode.Comment, annotationCommentPrefix)
|
annotation, ok := maybeTrim(cnode.Comment, annotationCommentPrefix)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
if p, ok := maybeTrim(annotation, "include_top"); ok {
|
if p, ok := maybeTrim(annotation, "include_top"); ok {
|
||||||
// Don't allow duplicate include tops, because then we will generate
|
// Don't allow duplicate include tops, because then we will generate
|
||||||
// invalid starlark code. (duplicate keys in the _entry dictionary)
|
// invalid starlark code. (duplicate keys in the _entry dictionary)
|
||||||
for _, top := range ctx.includeTops {
|
for _, top := range ctx.includeTops {
|
||||||
if top == p {
|
if top == p {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.includeTops = append(ctx.includeTops, p)
|
ctx.includeTops = append(ctx.includeTops, p)
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
ctx.errorf(cnode, "unsupported annotation %s", cnode.Comment)
|
ctx.errorf(cnode, "unsupported annotation %s", cnode.Comment)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *parseContext) insertComment(s string) {
|
func (ctx *parseContext) insertComment(s string) {
|
||||||
|
@@ -1071,7 +1071,6 @@ load("//vendor/foo1:cfg.star|init", _cfg_init = "init")
|
|||||||
def init(g, handle):
|
def init(g, handle):
|
||||||
cfg = rblf.cfg(handle)
|
cfg = rblf.cfg(handle)
|
||||||
g["MY_PATH"] = "foo"
|
g["MY_PATH"] = "foo"
|
||||||
#RBC# include_top vendor/foo1
|
|
||||||
rblf.inherit(handle, "vendor/foo1/cfg", _cfg_init)
|
rblf.inherit(handle, "vendor/foo1/cfg", _cfg_init)
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
@@ -1083,6 +1082,7 @@ MY_PATH:=foo
|
|||||||
#RBC# include_top vendor/foo1
|
#RBC# include_top vendor/foo1
|
||||||
$(call inherit-product,$(MY_PATH)/cfg.mk)
|
$(call inherit-product,$(MY_PATH)/cfg.mk)
|
||||||
#RBC# include_top vendor/foo1
|
#RBC# include_top vendor/foo1
|
||||||
|
#RBC# include_top vendor/foo1
|
||||||
$(call inherit-product,$(MY_PATH)/cfg.mk)
|
$(call inherit-product,$(MY_PATH)/cfg.mk)
|
||||||
`,
|
`,
|
||||||
expected: `load("//build/make/core:product_config.rbc", "rblf")
|
expected: `load("//build/make/core:product_config.rbc", "rblf")
|
||||||
@@ -1091,9 +1091,7 @@ load("//vendor/foo1:cfg.star|init", _cfg_init = "init")
|
|||||||
def init(g, handle):
|
def init(g, handle):
|
||||||
cfg = rblf.cfg(handle)
|
cfg = rblf.cfg(handle)
|
||||||
g["MY_PATH"] = "foo"
|
g["MY_PATH"] = "foo"
|
||||||
#RBC# include_top vendor/foo1
|
|
||||||
rblf.inherit(handle, "vendor/foo1/cfg", _cfg_init)
|
rblf.inherit(handle, "vendor/foo1/cfg", _cfg_init)
|
||||||
#RBC# include_top vendor/foo1
|
|
||||||
rblf.inherit(handle, "vendor/foo1/cfg", _cfg_init)
|
rblf.inherit(handle, "vendor/foo1/cfg", _cfg_init)
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
@@ -1112,15 +1110,13 @@ $(call inherit-product,$(MY_VAR)/font.mk)
|
|||||||
|
|
||||||
$(call inherit-product,$(MY_VAR)/font.mk)
|
$(call inherit-product,$(MY_VAR)/font.mk)
|
||||||
`,
|
`,
|
||||||
expected: `#RBC# include_top foo
|
expected: `load("//build/make/core:product_config.rbc", "rblf")
|
||||||
load("//build/make/core:product_config.rbc", "rblf")
|
|
||||||
load("//foo:font.star|init", _font_init = "init")
|
load("//foo:font.star|init", _font_init = "init")
|
||||||
load("//bar:font.star|init", _font1_init = "init")
|
load("//bar:font.star|init", _font1_init = "init")
|
||||||
|
|
||||||
def init(g, handle):
|
def init(g, handle):
|
||||||
cfg = rblf.cfg(handle)
|
cfg = rblf.cfg(handle)
|
||||||
rblf.inherit(handle, "foo/font", _font_init)
|
rblf.inherit(handle, "foo/font", _font_init)
|
||||||
#RBC# include_top foo
|
|
||||||
# There's some space and even this comment between the include_top and the inherit-product
|
# There's some space and even this comment between the include_top and the inherit-product
|
||||||
rblf.inherit(handle, "foo/font", _font_init)
|
rblf.inherit(handle, "foo/font", _font_init)
|
||||||
rblf.mkwarning("product.mk:11", "Including a path with a non-constant prefix, please convert this to a simple literal to generate cleaner starlark.")
|
rblf.mkwarning("product.mk:11", "Including a path with a non-constant prefix, please convert this to a simple literal to generate cleaner starlark.")
|
||||||
|
Reference in New Issue
Block a user