Skip to content

fix(bootstrap): isolate generated code from init output - #446

Open
ViktorBystrov72 wants to merge 1 commit into
mailru:masterfrom
ViktorBystrov72:fix/bootstrap-init-output
Open

ViktorBystrov72 wants to merge 1 commit into
mailru:masterfrom
ViktorBystrov72:fix/bootstrap-init-output

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

Output from an imported package's init() currently shares stdout with generated source. Normal generation then fails in gofmt, while -noformat saves invalid Go code.

Write bootstrap output to a dedicated file and make gen.Run(writer) send both its header and body to that writer. Header write errors are propagated, and the output file is closed before formatting or renaming. Standalone bootstrap execution without an output filename keeps its stdout behavior. Add the bootstrap package to the existing Makefile test target so CI runs the regression.

Fixes #340.

The earlier header-writer proposal in #226 is related prior work; this change also isolates bootstrap output end to end.

Validation on Go 1.23.0:

  • Formatted and -noformat generation with a noisy dependency fail before the fix and pass afterward; generated code compiles and round-trips JSON.
  • Complete-source writer and failing-header-writer regressions fail on the original implementation and pass after the fix.
  • Ordinary CLI stdout stays empty; standalone bootstrap stdout formats identically to ordinary generated source.
  • Full make (including the new bootstrap target, generation, tests, benchmarks, and golint), go test -race -count=1 ./..., and go vet ./... passed.

Signed-off-by: Виктор Быстров <anatema@bk.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output from dependent package's init code causes fatal error

1 participant