From f5adedce038c60cd326037337984ed32e6db0527 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Fri, 18 Mar 2022 14:05:06 -0700 Subject: [PATCH] Replace $(call my-dir) with a string literal This is so that we can set LOCAL_PATH to the result of my-dir, as LOCAL_PATH can only be set to a string literal of the exact value of LOCAL_PATH. It's probably also the correct choice to start phasing out LOCAL_PATH. Bug: 214405650 Test: go test Change-Id: Ia97d7fedf4ce62643921d90a176e65edd4e2fce6 --- mk2rbc/mk2rbc.go | 2 +- mk2rbc/mk2rbc_test.go | 13 +++++++++++++ mk2rbc/variable.go | 14 ++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go index 35d7d4de4..044185443 100644 --- a/mk2rbc/mk2rbc.go +++ b/mk2rbc/mk2rbc.go @@ -1370,7 +1370,7 @@ func (p *myDirCallParser) parse(ctx *parseContext, node mkparser.Node, args *mkp if !args.Empty() { return ctx.newBadExpr(node, "my-dir function cannot have any arguments passed to it.") } - return &variableRefExpr{ctx.addVariable("LOCAL_PATH"), true} + return &stringLiteralExpr{literal: filepath.Dir(ctx.script.mkFile)} } type isProductInListCallParser struct{} diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go index 408466041..df0a0a7c6 100644 --- a/mk2rbc/mk2rbc_test.go +++ b/mk2rbc/mk2rbc_test.go @@ -1451,6 +1451,19 @@ def init(g, handle): rblf.mk2rbc_error("product.mk:19", "type_hint annotations must come before the first Makefile statement") g["MY_VAR_4"] = "foo" _my_local_var_with_dashes = ["foo"] +`, + }, + { + desc: "Set LOCAL_PATH to my-dir", + mkname: "product.mk", + in: ` +LOCAL_PATH := $(call my-dir) +`, + expected: `load("//build/make/core:product_config.rbc", "rblf") + +def init(g, handle): + cfg = rblf.cfg(handle) + `, }, } diff --git a/mk2rbc/variable.go b/mk2rbc/variable.go index 506266a29..be1b17428 100644 --- a/mk2rbc/variable.go +++ b/mk2rbc/variable.go @@ -319,15 +319,13 @@ func (ctx *parseContext) addVariable(name string) variable { v = &localVariable{baseVariable{nam: name, typ: hintType}} } else { vt := hintType - if strings.HasPrefix(name, "LOCAL_") && vt == starlarkTypeUnknown { - // Heuristics: local variables that contribute to corresponding config variables - if cfgVarName, found := localProductConfigVariables[name]; found { - vi, found2 := KnownVariables[cfgVarName] - if !found2 { - panic(fmt.Errorf("unknown config variable %s for %s", cfgVarName, name)) - } - vt = vi.valueType + // Heuristics: local variables that contribute to corresponding config variables + if cfgVarName, found := localProductConfigVariables[name]; found && vt == starlarkTypeUnknown { + vi, found2 := KnownVariables[cfgVarName] + if !found2 { + panic(fmt.Errorf("unknown config variable %s for %s", cfgVarName, name)) } + vt = vi.valueType } if strings.HasSuffix(name, "_LIST") && vt == starlarkTypeUnknown { // Heuristics: Variables with "_LIST" suffix are lists