Translate more Make builtin functions
Adds support for abspath/firstword/dir/lastword/notdir functions Bug: 194521362 Test: internal Change-Id: I34dd6a81f21a4ef2f8f0a72bd80284ced8957b5c
This commit is contained in:
@@ -76,11 +76,13 @@ var knownFunctions = map[string]struct {
|
||||
runtimeName string
|
||||
returnType starlarkType
|
||||
}{
|
||||
"abspath": {baseName + ".abspath", starlarkTypeString},
|
||||
fileExistsPhony: {baseName + ".file_exists", starlarkTypeBool},
|
||||
wildcardExistsPhony: {baseName + ".file_wildcard_exists", starlarkTypeBool},
|
||||
"add-to-product-copy-files-if-exists": {baseName + ".copy_if_exists", starlarkTypeList},
|
||||
"addprefix": {baseName + ".addprefix", starlarkTypeList},
|
||||
"addsuffix": {baseName + ".addsuffix", starlarkTypeList},
|
||||
"dir": {baseName + ".dir", starlarkTypeList},
|
||||
"enforce-product-packages-exist": {baseName + ".enforce_product_packages_exist", starlarkTypeVoid},
|
||||
"error": {baseName + ".mkerror", starlarkTypeVoid},
|
||||
"findstring": {"!findstring", starlarkTypeInt},
|
||||
@@ -88,6 +90,7 @@ var knownFunctions = map[string]struct {
|
||||
"find-word-in-list": {"!find-word-in-list", starlarkTypeUnknown}, // internal macro
|
||||
"filter": {baseName + ".filter", starlarkTypeList},
|
||||
"filter-out": {baseName + ".filter_out", starlarkTypeList},
|
||||
"firstword": {"!firstword", starlarkTypeString},
|
||||
"get-vendor-board-platforms": {"!get-vendor-board-platforms", starlarkTypeList}, // internal macro, used by is-board-platform, etc.
|
||||
"info": {baseName + ".mkinfo", starlarkTypeVoid},
|
||||
"is-android-codename": {"!is-android-codename", starlarkTypeBool}, // unused by product config
|
||||
@@ -102,9 +105,11 @@ var knownFunctions = map[string]struct {
|
||||
"is-vendor-board-platform": {"!is-vendor-board-platform", starlarkTypeBool},
|
||||
callLoadAlways: {"!inherit-product", starlarkTypeVoid},
|
||||
callLoadIf: {"!inherit-product-if-exists", starlarkTypeVoid},
|
||||
"lastword": {"!lastword", starlarkTypeString},
|
||||
"match-prefix": {"!match-prefix", starlarkTypeUnknown}, // internal macro
|
||||
"match-word": {"!match-word", starlarkTypeUnknown}, // internal macro
|
||||
"match-word-in-list": {"!match-word-in-list", starlarkTypeUnknown}, // internal macro
|
||||
"notdir": {baseName + ".notdir", starlarkTypeString},
|
||||
"my-dir": {"!my-dir", starlarkTypeString},
|
||||
"patsubst": {baseName + ".mkpatsubst", starlarkTypeString},
|
||||
"produce_copy_files": {baseName + ".produce_copy_files", starlarkTypeList},
|
||||
@@ -1207,6 +1212,8 @@ func (ctx *parseContext) parseReference(node mkparser.Node, ref *mkparser.MakeSt
|
||||
switch expr.name {
|
||||
case "word":
|
||||
return ctx.parseWordFunc(node, args)
|
||||
case "firstword", "lastword":
|
||||
return ctx.parseFirstOrLastwordFunc(node, expr.name, args)
|
||||
case "my-dir":
|
||||
return &variableRefExpr{ctx.addVariable("LOCAL_PATH"), true}
|
||||
case "subst", "patsubst":
|
||||
@@ -1279,6 +1286,24 @@ func (ctx *parseContext) parseWordFunc(node mkparser.Node, args *mkparser.MakeSt
|
||||
return indexExpr{array, &intLiteralExpr{int(index - 1)}}
|
||||
}
|
||||
|
||||
func (ctx *parseContext) parseFirstOrLastwordFunc(node mkparser.Node, name string, args *mkparser.MakeString) starlarkExpr {
|
||||
arg := ctx.parseMakeString(node, args)
|
||||
if bad, ok := arg.(*badExpr); ok {
|
||||
return bad
|
||||
}
|
||||
index := &intLiteralExpr{0}
|
||||
if name == "lastword" {
|
||||
if v, ok := arg.(*variableRefExpr); ok && v.ref.name() == "MAKEFILE_LIST" {
|
||||
return &stringLiteralExpr{ctx.script.mkFile}
|
||||
}
|
||||
index.literal = -1
|
||||
}
|
||||
if arg.typ() == starlarkTypeList {
|
||||
return &indexExpr{arg, index}
|
||||
}
|
||||
return &indexExpr{&callExpr{object: arg, name: "split", returnType: starlarkTypeList}, index}
|
||||
}
|
||||
|
||||
func (ctx *parseContext) parseMakeString(node mkparser.Node, mk *mkparser.MakeString) starlarkExpr {
|
||||
if mk.Const() {
|
||||
return &stringLiteralExpr{mk.Dump()}
|
||||
|
@@ -658,6 +658,14 @@ PRODUCT_COPY_FILES := $(addprefix pfx-,a b c)
|
||||
PRODUCT_COPY_FILES := $(addsuffix .sff, a b c)
|
||||
PRODUCT_NAME := $(word 1, $(subst ., ,$(TARGET_BOARD_PLATFORM)))
|
||||
$(info $(patsubst %.pub,%,$(PRODUCT_ADB_KEYS)))
|
||||
$(info $(dir foo/bar))
|
||||
$(info $(firstword $(PRODUCT_COPY_FILES)))
|
||||
$(info $(lastword $(PRODUCT_COPY_FILES)))
|
||||
$(info $(dir $(lastword $(MAKEFILE_LIST))))
|
||||
$(info $(dir $(lastword $(PRODUCT_COPY_FILES))))
|
||||
$(info $(dir $(lastword $(foobar))))
|
||||
$(info $(abspath foo/bar))
|
||||
$(info $(notdir foo/bar))
|
||||
|
||||
`,
|
||||
expected: `load("//build/make/core:product_config.rbc", "rblf")
|
||||
@@ -668,6 +676,14 @@ def init(g, handle):
|
||||
cfg["PRODUCT_COPY_FILES"] = rblf.addsuffix(".sff", "a b c")
|
||||
cfg["PRODUCT_NAME"] = ((g.get("TARGET_BOARD_PLATFORM", "")).replace(".", " ")).split()[0]
|
||||
rblf.mkinfo("product.mk", rblf.mkpatsubst("%.pub", "%", g.get("PRODUCT_ADB_KEYS", "")))
|
||||
rblf.mkinfo("product.mk", rblf.dir("foo/bar"))
|
||||
rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][0])
|
||||
rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][-1])
|
||||
rblf.mkinfo("product.mk", rblf.dir("product.mk"))
|
||||
rblf.mkinfo("product.mk", rblf.dir(cfg["PRODUCT_COPY_FILES"][-1]))
|
||||
rblf.mkinfo("product.mk", rblf.dir((_foobar).split()[-1]))
|
||||
rblf.mkinfo("product.mk", rblf.abspath("foo/bar"))
|
||||
rblf.mkinfo("product.mk", rblf.notdir("foo/bar"))
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user