From 4b19686109b0962ea68dfe58feafffe3bac9c202 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 1 Oct 2026 22:24:09 +0900 Subject: cmd/dist: optionally build with race instrument This is mostly useful for the integration test suites. Signed-off-by: Ophestra --- cmd/dist/main.go | 14 ++++++++++++-- cmd/mbf/internal/ci/ci.go | 37 +++++++++++++++++++++++++++++++++++++ cmd/mbf/main.go | 23 +++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/dist/main.go b/cmd/dist/main.go index 8e1c57c1..1034f282 100644 --- a/cmd/dist/main.go +++ b/cmd/dist/main.go @@ -56,6 +56,7 @@ func main() { verbose := os.Getenv("VERBOSE") != "" runTests := os.Getenv("HAKUREI_DIST_MAKE") == "" + race := os.Getenv("HAKUREI_RACE") != "" version = getenv("HAKUREI_VERSION", strings.TrimSpace(version)) prefix := getenv("PREFIX", "/usr/local") destdir := getenv("DESTDIR", "dist") @@ -64,6 +65,10 @@ func main() { log.Println() } + if race { + version += "-race" + } + if err := os.MkdirAll(destdir, 0755); err != nil { log.Fatal(err) } @@ -95,12 +100,17 @@ func main() { verboseFlag = "-buildvcs=false" } + raceFlag := "-race" + if !race { + raceFlag = "-buildvcs=false" + } + log.Printf("Building hakurei %s for %s/%s.", version, runtime.GOOS, runtime.GOARCH) mustRun(ctx, nil, "go", "generate", "./...") mustRun( ctx, nil, "go", "build", "-trimpath", - verboseFlag, "-o", s, + verboseFlag, raceFlag, "-o", s, "-ldflags=-s -w "+ "-buildid= -linkmode external -extldflags=-static "+ "-X hakurei.app/internal/info.buildVersion="+version+" "+ @@ -125,7 +135,7 @@ func main() { if runTests { log.Println("##### Testing Hakurei.") mustRun( - ctx, nil, "go", "test", + ctx, nil, "go", "test", raceFlag, "-ldflags=-buildid= -linkmode external -extldflags=-static", "./...", ) diff --git a/cmd/mbf/internal/ci/ci.go b/cmd/mbf/internal/ci/ci.go index 5c993a1b..b1ee6a8c 100644 --- a/cmd/mbf/internal/ci/ci.go +++ b/cmd/mbf/internal/ci/ci.go @@ -450,6 +450,10 @@ const ( // endpointDist accepts a Path.writeSource stream and produces a // distribution for the submitted source. endpointDist = "/dist" + + // endpointRace is like endpointDist, but the resulting distribution is + // instrumented with the data race detector. + endpointRace = "/race" ) // MakeDist creates a hakurei distribution using the CI service. @@ -465,6 +469,19 @@ func (p Path) MakeDist( return p.fetch(ctx, id, output) } +// MakeDistRace creates a hakurei distribution (race) using the CI service. +func (p Path) MakeDistRace( + ctx context.Context, + w io.Writer, + output, source, version string, +) error { + id, err := p.writeSource(ctx, w, endpointRace, source, version) + if err != nil { + return err + } + return p.fetch(ctx, id, output) +} + // Serve services CI workload dispatched to c. func Serve(ctx context.Context, msg message.Msg, c *pkg.Cache) error { const shutdownTimeout = 15 * time.Second @@ -495,6 +512,26 @@ func Serve(ctx context.Context, msg message.Msg, c *pkg.Cache) error { ) } }) + mux.HandleFunc("POST "+endpointRace, func(w http.ResponseWriter, r *http.Request) { + s, err := readSource(w, r) + if err != nil { + msg.Verbose(err) + return + } + defer putS(s) + + _, a := s.Std().MustLoad(rosa.H("hakurei-dist-race")) + if err = cure(c, a, w); err != nil { + msg.Verbose(err) + return + } + if msg.IsVerbose() { + msg.Verbosef( + "satisfied distribution %s (race)", + pkg.Encode(c.Ident(a).Value()), + ) + } + }) if r, err := os.OpenRoot(p.String()); err != nil { return err diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go index 5dd4e8a0..dd5ee624 100644 --- a/cmd/mbf/main.go +++ b/cmd/mbf/main.go @@ -548,6 +548,29 @@ func main() { "Write the resulting distribution to the named directory", ) } + { + var flagOutput string + _ci.NewCommand( + "race", + "Request distribution tarball (race) for the specified source directory", + func(args []string) error { + if len(args) != 2 { + return errors.New("race requires 2 arguments") + } + + return ci.Path(cm.base).MakeDistRace( + ctx, + os.Stdout, + flagOutput, + args[0], args[1], + ) + }, + ).Flag( + &flagOutput, + "o", command.StringFlag("."), + "Write the resulting distribution to the named directory", + ) + } c.NewCommand( "keygen", -- cgit v1.3.1