codejen: Update to latest codejen (#58866)
This commit is contained in:
@@ -34,12 +34,20 @@ func ForGen(rt *thema.Runtime, decl *kindsys.SomeDecl) (*DeclForGen, error) {
|
||||
type DeclForGen struct {
|
||||
*kindsys.SomeDecl
|
||||
lin thema.Lineage
|
||||
sch thema.Lineage
|
||||
}
|
||||
|
||||
// Lineage returns the [thema.Lineage] for the underlying [kindsys.SomeDecl].
|
||||
func (decl *DeclForGen) Lineage() thema.Lineage {
|
||||
return decl.lin
|
||||
}
|
||||
|
||||
// Schema returns the [thema.Schema] that a jenny should operate against, for those
|
||||
// jennies that target a single schema.
|
||||
func (decl *DeclForGen) Schema() thema.Lineage {
|
||||
return decl.sch
|
||||
}
|
||||
|
||||
// SlashHeaderMapper produces a FileMapper that injects a comment header onto
|
||||
// a [codejen.File] indicating the main generator that produced it (via the provided
|
||||
// maingen, which should be a path) and the jenny or jennies that constructed the
|
||||
|
||||
@@ -31,7 +31,7 @@ func (gen *genBaseRegistry) JennyName() string {
|
||||
return "BaseCoreRegistryJenny"
|
||||
}
|
||||
|
||||
func (gen *genBaseRegistry) Generate(decls []*DeclForGen) (*codejen.File, error) {
|
||||
func (gen *genBaseRegistry) Generate(decls ...*DeclForGen) (*codejen.File, error) {
|
||||
var numRaw int
|
||||
for _, k := range decls {
|
||||
if k.IsRaw() {
|
||||
|
||||
@@ -39,7 +39,7 @@ func (gen *genTSVeneerIndex) JennyName() string {
|
||||
return "TSVeneerIndexJenny"
|
||||
}
|
||||
|
||||
func (gen *genTSVeneerIndex) Generate(decls []*DeclForGen) (*codejen.File, error) {
|
||||
func (gen *genTSVeneerIndex) Generate(decls ...*DeclForGen) (*codejen.File, error) {
|
||||
tsf := new(ast.File)
|
||||
for _, decl := range decls {
|
||||
if decl.IsRaw() {
|
||||
|
||||
@@ -10,7 +10,7 @@ This document is the guide to extending kindsys. But first, we have to identify
|
||||
|
||||
* **CUE framework** - the collection of .cue files in this directory, `pkg/kindsys`. These are schemas that define how Kinds are declared.
|
||||
* **Go framework** - the Go package in this directory containing utilities for loading individual kind declarations, validating them against the CUE framework, and representing them consistently in Go.
|
||||
* **Code generators** - `pkg/codegen` contains the codegen framework. Individual generators (which take one or many `pkg/kindsys.Decl`, and produce a single file) each have a `pkg/codegen/generator_*.go` file.
|
||||
* **Code generators** - written using the `github.com/grafana/codejen` framework, which applies the [single responsibility principle](https://en.wikipedia.org/wiki/Single-responsibility_principle) to code generation, allowing us to compose modular code generators. Each jenny - a modular generator with a single responsibility - is declared as a `pkg/codegen/jenny_*.go` file.
|
||||
* **Registries** - generated lists of all or a well-defined subset of kinds that can be used in code. `pkg/registries/corekind` is a registry of all core `pkg/kindsys.Interface` implementations; `packages/grafana-schema/src/index.gen.ts` is a registry of all the TypeScript types generated from the current versions of each kind's schema.
|
||||
* **Kind declarations** - the declarations of individual kinds. By kind category:
|
||||
* **Core Structured** - each child directory of `kinds/structured`.
|
||||
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
grootp := strings.Split(cwd, string(os.PathSeparator))
|
||||
groot := filepath.Join(string(os.PathSeparator), filepath.Join(grootp[:len(grootp)-3]...))
|
||||
|
||||
jfs := elsedie(jl.GenerateFS([]thema.Lineage{lin}))("plugindef jenny pipeline failed")
|
||||
jfs := elsedie(jl.GenerateFS(lin))("plugindef jenny pipeline failed")
|
||||
if _, set := os.LookupEnv("CODEGEN_VERIFY"); set {
|
||||
if err := jfs.Verify(context.Background(), groot); err != nil {
|
||||
die(fmt.Errorf("generated code is out of sync with inputs:\n%s\nrun `make gen-cue` to regenerate", err))
|
||||
|
||||
Reference in New Issue
Block a user