A compiled artifact names the binary a machine will run
novox/hq 04-ISSUES/142. The name a machine runs a binary by is not always the name of the package that built it. The host's command is cmd/mesh-host and every machine runs it as nox-mesh-host — the path it is installed at, the name in its unit, and the name its launcher looks for inside a delivered version. So the first delivered host version landed as `mesh-host`, the host reported "created /usr/lib/nox-mesh-host/versions/2681d936b949: 1 file(s)", everything said success, and the launcher would never have seen it. Found by listing the directory instead of believing the line. An artifact may now say what its executable is called. Saying nothing keeps what the compiler would have chosen — the package's name — so nothing that worked before changes.
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
package builder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/novox/mesh-controller/internal/catalogue"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The name a machine runs a binary by is not always the name of the package that built it. The host's
|
||||||
|
// command is cmd/mesh-host and every machine runs it as nox-mesh-host — the path it is installed at,
|
||||||
|
// the name in its unit, and the name its launcher looks for inside a delivered version.
|
||||||
|
//
|
||||||
|
// A bundle carrying the package's name was delivered to a machine correctly, reported "created … 1
|
||||||
|
// file(s)", and was invisible to the launcher (novox/hq 04-ISSUES/142). Found by reading the delivered
|
||||||
|
// directory rather than by trusting the line that said it worked.
|
||||||
|
|
||||||
|
func TestACompiledArtifactNamesTheBinaryAMachineWillRun(t *testing.T) {
|
||||||
|
got := binaryName(catalogue.Artifact{
|
||||||
|
Name: "host-arch", From: "cmd/mesh-host", Binary: "nox-mesh-host",
|
||||||
|
})
|
||||||
|
if got != "nox-mesh-host" {
|
||||||
|
t.Fatalf("the binary is named %q, and the launcher looks for nox-mesh-host", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSayingNothingKeepsWhatTheCompilerWouldHaveChosen(t *testing.T) {
|
||||||
|
// go build names its output after the package, so an artifact that says nothing gets the same
|
||||||
|
// thing it got before this existed.
|
||||||
|
if got := binaryName(catalogue.Artifact{Name: "host-arch", From: "cmd/mesh-host"}); got != "mesh-host" {
|
||||||
|
t.Fatalf("an artifact naming no binary produced %q", got)
|
||||||
|
}
|
||||||
|
if got := binaryName(catalogue.Artifact{Name: "host-arch", From: "./cmd/agent/"}); got != "agent" {
|
||||||
|
t.Fatalf("a from with slashes produced %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestABundleBuiltFromTheModuleRootFallsBackToItsArtifactName(t *testing.T) {
|
||||||
|
// A single-command repository names no package, and `go build -o <dir>` would then write a file
|
||||||
|
// named after the module directory — which is not something the manifest states. The artifact's
|
||||||
|
// own name is what the manifest does state.
|
||||||
|
if got := binaryName(catalogue.Artifact{Name: "tool"}); got != "tool" {
|
||||||
|
t.Fatalf("a bundle built from the root produced %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -878,7 +878,16 @@ func compile(ctx context.Context, run Runner, tree string, chain Toolchain,
|
|||||||
}
|
}
|
||||||
invocation = append(invocation, chain.Compile...)
|
invocation = append(invocation, chain.Compile...)
|
||||||
if chain.OutputFlag != "" {
|
if chain.OutputFlag != "" {
|
||||||
invocation = append(invocation, chain.OutputFlag, out)
|
// A compiler pointed at a package is told the file to write, not the directory: the name a
|
||||||
|
// machine runs it by is not always the name of the package that built it. The host's command
|
||||||
|
// is `cmd/mesh-host` and every machine runs it as `nox-mesh-host` — so a bundle carrying the
|
||||||
|
// package's name lands correctly, reports success, and is invisible to whatever looks for it
|
||||||
|
// (novox/hq 04-ISSUES/142).
|
||||||
|
target := out
|
||||||
|
if chain.Unit == UnitPackage {
|
||||||
|
target = filepath.Join(out, binaryName(a))
|
||||||
|
}
|
||||||
|
invocation = append(invocation, chain.OutputFlag, target)
|
||||||
}
|
}
|
||||||
// What to compile. Named by the module rather than discovered, so adding a file does not
|
// What to compile. Named by the module rather than discovered, so adding a file does not
|
||||||
// silently change what a build produces.
|
// silently change what a build produces.
|
||||||
@@ -1067,3 +1076,15 @@ func readBy(manifest catalogue.Manifest) []catalogue.ArtifactContext {
|
|||||||
})
|
})
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// binaryName is what a compiled bundle's executable is called: what the artifact says, or the name of
|
||||||
|
// the package it is built from, which is what a compiler would have chosen anyway.
|
||||||
|
func binaryName(a catalogue.Artifact) string {
|
||||||
|
if name := strings.TrimSpace(a.Binary); name != "" {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
if from := strings.Trim(a.From, "./"); from != "" {
|
||||||
|
return filepath.Base(from)
|
||||||
|
}
|
||||||
|
return a.Name
|
||||||
|
}
|
||||||
|
|||||||
@@ -597,6 +597,16 @@ type Artifact struct {
|
|||||||
// Empty for every other kind, which do not compile.
|
// Empty for every other kind, which do not compile.
|
||||||
Language string `json:"language,omitempty"`
|
Language string `json:"language,omitempty"`
|
||||||
|
|
||||||
|
// Binary is what the compiled executable is called, for a bundle in a language that compiles to
|
||||||
|
// one. Empty means the package's own name, which is what a compiler does by default.
|
||||||
|
//
|
||||||
|
// **Because the name a machine runs it by is not always the name of the package that built it.**
|
||||||
|
// The host's command is `cmd/mesh-host` and every machine runs it as `nox-mesh-host` — the path
|
||||||
|
// it is installed at, the name in its unit, and the name its launcher looks for inside a
|
||||||
|
// delivered version. A bundle that carried the package's name was delivered correctly, reported
|
||||||
|
// success, and was invisible to the launcher (novox/hq 04-ISSUES/142).
|
||||||
|
Binary string `json:"binary,omitempty"`
|
||||||
|
|
||||||
// Entrypoints are the compiled files a tool host should load from this module, relative to the
|
// Entrypoints are the compiled files a tool host should load from this module, relative to the
|
||||||
// bundle's root.
|
// bundle's root.
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user