Merge "Call rblf.setDefault() when appending to a variable without +="
This commit is contained in:
@@ -993,6 +993,7 @@ endif
|
|||||||
def init(g, handle):
|
def init(g, handle):
|
||||||
cfg = rblf.cfg(handle)
|
cfg = rblf.cfg(handle)
|
||||||
if "hwaddress" not in cfg.get("PRODUCT_PACKAGES", []):
|
if "hwaddress" not in cfg.get("PRODUCT_PACKAGES", []):
|
||||||
|
rblf.setdefault(handle, "PRODUCT_PACKAGES")
|
||||||
cfg["PRODUCT_PACKAGES"] = (rblf.mkstrip("%s hwaddress" % " ".join(cfg.get("PRODUCT_PACKAGES", [])))).split()
|
cfg["PRODUCT_PACKAGES"] = (rblf.mkstrip("%s hwaddress" % " ".join(cfg.get("PRODUCT_PACKAGES", [])))).split()
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
@@ -88,20 +88,33 @@ func (pcv productConfigVariable) emitSet(gctx *generationContext, asgn *assignme
|
|||||||
}
|
}
|
||||||
value.emit(gctx)
|
value.emit(gctx)
|
||||||
}
|
}
|
||||||
|
emitSetDefault := func() {
|
||||||
switch asgn.flavor {
|
|
||||||
case asgnSet:
|
|
||||||
emitAssignment()
|
|
||||||
case asgnAppend:
|
|
||||||
emitAppend()
|
|
||||||
case asgnMaybeAppend:
|
|
||||||
// If we are not sure variable has been assigned before, emit setdefault
|
|
||||||
if pcv.typ == starlarkTypeList {
|
if pcv.typ == starlarkTypeList {
|
||||||
gctx.writef("%s(handle, %q)", cfnSetListDefault, pcv.name())
|
gctx.writef("%s(handle, %q)", cfnSetListDefault, pcv.name())
|
||||||
} else {
|
} else {
|
||||||
gctx.writef("cfg.setdefault(%q, %s)", pcv.name(), pcv.defaultValueString())
|
gctx.writef("cfg.setdefault(%q, %s)", pcv.name(), pcv.defaultValueString())
|
||||||
}
|
}
|
||||||
gctx.newLine()
|
gctx.newLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
switch asgn.flavor {
|
||||||
|
case asgnSet:
|
||||||
|
isSelfReferential := false
|
||||||
|
asgn.value.transform(func(expr starlarkExpr) starlarkExpr {
|
||||||
|
if ref, ok := expr.(*variableRefExpr); ok && ref.ref.name() == pcv.name() {
|
||||||
|
isSelfReferential = true
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if isSelfReferential {
|
||||||
|
emitSetDefault()
|
||||||
|
}
|
||||||
|
emitAssignment()
|
||||||
|
case asgnAppend:
|
||||||
|
emitAppend()
|
||||||
|
case asgnMaybeAppend:
|
||||||
|
// If we are not sure variable has been assigned before, emit setdefault
|
||||||
|
emitSetDefault()
|
||||||
emitAppend()
|
emitAppend()
|
||||||
case asgnMaybeSet:
|
case asgnMaybeSet:
|
||||||
gctx.writef("if cfg.get(%q) == None:", pcv.nam)
|
gctx.writef("if cfg.get(%q) == None:", pcv.nam)
|
||||||
|
Reference in New Issue
Block a user