From b0b2457842680dc403ece583d9c529a44af5bded Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Fri, 6 Oct 2023 11:53:50 -0700 Subject: [PATCH] Handle include statements with trailing whitespace Fixes: 303832950 Test: go test Change-Id: I919556ee43a60f59dbd7c040025f01abb53da2a8 --- mk2rbc/mk2rbc.go | 2 ++ mk2rbc/mk2rbc_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go index 8225df60d..3a6854c29 100644 --- a/mk2rbc/mk2rbc.go +++ b/mk2rbc/mk2rbc.go @@ -941,6 +941,8 @@ func (p *inheritProductCallParser) parse(ctx *parseContext, v mkparser.Node, arg func (ctx *parseContext) handleInclude(v *mkparser.Directive) []starlarkNode { loadAlways := v.Name[0] != '-' + v.Args.TrimRightSpaces() + v.Args.TrimLeftSpaces() return ctx.handleSubConfig(v, ctx.parseMakeString(v, v.Args), loadAlways, func(im inheritedModule) starlarkNode { return &includeNode{im, loadAlways} }) diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go index 7e68026b2..a9b61978a 100644 --- a/mk2rbc/mk2rbc_test.go +++ b/mk2rbc/mk2rbc_test.go @@ -192,6 +192,31 @@ def init(g, handle): `, }, + { + desc: "Include with trailing whitespace", + mkname: "product.mk", + in: ` +# has a trailing whitespace after cfg.mk +include vendor/$(foo)/cfg.mk +`, + expected: `# has a trailing whitespace after cfg.mk +load("//build/make/core:product_config.rbc", "rblf") +load("//vendor/foo1:cfg.star|init", _cfg_init = "init") +load("//vendor/bar/baz:cfg.star|init", _cfg1_init = "init") + +def init(g, handle): + cfg = rblf.cfg(handle) + _entry = { + "vendor/foo1/cfg.mk": ("vendor/foo1/cfg", _cfg_init), + "vendor/bar/baz/cfg.mk": ("vendor/bar/baz/cfg", _cfg1_init), + }.get("vendor/%s/cfg.mk" % _foo) + (_varmod, _varmod_init) = _entry if _entry else (None, None) + if not _varmod_init: + rblf.mkerror("product.mk", "Cannot find %s" % ("vendor/%s/cfg.mk" % _foo)) + _varmod_init(g, handle) +`, + }, + { desc: "Synonymous inherited configurations", mkname: "path/product.mk",