Kindsys: Replace DefForGen with kindsys.Kind (#62642)

* Kindsys: Replace DeclForGen with kindsys.Kind

DeclForGen was always unnecessary - it just wasn't obvious on initial
implementation, when we were focused on generating unique types for each
core kind. This removes it, considerably simplifying interactions with
kindsys - virtually everything now just relies on kindsys.Kind and its
derived interfaces.

* Removed unused jenny

* Rename params in jennies
This commit is contained in:
sam boyer
2023-01-31 19:40:15 -05:00
committed by GitHub
parent 0f0a53fbbb
commit 30b4205521
25 changed files with 273 additions and 543 deletions

View File

@@ -31,8 +31,8 @@ func main() {
// Core kinds composite code generator. Produces all generated code in
// grafana/grafana that derives from core kinds.
coreKindsGen := codejen.JennyListWithNamer(func(def *codegen.DefForGen) string {
return def.Properties.Common().MachineName
coreKindsGen := codejen.JennyListWithNamer(func(def kindsys.Kind) string {
return def.Props().Common().MachineName
})
// All the jennies that comprise the core kinds generator pipeline
@@ -56,28 +56,28 @@ func main() {
groot := filepath.Dir(cwd)
rt := cuectx.GrafanaThemaRuntime()
var all []*codegen.DefForGen
var all []kindsys.Kind
f := os.DirFS(filepath.Join(groot, kindsys.CoreDeclParentPath))
f := os.DirFS(filepath.Join(groot, kindsys.CoreDefParentPath))
kinddirs := elsedie(fs.ReadDir(f, "."))("error reading core kind fs root directory")
for _, ent := range kinddirs {
if !ent.IsDir() {
for _, kinddir := range kinddirs {
if !kinddir.IsDir() {
continue
}
rel := filepath.Join(kindsys.CoreDeclParentPath, ent.Name())
decl, err := kindsys.LoadCoreKind(rel, rt.Context(), nil)
rel := filepath.Join(kindsys.CoreDefParentPath, kinddir.Name())
def, err := kindsys.LoadCoreKindDef(rel, rt.Context(), nil)
if err != nil {
die(fmt.Errorf("%s is not a valid kind: %s", rel, errors.Details(err, nil)))
}
if decl.Properties.MachineName != ent.Name() {
die(fmt.Errorf("%s: kind's machine name (%s) must equal parent dir name (%s)", rel, decl.Properties.Name, ent.Name()))
if def.Properties.MachineName != kinddir.Name() {
die(fmt.Errorf("%s: kind's machine name (%s) must equal parent dir name (%s)", rel, def.Properties.Name, kinddir.Name()))
}
all = append(all, elsedie(codegen.ForGen(rt, decl.Some()))(rel))
all = append(all, elsedie(kindsys.BindCore(rt, def))(rel))
}
sort.Slice(all, func(i, j int) bool {
return nameFor(all[i].Properties) < nameFor(all[j].Properties)
return nameFor(all[i].Props()) < nameFor(all[j].Props())
})
jfs, err := coreKindsGen.GenerateFS(all...)