// Command mesh-checking-program is the checker's checking program (novox/hq ADR 0644, ADR 0656; design 47's bootstrap // delivery): built from a check's heads and run in the build seat's sandbox through the seat node-build-go's ask run, // with no network and no bus account, it reads the check's facts from the file MESH_RUN_INPUT names and answers the // verdict the judging rules give them, as one JSON line on its standard output (rules.Answer). // // mesh-checking-program -verdict // mesh-checking-program -seats // // Asked -seats, it answers the seat list of the heads laid in the directory MESH_RUN_HEADS names (rules.SeatsAnswer). // It refuses facts of a version it does not read, naming it, with exit 2. package main import ( "fmt" "io" "io/fs" "os" "slices" "mesh-delivery-checker/rules" "git.novox.be/novox/mesh-delivery/sdk/buildstep" ) func main() { os.Exit(run(os.Args[1:], os.Getenv, os.Stdout, os.Stderr)) } // run is the command over its arguments, environment and outputs, answering its exit. func run(args []string, getenv func(string) string, stdout, stderr io.Writer) int { var heads fs.FS if dir := getenv(buildstep.RunHeadsEnv); dir != "" { heads = os.DirFS(dir) } input := func() ([]byte, error) { file := getenv(buildstep.RunInputEnv) if file == "" { return nil, fmt.Errorf("%s names no file", buildstep.RunInputEnv) } return os.ReadFile(file) } line, err := rules.Program(args, input, heads) if err != nil { if heads == nil && slices.Contains(args, "-seats") { err = fmt.Errorf("no heads: %s names no directory", buildstep.RunHeadsEnv) } fmt.Fprintf(stderr, "mesh-checking-program: %v\n", err) return 2 } fmt.Fprintf(stdout, "%s\n", line) return 0 }