diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go index 02b3d0859..8d28c8060 100644 --- a/mk2rbc/mk2rbc.go +++ b/mk2rbc/mk2rbc.go @@ -1074,6 +1074,18 @@ func (ctx *parseContext) parseCompare(cond *mkparser.Directive) starlarkExpr { return otherOperand } } + if otherOperand.typ() == starlarkTypeList { + fields := strings.Fields(stringOperand) + elements := make([]starlarkExpr, len(fields)) + for i, s := range fields { + elements[i] = &stringLiteralExpr{literal: s} + } + return &eqExpr{ + left: otherOperand, + right: &listExpr{elements}, + isEq: isEq, + } + } if intOperand, err := strconv.Atoi(strings.TrimSpace(stringOperand)); err == nil && otherOperand.typ() == starlarkTypeInt { return &eqExpr{ left: otherOperand, @@ -1119,8 +1131,6 @@ func (ctx *parseContext) parseCompareSpecialCases(directive *mkparser.Directive, switch call.name { case baseName + ".filter": return ctx.parseCompareFilterFuncResult(directive, call, value, isEq) - case baseName + ".expand_wildcard": - return ctx.parseCompareWildcardFuncResult(directive, call, value, !isEq), true case baseName + ".findstring": return ctx.parseCheckFindstringFuncResult(directive, call, value, !isEq), true case baseName + ".strip": @@ -1165,22 +1175,6 @@ func (ctx *parseContext) parseCompareFilterFuncResult(cond *mkparser.Directive, } } -func (ctx *parseContext) parseCompareWildcardFuncResult(directive *mkparser.Directive, - xCall *callExpr, xValue starlarkExpr, negate bool) starlarkExpr { - if !isEmptyString(xValue) { - return ctx.newBadExpr(directive, "wildcard result can be compared only to empty: %s", xValue) - } - callFunc := baseName + ".file_wildcard_exists" - if s, ok := xCall.args[0].(*stringLiteralExpr); ok && !strings.ContainsAny(s.literal, "*?{[") { - callFunc = baseName + ".file_exists" - } - var cc starlarkExpr = &callExpr{name: callFunc, args: xCall.args, returnType: starlarkTypeBool} - if !negate { - cc = ¬Expr{cc} - } - return cc -} - func (ctx *parseContext) parseCheckFindstringFuncResult(directive *mkparser.Directive, xCall *callExpr, xValue starlarkExpr, negate bool) starlarkExpr { if isEmptyString(xValue) { diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go index 9485a42fc..a190a1056 100644 --- a/mk2rbc/mk2rbc_test.go +++ b/mk2rbc/mk2rbc_test.go @@ -568,14 +568,18 @@ ifeq (,$(wildcard foo.mk)) endif ifneq (,$(wildcard foo*.mk)) endif +ifeq (foo1.mk foo2.mk barxyz.mk,$(wildcard foo*.mk bar*.mk)) +endif `, expected: `load("//build/make/core:product_config.rbc", "rblf") def init(g, handle): cfg = rblf.cfg(handle) - if not rblf.file_exists("foo.mk"): + if not rblf.expand_wildcard("foo.mk"): pass - if rblf.file_wildcard_exists("foo*.mk"): + if rblf.expand_wildcard("foo*.mk"): + pass + if rblf.expand_wildcard("foo*.mk bar*.mk") == ["foo1.mk", "foo2.mk", "barxyz.mk"]:␤ pass `, },