Merge "Allow comparing $(wildcard) results to non-empty values"
This commit is contained in:
@@ -1074,6 +1074,18 @@ func (ctx *parseContext) parseCompare(cond *mkparser.Directive) starlarkExpr {
|
|||||||
return otherOperand
|
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 {
|
if intOperand, err := strconv.Atoi(strings.TrimSpace(stringOperand)); err == nil && otherOperand.typ() == starlarkTypeInt {
|
||||||
return &eqExpr{
|
return &eqExpr{
|
||||||
left: otherOperand,
|
left: otherOperand,
|
||||||
@@ -1119,8 +1131,6 @@ func (ctx *parseContext) parseCompareSpecialCases(directive *mkparser.Directive,
|
|||||||
switch call.name {
|
switch call.name {
|
||||||
case baseName + ".filter":
|
case baseName + ".filter":
|
||||||
return ctx.parseCompareFilterFuncResult(directive, call, value, isEq)
|
return ctx.parseCompareFilterFuncResult(directive, call, value, isEq)
|
||||||
case baseName + ".expand_wildcard":
|
|
||||||
return ctx.parseCompareWildcardFuncResult(directive, call, value, !isEq), true
|
|
||||||
case baseName + ".findstring":
|
case baseName + ".findstring":
|
||||||
return ctx.parseCheckFindstringFuncResult(directive, call, value, !isEq), true
|
return ctx.parseCheckFindstringFuncResult(directive, call, value, !isEq), true
|
||||||
case baseName + ".strip":
|
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,
|
func (ctx *parseContext) parseCheckFindstringFuncResult(directive *mkparser.Directive,
|
||||||
xCall *callExpr, xValue starlarkExpr, negate bool) starlarkExpr {
|
xCall *callExpr, xValue starlarkExpr, negate bool) starlarkExpr {
|
||||||
if isEmptyString(xValue) {
|
if isEmptyString(xValue) {
|
||||||
|
@@ -568,14 +568,18 @@ ifeq (,$(wildcard foo.mk))
|
|||||||
endif
|
endif
|
||||||
ifneq (,$(wildcard foo*.mk))
|
ifneq (,$(wildcard foo*.mk))
|
||||||
endif
|
endif
|
||||||
|
ifeq (foo1.mk foo2.mk barxyz.mk,$(wildcard foo*.mk bar*.mk))
|
||||||
|
endif
|
||||||
`,
|
`,
|
||||||
expected: `load("//build/make/core:product_config.rbc", "rblf")
|
expected: `load("//build/make/core:product_config.rbc", "rblf")
|
||||||
|
|
||||||
def init(g, handle):
|
def init(g, handle):
|
||||||
cfg = rblf.cfg(handle)
|
cfg = rblf.cfg(handle)
|
||||||
if not rblf.file_exists("foo.mk"):
|
if not rblf.expand_wildcard("foo.mk"):
|
||||||
pass
|
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
|
pass
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user