coremodels: Update to latest Thema with generics (#56602)
* Update thema to latest * Deal with s/Library/*Runtime/ * Commit new, working results of codegen
This commit is contained in:
@@ -18,8 +18,8 @@ var currentVersion = thema.SV({{ .LatestSeqv }}, {{ .LatestSchv }})
|
||||
{{- if .IsComposed }}//
|
||||
// This is the base variant of the schema. It does not include any composed
|
||||
// plugin schemas.{{ end }}
|
||||
func Lineage(lib thema.Library, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
return cuectx.LoadGrafanaInstancesWithThema(filepath.Join("pkg", "coremodel", "{{ .Name }}"), cueFS, lib, opts...)
|
||||
func Lineage(rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
return cuectx.LoadGrafanaInstancesWithThema(filepath.Join("pkg", "coremodel", "{{ .Name }}"), cueFS, rt, opts...)
|
||||
}
|
||||
|
||||
var _ thema.LineageFactory = Lineage
|
||||
@@ -52,8 +52,8 @@ func (c *Coremodel) GoType() interface{} {
|
||||
// Note that this function does not cache, and initially loading a Thema lineage
|
||||
// can be expensive. As such, the Grafana backend should prefer to access this
|
||||
// coremodel through a registry (pkg/framework/coremodel/registry), which does cache.
|
||||
func New(lib thema.Library) (*Coremodel, error) {
|
||||
lin, err := Lineage(lib)
|
||||
func New(rt *thema.Runtime) (*Coremodel, error) {
|
||||
lin, err := Lineage(rt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ func (b *Base) {{ .TitleName }}() *{{ .Name }}.Coremodel {
|
||||
}
|
||||
{{end}}
|
||||
|
||||
func doProvideBase(lib thema.Library) *Base {
|
||||
func doProvideBase(rt *thema.Runtime) *Base {
|
||||
var err error
|
||||
reg := &Base{}
|
||||
|
||||
{{range .Coremodels }}
|
||||
reg.{{ .Name }}, err = {{ .Name }}.New(lib)
|
||||
reg.{{ .Name }}, err = {{ .Name }}.New(rt)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("error while initializing {{ .Name }} coremodel: %s", err))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ var currentVersion{{ .SlotName }} = thema.SV({{ .LatestSeqv }}, {{ .LatestSchv }
|
||||
|
||||
// {{ .SlotName }}Lineage returns the Thema lineage for the {{ .PluginID }} {{ .PluginType }} plugin's
|
||||
// {{ .SlotName }} ["github.com/grafana/grafana/pkg/framework/coremodel".Slot] implementation.
|
||||
func {{ .SlotName }}Lineage(lib thema.Library, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
return cuectx.LoadGrafanaInstancesWithThema(filepath.Join("public", "app", "{{ .Name }}"), cueFS, lib, opts...)
|
||||
func {{ .SlotName }}Lineage(rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
return cuectx.LoadGrafanaInstancesWithThema(filepath.Join("public", "app", "{{ .Name }}"), cueFS, rt, opts...)
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ var ptree *pfs.Tree
|
||||
var plugFS embed.FS
|
||||
|
||||
// PluginTree returns the plugin tree representing the statically analyzable contents of the {{ .PluginID }} plugin.
|
||||
func PluginTree(lib *thema.Library) *pfs.Tree {
|
||||
func PluginTree(rt *thema.Runtime) *pfs.Tree {
|
||||
var err error
|
||||
if lib == nil {
|
||||
if rt == nil || rt == cuectx.GrafanaThemaRuntime() {
|
||||
parseOnce.Do(func() {
|
||||
ptree, err = pfs.ParsePluginFS(plugFS, cuectx.ProvideThemaLibrary())
|
||||
ptree, err = pfs.ParsePluginFS(plugFS, cuectx.GrafanaThemaRuntime())
|
||||
})
|
||||
} else {
|
||||
ptree, err = pfs.ParsePluginFS(plugFS, cuectx.ProvideThemaLibrary())
|
||||
ptree, err = pfs.ParsePluginFS(plugFS, rt)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -40,8 +40,8 @@ func PluginTree(lib *thema.Library) *pfs.Tree {
|
||||
{{ $pluginfo := . }}{{ range $slot := .SlotImpls }}
|
||||
// {{ .SlotName }}Lineage returns the Thema lineage for the {{ $pluginfo.PluginID }} {{ $pluginfo.PluginType }} plugin's
|
||||
// {{ .SlotName }} ["github.com/grafana/grafana/pkg/framework/coremodel".Slot] implementation.
|
||||
func {{ .SlotName }}Lineage(lib *thema.Library, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
t := PluginTree(lib)
|
||||
func {{ .SlotName }}Lineage(rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
t := PluginTree(rt)
|
||||
lin, has := t.RootPlugin().SlotImplementations()["{{ .SlotName }}"]
|
||||
if !has {
|
||||
panic("unreachable: lineage for {{ .SlotName }} does not exist, but code is only generated for existing lineages")
|
||||
|
||||
@@ -10,22 +10,22 @@ import (
|
||||
"github.com/grafana/thema"
|
||||
)
|
||||
|
||||
func makeTreeOrPanic(path string, pkgname string, lib thema.Library) *pfs.Tree {
|
||||
func makeTreeOrPanic(path string, pkgname string, rt *thema.Runtime) *pfs.Tree {
|
||||
sub, err := fs.Sub(grafana.CueSchemaFS, path)
|
||||
if err != nil {
|
||||
panic("could not create fs sub to " + path)
|
||||
}
|
||||
tree, err := pfs.ParsePluginFS(sub, lib)
|
||||
tree, err := pfs.ParsePluginFS(sub, rt)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("error parsing plugin metadata for %s: %s", pkgname, err))
|
||||
}
|
||||
return tree
|
||||
}
|
||||
|
||||
func coreTreeList(lib thema.Library) pfs.TreeList{
|
||||
func coreTreeList(rt *thema.Runtime) pfs.TreeList{
|
||||
return pfs.TreeList{
|
||||
{{- range .Plugins }}
|
||||
makeTreeOrPanic("{{ .Path }}", "{{ .PkgName }}", lib),
|
||||
makeTreeOrPanic("{{ .Path }}", "{{ .PkgName }}", rt),
|
||||
{{- end }}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
{{ if .NoAlias }}{{ .PkgName }} {{end}}"{{ .Path }}"{{ end }}
|
||||
)
|
||||
|
||||
func coreTreeLoaders() []func(*thema.Library) *pfs.Tree{
|
||||
return []func(*thema.Library) *pfs.Tree{
|
||||
func coreTreeLoaders() []func(*thema.Runtime) *pfs.Tree{
|
||||
return []func(*thema.Runtime) *pfs.Tree{
|
||||
{{- range .Plugins }}
|
||||
{{ .PkgName }}.PluginTree,{{ end }}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user