BG5, BN5, BG6, BN6 (toolchain part): toolchain-reported on the seat's subject, with the toolchain program's digest
The guard's toolchains value carries the sha256 of the go or node program found on the path (read again when the version changes); toolchain-reported is said on the build seat's subject of the node at start and on each change of version, recipe or digest; a build's ToolchainUsed names the digest. The legacy toolchain.reported emit and its stream go: nobody consumes them. Builds: design 47 G §492, §472, §466 (lead answer A-152) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -64,9 +65,15 @@ type Module struct {
|
||||
ForgetPause func(key string) error
|
||||
// WatchPauses follows the drops other holders write in the shared pauses state (stdio.State(...).Watch).
|
||||
WatchPauses func(key string, handle func(stdio.StateChange) error) error
|
||||
// Emit tells the bus an event (stdio.Emit); nil emits nothing. The guard emits toolchain.reported after each write of
|
||||
// the toolchains key, so the indexer, which holds no timer, learns that the bucket exists (issue 1444).
|
||||
Emit func(eventType string, body any) error
|
||||
// SayToolchain says an event on a seat's subject (stdio.SeatPublish; nil says none, a test's); ToolchainProgram finds the
|
||||
// node program whose digest the toolchain's is (exec.LookPath when nil).
|
||||
SayToolchain func(subject string, body any, id string) error
|
||||
ToolchainProgram func() (string, error)
|
||||
reporterOnce sync.Once
|
||||
reporter *toolchainReporter
|
||||
digestMu sync.Mutex
|
||||
digestFor string
|
||||
progDigest string
|
||||
// Ctx is the process's context, which a step runs under (the tool call's is cut at 30 s, the step's is not).
|
||||
Ctx context.Context
|
||||
Say func(format string, a ...any)
|
||||
@@ -266,20 +273,38 @@ func pathOrDefault() string {
|
||||
return defaultPath
|
||||
}
|
||||
|
||||
// ToolchainReported is the event the guard emits after it writes the toolchains key.
|
||||
const ToolchainReported = "toolchain.reported"
|
||||
|
||||
// reportingPut is the toolchains Put that then emits toolchain.reported with the node and the language. A write that
|
||||
// failed emits nothing; an emit that failed is said and does not refuse the step.
|
||||
// reportingPut is the toolchains Put that then says toolchain-reported on the Node build seat's subject of this node when
|
||||
// the toolchain changed (design 47 G §492): at the module's start and on each change of the key. A write that failed
|
||||
// says nothing; an event that failed is said and does not refuse the step.
|
||||
func (m *Module) reportingPut() buildstep.Put {
|
||||
return func(key string, value any) (uint64, error) {
|
||||
rev, err := m.Toolchains(key, value)
|
||||
if err != nil || m.Emit == nil {
|
||||
return rev, err
|
||||
m.reporterOnce.Do(func() {
|
||||
m.reporter = &toolchainReporter{AskLanguage: sdkstep.AskNode, Node: m.Node, Publish: m.SayToolchain}
|
||||
})
|
||||
return putReporting(m.Toolchains, m.reporter, m.programDigest, m.Say)
|
||||
}
|
||||
|
||||
// programDigest is the digest of the node program this node's node-toolchain provides, the `node` found on the path: read
|
||||
// again only when the installed version changed (design 47 G §472; the lead's answer A-152).
|
||||
func (m *Module) programDigest(version string) string {
|
||||
m.digestMu.Lock()
|
||||
defer m.digestMu.Unlock()
|
||||
if m.digestFor == version && m.progDigest != "" {
|
||||
return m.progDigest
|
||||
}
|
||||
find := m.ToolchainProgram
|
||||
if find == nil {
|
||||
find = func() (string, error) { return exec.LookPath("node") }
|
||||
}
|
||||
path, err := find()
|
||||
if err == nil {
|
||||
var d string
|
||||
if d, err = programFileDigest(path); err == nil {
|
||||
m.digestFor, m.progDigest = version, d
|
||||
return d
|
||||
}
|
||||
if eerr := m.Emit(ToolchainReported, map[string]string{"node": m.Node, "language": "typescript"}); eerr != nil && m.Say != nil {
|
||||
m.Say("the event %s could not be emitted: %v", ToolchainReported, eerr)
|
||||
}
|
||||
return rev, nil
|
||||
}
|
||||
if m.Say != nil {
|
||||
m.Say("the digest of the node toolchain program could not be read: %v", err)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user