runtime/debug: populate BuildInfo so ReadBuildInfo works - #5592
Conversation
|
This PR updates all submodules - unintentionally I guess? |
debug.ReadBuildInfo() returns ok=false under TinyGo, so anything that
reports its own version — a --version flag, a crash handler, a metric —
has nothing to read.
The information already exists: `go list` reports module paths and
versions for the loaded packages, and the standard toolchain stamps the
same data into runtime/debug.modinfo, a plain string global that
runtime/debug parses back into a *BuildInfo. This fills that global the
same way.
Four pieces, because the data has to travel:
- loader: keep the module Version that `go list` already returns and
the struct was discarding.
- builder: assemble the modinfo string and set the global, unless
-ldflags="-X runtime/debug.modinfo=..." already did.
- src/runtime/debug: parse it, which is where ReadBuildInfo reads from.
- go.mod: golang.org/x/mod, for module.Check and semver validation of
what goes into the string.
Skipped in GOPATH mode and when the main package is not in a module,
where there is nothing to report.
Verified: a module built with this prints its own path and version from
ReadBuildInfo, where it previously reported nothing available.
|
Correct, entirely unintentional — thanks for catching it. The branch had picked up submodule pointer bumps for All seven are gone; the diff is now only Also rebased on dev, which merged cleanly with c33682c apart from an import that both sides added to; |
86d1329 to
e053e7f
Compare
|
This needs a test. |
debug.ReadBuildInfo()returnsok=falseunder TinyGo, so anything that reports its own version — a--versionflag, a crash handler, a metric — has nothing to read.The information already exists.
go listreports module paths and versions for the loaded packages, and the standard toolchain stamps the same data intoruntime/debug.modinfo, a plain string global thatruntime/debugparses back into a*BuildInfo. This fills that global the same way, so the existing parsing path does the rest.Four pieces, because the data has to travel:
Versionthatgo listalready returns and the struct was discarding-ldflags="-X runtime/debug.modinfo=..."already didReadBuildInforeads fromgolang.org/x/mod, formodule.Checkand semver validation of what goes into the stringSkipped in GOPATH mode and when the main package isn't in a module, where there's nothing to report.
Verified: a module built with this prints its own path and version from
ReadBuildInfo(path: bitest,main: bitest (devel)), where it previously reported nothing available.