Loading mk2rbc/mk2rbc.go +15 −2 Original line number Diff line number Diff line Loading @@ -105,7 +105,7 @@ var knownFunctions = map[string]struct { "dist-for-goals": {baseName + ".mkdist_for_goals", starlarkTypeVoid, hiddenArgGlobal}, "enforce-product-packages-exist": {baseName + ".enforce_product_packages_exist", starlarkTypeVoid, hiddenArgNone}, "error": {baseName + ".mkerror", starlarkTypeVoid, hiddenArgNone}, "findstring": {"!findstring", starlarkTypeInt, hiddenArgNone}, "findstring": {baseName + ".findstring", starlarkTypeString, hiddenArgNone}, "find-copy-subdir-files": {baseName + ".find_and_copy", starlarkTypeList, hiddenArgNone}, "find-word-in-list": {"!find-word-in-list", starlarkTypeUnknown, hiddenArgNone}, // internal macro "filter": {baseName + ".filter", starlarkTypeList, hiddenArgNone}, Loading Loading @@ -1288,8 +1288,21 @@ func (ctx *parseContext) parseCheckFindstringFuncResult(directive *mkparser.Dire right: &intLiteralExpr{-1}, isEq: !negate, } } else if s, ok := maybeString(xValue); ok { if s2, ok := maybeString(xCall.args[0]); ok && s == s2 { return &eqExpr{ left: &callExpr{ object: xCall.args[1], name: "find", args: []starlarkExpr{xCall.args[0]}, returnType: starlarkTypeInt, }, right: &intLiteralExpr{-1}, isEq: negate, } } } return ctx.newBadExpr(directive, "findstring result can be compared only to empty: %s", xValue) return ctx.newBadExpr(directive, "$(findstring) can only be compared to nothing or its first argument") } func (ctx *parseContext) parseCompareStripFuncResult(directive *mkparser.Directive, Loading mk2rbc/mk2rbc_test.go +27 −0 Original line number Diff line number Diff line Loading @@ -633,15 +633,42 @@ def init(g, handle): desc: "findstring call", mkname: "product.mk", in: ` result := $(findstring a,a b c) result := $(findstring b,x y z) `, expected: `load("//build/make/core:product_config.rbc", "rblf") def init(g, handle): cfg = rblf.cfg(handle) _result = rblf.findstring("a", "a b c") _result = rblf.findstring("b", "x y z") `, }, { desc: "findstring in if statement", mkname: "product.mk", in: ` ifeq ($(findstring foo,$(PRODUCT_PACKAGES)),) endif ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),) endif ifeq ($(findstring foo,$(PRODUCT_PACKAGES)),foo) endif ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),foo) endif `, expected: `load("//build/make/core:product_config.rbc", "rblf") def init(g, handle): cfg = rblf.cfg(handle) if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") == -1: pass if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1: pass if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1: pass if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") == -1: pass `, }, { Loading Loading
mk2rbc/mk2rbc.go +15 −2 Original line number Diff line number Diff line Loading @@ -105,7 +105,7 @@ var knownFunctions = map[string]struct { "dist-for-goals": {baseName + ".mkdist_for_goals", starlarkTypeVoid, hiddenArgGlobal}, "enforce-product-packages-exist": {baseName + ".enforce_product_packages_exist", starlarkTypeVoid, hiddenArgNone}, "error": {baseName + ".mkerror", starlarkTypeVoid, hiddenArgNone}, "findstring": {"!findstring", starlarkTypeInt, hiddenArgNone}, "findstring": {baseName + ".findstring", starlarkTypeString, hiddenArgNone}, "find-copy-subdir-files": {baseName + ".find_and_copy", starlarkTypeList, hiddenArgNone}, "find-word-in-list": {"!find-word-in-list", starlarkTypeUnknown, hiddenArgNone}, // internal macro "filter": {baseName + ".filter", starlarkTypeList, hiddenArgNone}, Loading Loading @@ -1288,8 +1288,21 @@ func (ctx *parseContext) parseCheckFindstringFuncResult(directive *mkparser.Dire right: &intLiteralExpr{-1}, isEq: !negate, } } else if s, ok := maybeString(xValue); ok { if s2, ok := maybeString(xCall.args[0]); ok && s == s2 { return &eqExpr{ left: &callExpr{ object: xCall.args[1], name: "find", args: []starlarkExpr{xCall.args[0]}, returnType: starlarkTypeInt, }, right: &intLiteralExpr{-1}, isEq: negate, } } } return ctx.newBadExpr(directive, "findstring result can be compared only to empty: %s", xValue) return ctx.newBadExpr(directive, "$(findstring) can only be compared to nothing or its first argument") } func (ctx *parseContext) parseCompareStripFuncResult(directive *mkparser.Directive, Loading
mk2rbc/mk2rbc_test.go +27 −0 Original line number Diff line number Diff line Loading @@ -633,15 +633,42 @@ def init(g, handle): desc: "findstring call", mkname: "product.mk", in: ` result := $(findstring a,a b c) result := $(findstring b,x y z) `, expected: `load("//build/make/core:product_config.rbc", "rblf") def init(g, handle): cfg = rblf.cfg(handle) _result = rblf.findstring("a", "a b c") _result = rblf.findstring("b", "x y z") `, }, { desc: "findstring in if statement", mkname: "product.mk", in: ` ifeq ($(findstring foo,$(PRODUCT_PACKAGES)),) endif ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),) endif ifeq ($(findstring foo,$(PRODUCT_PACKAGES)),foo) endif ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),foo) endif `, expected: `load("//build/make/core:product_config.rbc", "rblf") def init(g, handle): cfg = rblf.cfg(handle) if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") == -1: pass if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1: pass if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1: pass if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") == -1: pass `, }, { Loading