All of mesh-build-go's buildstep Go module leaves mesh-catalog for modules/mesh-delivery-sdk: the step run, fetch and release and the regenerate-and-compare step as the package steprun, the CPU share as steprun/buildcpu, the conformance kit as steprun/conformance, the seat generator as seatgen with cmd/seatgen, and cmd/mesh-pack. The three build modules and the builder's and checker's tests import the SDK and keep no copy; the SDK requires nothing of mesh-catalog. Code the build modules share is the delivery domain's SDK, not one module's package. It carries the build-module round's two new files of that package (dropdetected.go 247c422f, storedbuilds.go 904b8aed). Builds: design 47 G §464, §680, §327, §420, §495 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
73 lines
2.6 KiB
Go
73 lines
2.6 KiB
Go
package seatgen
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
re "regexp"
|
|
"strings"
|
|
)
|
|
|
|
// callerName is a seat's or a module's name inside a caller entry.
|
|
var callerName = re.MustCompile(`^[a-z][a-z0-9]*(-[a-z0-9]+)*$`)
|
|
|
|
// callerClasses are the entries that take no name (design 47 G §336, §392).
|
|
var callerClasses = map[string]bool{"operator": true, "healers": true, "persons": true, "sessions": true, "invokers": true}
|
|
|
|
// callerForm says whether an entry is one of the forms of design 47 G §336 as §392 writes them: `operator`, `healers`,
|
|
// `persons`, `sessions`, `invokers`, `seat:<seat>`, `module:<module>` and `holder:<seat>@same-node`.
|
|
func callerForm(entry string) bool {
|
|
switch {
|
|
case callerClasses[entry]:
|
|
return true
|
|
case strings.HasPrefix(entry, "seat:"):
|
|
return callerName.MatchString(strings.TrimPrefix(entry, "seat:"))
|
|
case strings.HasPrefix(entry, "module:"):
|
|
return callerName.MatchString(strings.TrimPrefix(entry, "module:"))
|
|
case strings.HasPrefix(entry, "holder:") && strings.HasSuffix(entry, "@same-node"):
|
|
return callerName.MatchString(strings.TrimSuffix(strings.TrimPrefix(entry, "holder:"), "@same-node"))
|
|
}
|
|
return false
|
|
}
|
|
|
|
// checkCallers refuses a definition or part whose verb or accepted kind names a `callers` that is no list of the
|
|
// forms of §336, naming the entry (design 47 G §339: the generator reads `callers` and makes nothing of it; the
|
|
// grants part reads them from the definition). Text, the old form, is refused as one entry.
|
|
func checkCallers(file string, raw []byte) error {
|
|
var doc struct {
|
|
Verbs []callerHolder `json:"verbs"`
|
|
Accepts []callerHolder `json:"accepts"`
|
|
}
|
|
if err := json.Unmarshal(raw, &doc); err != nil {
|
|
return nil // the definition reader names a malformed file
|
|
}
|
|
for _, group := range []struct {
|
|
field string
|
|
items []callerHolder
|
|
}{{"verbs", doc.Verbs}, {"accepts", doc.Accepts}} {
|
|
for _, it := range group.items {
|
|
if len(it.Callers) == 0 {
|
|
continue
|
|
}
|
|
var list []string
|
|
if err := json.Unmarshal(it.Callers, &list); err != nil {
|
|
var text string
|
|
if json.Unmarshal(it.Callers, &text) != nil {
|
|
return fmt.Errorf("%s: %s %q: callers is neither a list nor text", file, group.field, it.Name)
|
|
}
|
|
list = []string{text}
|
|
}
|
|
for _, e := range list {
|
|
if !callerForm(e) {
|
|
return fmt.Errorf("%s: %s %q: caller %q is no form of the format (operator, healers, persons, sessions, invokers, seat:<seat>, module:<module>, holder:<seat>@same-node)", file, group.field, it.Name, e)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type callerHolder struct {
|
|
Name string `json:"name"`
|
|
Callers json.RawMessage `json:"callers"`
|
|
}
|