Remove variableDefinedExpr
VariableDefinedExpr was under-developed, and would not take into account if a variable was from the globals or product config dictionary. It also always emitted `g.get("VARIABLE") != None`, which is not correct behavior. In this example makefile: ``` MY_VAR := ifdef MY_VAR $(info MY_VAR is defined) else $(info MY_VAR is not defined) endif ifdef MY_UNDEFINED_VAR $(info MY_UNDEFINED_VAR is defined) else $(info MY_UNDEFINED_VAR is not defined) endif MY_VAR ?= true MY_UNDEFINED_VAR ?= true $(info MY_VAR after ?= is $(MY_VAR)) $(info MY_UNDEFINED_VAR after ?= is $(MY_UNDEFINED_VAR)) .PHONY: all all: @: ``` We get the output: MY_VAR is not defined MY_UNDEFINED_VAR is not defined MY_VAR after ?= is MY_UNDEFINED_VAR after ?= is true So we can see that even if a variable was set, it's considered not defined if it was set to an empty value. However, ?= works differently, and does require the != None, so that was left as is. Just use a variableRefExpr and rely on the fact that variables will be truthy if they're defined. Fixes: 216700361 Test: go test Change-Id: If8944da2579e8658e3fc4f666b1f3b2815f8c8b1
This commit is contained in:
@@ -378,32 +378,6 @@ func (eq *eqExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) st
|
||||
}
|
||||
}
|
||||
|
||||
// variableDefinedExpr corresponds to Make's ifdef VAR
|
||||
type variableDefinedExpr struct {
|
||||
v variable
|
||||
}
|
||||
|
||||
func (v *variableDefinedExpr) emit(gctx *generationContext) {
|
||||
if v.v != nil {
|
||||
v.v.emitDefined(gctx)
|
||||
return
|
||||
}
|
||||
gctx.writef("%s(%q)", cfnWarning, "TODO(VAR)")
|
||||
}
|
||||
|
||||
func (_ *variableDefinedExpr) typ() starlarkType {
|
||||
return starlarkTypeBool
|
||||
}
|
||||
|
||||
func (v *variableDefinedExpr) emitListVarCopy(gctx *generationContext) {
|
||||
v.emit(gctx)
|
||||
}
|
||||
|
||||
func (v *variableDefinedExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr {
|
||||
// TODO: VariableDefinedExpr isn't really an expression?
|
||||
return v
|
||||
}
|
||||
|
||||
type listExpr struct {
|
||||
items []starlarkExpr
|
||||
}
|
||||
|
Reference in New Issue
Block a user