Skip to content

Bazelify Go stringer#47428

Draft
rdesgroppes wants to merge 2 commits intomainfrom
regis.desgroppes/bazel-go-stringer
Draft

Bazelify Go stringer#47428
rdesgroppes wants to merge 2 commits intomainfrom
regis.desgroppes/bazel-go-stringer

Conversation

@rdesgroppes
Copy link
Contributor

What does this PR do?

Motivation

Describe how you validated your changes

Additional Notes

@github-actions github-actions bot added the long review PR is complex, plan time to review it label Mar 5, 2026
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Mar 5, 2026

Files inventory check summary

File checks results against ancestor 960d881b:

Results for datadog-agent_7.78.0~devel.git.362.20227cf.pipeline.100708395-1_amd64.deb:

No change detected

### What does this PR do?
- add `bazel/tools/stringer_wrapper.sh` + `sh_binary`: wrapper that
  puts the rules_go `go` binary on PATH and cds to the package
  directory before invoking stringer, so the generated header matches
  `//go:generate` output exactly
- add `bazel/rules/go_stringer.bzl`: `go_stringer` Starlark macro
  wrapping `run_binary`; params: `name`, `src`, `type`, `gomod`,
  `output`, `trimprefix`, `linecomment`, `go_tags`, `**kwargs`
- add `internal/tools/gazelle-stringer/`: Gazelle language extension
  that reads `//go:generate stringer` directives and emits
  `go_stringer` rules; wired into a custom `gazelle_binary` at
  `//:gazelle`
- Bazelify `pkg/template` as proof of concept: BUILD.bazel files for
  the root package, `internal/fmtsort`, `text`, and `html`; the six
  `html` stringer targets, one `write_source_file` diff-test per
  target, and `go_library` targets; unexclude `pkg/template` from the
  root Gazelle exclusion list
- update checked-in `*_string.go` files in `pkg/template/html`; those
  files were copied from the Go stdlib in #36024 and had never been
  regenerated in this repo; the diffs reflect a newer
  `golang.org/x/tools` version bundled with rules_go vs what the Go
  team used at the time

### Motivation
Replaces manual `go generate` invocations with hermetic Bazel actions,
making the build self-contained and stringer outputs verifiable via
`bazel test`.

### Describe how you validated your changes
- `bazel build //pkg/template/html:...` builds all six stringer targets
  and the `go_library`
- `bazel test //pkg/template/...` passes six diff-tests (one per
  generated file)
- `bazel run //:gazelle -- -mode=diff` produces no diff
@rdesgroppes rdesgroppes force-pushed the regis.desgroppes/bazel-go-stringer branch from 6bfdae0 to 20227cf Compare March 5, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Identify a non-fork PR long review PR is complex, plan time to review it team/agent-build team/agent-runtimes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant