novox/hq 04-ISSUES/161. A repeated flag is not a merged one. The Go command takes the last -ldflags and drops the first, so passing the toolchain's flags and then the system stamp as a second one produced a binary that knew its system and had lost -s -w: 12.2MB against 8.5MB, with its debug info intact. My own comment said the linker "accepts and merges" them. It does not, and I found out by reading the file the build produced rather than by reading the comment again. Linker flags are now the toolchain's own list, composed into one flag with the stamp. A test refuses a compile line that carries -ldflags itself, because that is what makes two.
77 lines
2.5 KiB
Go
77 lines
2.5 KiB
Go
package builder
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A host built without knowing its system refuses every declaration before applying anything —
|
|
// safely, totally, and with nothing reporting it. The mesh built one, delivered it, started it, and
|
|
// it would have refused the first thing it was asked to do (novox/hq 04-ISSUES/161).
|
|
|
|
func TestTheGoToolchainStampsTheArtifactsSystem(t *testing.T) {
|
|
chain, err := ToolchainFor("go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if chain.SystemStamp != "main.builtFor" {
|
|
t.Fatalf("the go toolchain fills %q", chain.SystemStamp)
|
|
}
|
|
}
|
|
|
|
func TestALanguageWithNoPinnedSystemStampsNothing(t *testing.T) {
|
|
// Interpreted output is not pinned to a system, and a manifest declaring one for it is already
|
|
// refused. Nothing to fill.
|
|
for _, language := range []string{"typescript", "python"} {
|
|
chain, err := ToolchainFor(language)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if chain.SystemStamp != "" {
|
|
t.Fatalf("%s fills %q, and its output is not pinned to a system",
|
|
language, chain.SystemStamp)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTheStampIsTheOneThingTakenFromTheArtifact(t *testing.T) {
|
|
// The toolchain accepts nothing else from the module — anything it could override it would be
|
|
// writing a Dockerfile to override. The system is the stated exception, because a compiled
|
|
// binary is per system and the artifact is what declares one (ADR 0142).
|
|
chain, err := ToolchainFor("go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
joined := strings.Join(chain.Compile, " ")
|
|
if strings.Contains(joined, "${") || strings.Contains(joined, "%s") {
|
|
t.Fatalf("the compile line takes something from the module: %q", joined)
|
|
}
|
|
}
|
|
|
|
func TestTheLinkerIsToldOnceNotTwice(t *testing.T) {
|
|
// A repeated flag is not a merged one: the Go command takes the last -ldflags and drops the
|
|
// first. Passing the toolchain's flags and then the stamp separately produced a binary that knew
|
|
// its system and had lost -s -w — 12.2MB against 8.5MB, with its debug info (04-ISSUES/161).
|
|
chain, err := ToolchainFor("go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, arg := range chain.Compile {
|
|
if arg == "-ldflags" {
|
|
t.Fatal("the compile line carries -ldflags, so composing one here makes two")
|
|
}
|
|
}
|
|
if len(chain.LinkerFlags) == 0 {
|
|
t.Fatal("the go toolchain passes no linker flags, so the binary keeps its debug info")
|
|
}
|
|
var stripped bool
|
|
for _, f := range chain.LinkerFlags {
|
|
if f == "-s" {
|
|
stripped = true
|
|
}
|
|
}
|
|
if !stripped {
|
|
t.Fatalf("the go toolchain does not strip: %v", chain.LinkerFlags)
|
|
}
|
|
}
|