diff --git a/pkg/project/expander.go b/pkg/project/expander.go index 67b33a5a4d..7fa8937b48 100644 --- a/pkg/project/expander.go +++ b/pkg/project/expander.go @@ -291,6 +291,22 @@ func makeEntryMapMap(structure reflect.Value) map[string]map[string]entry { return m } +func makeLazyExpanderFuncFromPtrToStruct(val reflect.Value) ExpanderFunc { + return func(v, name, meta string, isFunc bool, ctx *Expansion) (string, error) { + iface := val.Interface() + if u, ok := iface.(interface{ Update(*Project) }); ok { + u.Update(ctx.Project) + } + + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + fn := makeExpanderFuncFromMap(makeEntryMapMap(val)) + + return fn(v, name, meta, isFunc, ctx) + } +} + func makeExpanderFuncFromMap(m map[string]map[string]entry) ExpanderFunc { return func(v, name, meta string, isFunc bool, ctx *Expansion) (string, error) { if isFunc && meta == "()" { diff --git a/pkg/project/project.go b/pkg/project/project.go index ffd8c988dd..4eb646478e 100644 --- a/pkg/project/project.go +++ b/pkg/project/project.go @@ -58,13 +58,6 @@ func (p *Project) SetCommit(commitID string) error { return p.Source().SetCommit(commitID, p.IsHeadless()) } -func (p *Project) SetUpdateCallback(fn func()) { - if p.projectfile == nil { - return - } - p.projectfile.SetUpdateCallback(fn) -} - // Constants returns a reference to projectfile.Constants func (p *Project) Constants() []*Constant { constrained, err := constraints.FilterUnconstrained(pConditional, p.projectfile.Constants.AsConstrainedEntities()) diff --git a/pkg/project/registry.go b/pkg/project/registry.go index c4402d9bc2..b4e6caba3a 100644 --- a/pkg/project/registry.go +++ b/pkg/project/registry.go @@ -31,55 +31,7 @@ func init() { } } -func RegisterTopLevelStruct(name string, val interface{}) error { - v := reflect.ValueOf(val) - if v.Kind() == reflect.Ptr { - v = v.Elem() - } - - m := makeEntryMapMap(v) - name = strings.ToLower(name) - err := RegisterExpander(name, makeExpanderFuncFromMap(m)) - if err != nil { - return locale.WrapError( - err, "project_expand_register_expander_map", - "Cannot register expander (map)", - ) - } - - return nil -} - -func RegisterTopLevelFunc(name string, val interface{}) error { - v := reflect.ValueOf(val) - if v.Kind() == reflect.Ptr { - v = v.Elem() - } - - name = strings.ToLower(name) - err := RegisterExpander(name, makeExpanderFuncFromFunc(v)) - if err != nil { - return locale.WrapError( - err, "project_expand_register_expander_func", - "Cannot register expander (func)", - ) - } - - return nil -} - -func RegisterTopLevelStringer(name string, val interface{}) error { - v := reflect.ValueOf(val) - if v.Kind() == reflect.Ptr { - v = v.Elem() - } - - topLevelLookup[strings.ToLower(name)] = fmt.Sprintf("%v", v.Interface()) - - return nil -} - -/*func RegisterStruct(val interface{}) error { +func RegisterStruct(val interface{}) error { v := reflect.ValueOf(val) // deref if needed if v.Kind() == reflect.Ptr { @@ -95,6 +47,7 @@ func RegisterTopLevelStringer(name string, val interface{}) error { } d1Val := v.FieldByIndex(f.Index) + d1ValOrig := d1Val if d1Val.Kind() == reflect.Ptr { d1Val = d1Val.Elem() } @@ -105,9 +58,8 @@ func RegisterTopLevelStringer(name string, val interface{}) error { switch d1Val.Type().Kind() { // Convert type (to map-map) to express advanced control like tag handling. case reflect.Struct: - m := makeEntryMapMap(d1Val) name := strings.ToLower(f.Name) - err := RegisterExpander(name, makeExpanderFuncFromMap(m)) + err := RegisterExpander(name, makeLazyExpanderFuncFromPtrToStruct(d1ValOrig)) if err != nil { return locale.WrapError( err, "project_expand_register_expander_map", @@ -133,7 +85,7 @@ func RegisterTopLevelStringer(name string, val interface{}) error { } return nil -}*/ +} // RegisterExpander registers an Expander Func for some given handler value. The handler value // must not effectively be a blank string and the Func must be defined. It is definitely possible