From 73660428700a206b3fa982e709b51988f0c36d71 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 5 Jan 2023 11:07:47 -0800 Subject: [PATCH] Show correct line numbers for errors in an $(eval) Bug: 264488559 Test: go test Change-Id: I95ce0345912a2af351be0ecc4595bdc4a2047c0c --- mk2rbc/mk2rbc.go | 12 ++++++++++++ mk2rbc/mk2rbc_test.go | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go index 705eac37b..77394d964 100644 --- a/mk2rbc/mk2rbc.go +++ b/mk2rbc/mk2rbc.go @@ -1872,6 +1872,18 @@ func (p *evalNodeParser) parse(ctx *parseContext, node mkparser.Node, args *mkpa if len(nodes) == 0 { return []starlarkNode{} } else if len(nodes) == 1 { + // Replace the nodeLocator with one that just returns the location of + // the $(eval) node. Otherwise, statements inside an $(eval) will show as + // being on line 1 of the file, because they're on line 1 of + // strings.NewReader(args.Dump()) + oldNodeLocator := ctx.script.nodeLocator + ctx.script.nodeLocator = func(pos mkparser.Pos) int { + return oldNodeLocator(node.Pos()) + } + defer func() { + ctx.script.nodeLocator = oldNodeLocator + }() + switch n := nodes[0].(type) { case *mkparser.Assignment: if n.Name.Const() { diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go index 65a3be7f7..7e68026b2 100644 --- a/mk2rbc/mk2rbc_test.go +++ b/mk2rbc/mk2rbc_test.go @@ -1567,6 +1567,9 @@ $(foreach x,$(MY_LIST_VAR), \ $(foreach x,$(MY_LIST_VAR), \ $(eval include foo/$(x).mk)) + +# Check that we get as least close to correct line numbers for errors on statements inside evals +$(eval $(call inherit-product,$(A_VAR))) `, expected: `load("//build/make/core:product_config.rbc", "rblf") load("//foo:font.star", _font_init = "init") @@ -1592,6 +1595,8 @@ def init(g, handle): if not _varmod_init: rblf.mkerror("product.mk", "Cannot find %s" % ("foo/%s.mk" % x)) _varmod_init(g, handle) + # Check that we get as least close to correct line numbers for errors on statements inside evals + rblf.mk2rbc_error("product.mk:17", "inherit-product/include argument is too complex") `, }, {