feat(build): bake plugin metadata and the framework version into plugins.gen.go
- party.Info, party.Installed, party.Describe (additive; Plugin and Activate unchanged) - summer build resolves plugin dirs with one go list, reads plugin.yaml, versions per D-07 (module version, git describe without --dirty, none for in-app plugins) - build.EffectiveFramework: newest tag of a locally replaced or used framework checkout, else the go.mod require - generated main calls party.Describe(app, PluginInfo, FrameworkVersion) before Activate; metadata failures warn and fall back to IDs - summer new goldens and examples/hello regenerated
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/party"
|
||||
)
|
||||
|
||||
// App generates app sources from summer.yaml and runs go build in appDir.
|
||||
@@ -34,7 +36,11 @@ func App(ctx context.Context, appDir string, out io.Writer) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := generate(appDir, m); err != nil {
|
||||
meta, warnings := resolveBuildMeta(ctx, appDir, m)
|
||||
for _, w := range warnings {
|
||||
fmt.Fprintf(out, "warning: %s\n", w)
|
||||
}
|
||||
if err := generate(appDir, m, meta); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := checkModelsLeaf(appDir, m); err != nil {
|
||||
@@ -73,12 +79,12 @@ func goBuildArgs(binRel string, tags []string) []string {
|
||||
return append(args, "-o", binRel, ".")
|
||||
}
|
||||
|
||||
func generate(appDir string, m Manifest) error {
|
||||
func generate(appDir string, m Manifest, meta buildMeta) error {
|
||||
mainSrc, err := generateMain(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pluginsSrc, err := generatePluginsGen(m)
|
||||
pluginsSrc, err := generatePluginsGen(m, meta)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -122,6 +128,7 @@ func generateMain(m Manifest) ([]byte, error) {
|
||||
b.WriteString("\tif err != nil {\n" + fail + "\t}\n")
|
||||
b.WriteString("\tif err := diary.Setup(cfg, diary.FromGlobals(g)); err != nil {\n" + fail + "\t}\n")
|
||||
b.WriteString("\tapp := backpack.New(cfg)\n")
|
||||
b.WriteString("\tif err := party.Describe(app, PluginInfo, FrameworkVersion); err != nil {\n" + fail + "\t}\n")
|
||||
b.WriteString("\tplugins, err := party.Activate(app, PluginIDs)\n")
|
||||
b.WriteString("\tif err != nil {\n" + fail + "\t}\n")
|
||||
b.WriteString("\tcommands := lagoon.RuntimeCommands(app, plugins)\n")
|
||||
@@ -142,26 +149,72 @@ func generateMain(m Manifest) ([]byte, error) {
|
||||
return formatSource([]byte(b.String()))
|
||||
}
|
||||
|
||||
func generatePluginsGen(m Manifest) ([]byte, error) {
|
||||
// generatePluginsGen writes plugins.gen.go: the blank plugin imports, the
|
||||
// ordered PluginIDs, the PluginInfo metadata and FrameworkVersion. Every
|
||||
// baked string goes through strconv.Quote.
|
||||
func generatePluginsGen(m Manifest, meta buildMeta) ([]byte, error) {
|
||||
var b strings.Builder
|
||||
b.WriteString("// Code generated by summer build. DO NOT EDIT.\n\n")
|
||||
b.WriteString("package main\n\n")
|
||||
if len(m.Plugins) > 0 {
|
||||
b.WriteString("import (\n")
|
||||
for _, p := range m.Plugins {
|
||||
fmt.Fprintf(&b, "\t_ %s\n", strconv.Quote(p.Module))
|
||||
}
|
||||
b.WriteString(")\n\n")
|
||||
b.WriteString("import (\n")
|
||||
for _, p := range m.Plugins {
|
||||
fmt.Fprintf(&b, "\t_ %s\n", strconv.Quote(p.Module))
|
||||
}
|
||||
if len(m.Plugins) > 0 {
|
||||
b.WriteString("\n")
|
||||
}
|
||||
b.WriteString("\t\"git.golem15.com/golem15/summercms/modules/party\"\n")
|
||||
b.WriteString(")\n\n")
|
||||
b.WriteString("// PluginIDs is the ordered plugin list from summer.yaml.\n")
|
||||
b.WriteString("var PluginIDs = []string{\n")
|
||||
for _, p := range m.Plugins {
|
||||
fmt.Fprintf(&b, "\t%s,\n", strconv.Quote(p.ID))
|
||||
}
|
||||
b.WriteString("}\n")
|
||||
b.WriteString("}\n\n")
|
||||
b.WriteString("// PluginInfo is each plugin's metadata in summer.yaml order: name and\n")
|
||||
b.WriteString("// description from its plugin.yaml, version and source from summer build.\n")
|
||||
b.WriteString("var PluginInfo = []party.Info{\n")
|
||||
for i, p := range m.Plugins {
|
||||
info := party.Info{ID: p.ID}
|
||||
if i < len(meta.Plugins) && meta.Plugins[i].ID == p.ID {
|
||||
info = meta.Plugins[i]
|
||||
}
|
||||
fmt.Fprintf(&b, "\t{%s},\n", infoLiteral(info))
|
||||
}
|
||||
b.WriteString("}\n\n")
|
||||
b.WriteString("// FrameworkVersion is the framework version the app was built against.\n")
|
||||
fmt.Fprintf(&b, "const FrameworkVersion = %s\n", strconv.Quote(meta.Framework))
|
||||
return formatSource([]byte(b.String()))
|
||||
}
|
||||
|
||||
// infoLiteral is the field list of a party.Info composite literal with the
|
||||
// empty fields left out.
|
||||
func infoLiteral(info party.Info) string {
|
||||
fields := []string{"ID: " + strconv.Quote(info.ID)}
|
||||
add := func(name, v string) {
|
||||
if v != "" {
|
||||
fields = append(fields, name+": "+strconv.Quote(v))
|
||||
}
|
||||
}
|
||||
add("Module", info.Module)
|
||||
add("Package", info.Package)
|
||||
add("Name", info.Name)
|
||||
add("Description", info.Description)
|
||||
add("Version", info.Version)
|
||||
switch info.Source {
|
||||
case "":
|
||||
case party.SourceModule:
|
||||
fields = append(fields, "Source: party.SourceModule")
|
||||
case party.SourceSubmodule:
|
||||
fields = append(fields, "Source: party.SourceSubmodule")
|
||||
case party.SourceLocal:
|
||||
fields = append(fields, "Source: party.SourceLocal")
|
||||
default:
|
||||
fields = append(fields, "Source: "+strconv.Quote(info.Source))
|
||||
}
|
||||
return strings.Join(fields, ", ")
|
||||
}
|
||||
|
||||
func formatSource(src []byte) ([]byte, error) {
|
||||
formatted, err := format.Source(src)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user