Skip to content

Commit 94fcca3

Browse files
committed
api: generate field ownership functions
Introduce a `protoc` generator (`tools/protoc-gen-owners`) to automatically generate the repetitive field ownership tracking functions. This refactors the `pkg/api/owners.go` file. The new generator uses the `Field` enum in `api.proto` as the source of truth. The original `owners.go` file has been split logically into generated and handwritten parts: - `owners_generated.go`: Contains the auto-generated boilerplate for most fields. - `owners.go`: Retains the core handwritten logic, including constructors, conflict resolution, and special-cased handlers for fields with custom logic (`OciHooks`, `Rdt`). This change reduces manual boilerplate, improves maintainability, and ensures consistency between the protobuf definitions and the Go API. Assisted-by: gemini-cli Signed-off-by: Samuel Karp <samuelkarp@google.com>
1 parent 8c8e2be commit 94fcca3

4 files changed

Lines changed: 1206 additions & 635 deletions

File tree

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ FORCE:
8080
# build targets
8181
#
8282

83-
build-proto: check-protoc install-ttrpc-plugin install-wasm-plugin install-protoc-dependencies build-protoc-gen-strip
83+
build-proto: check-protoc install-ttrpc-plugin install-wasm-plugin install-protoc-dependencies build-protoc-gen-strip build-protoc-gen-owners
8484
for src in $(PROTO_SOURCES); do \
8585
$(PROTO_COMPILE) \
8686
--plugin=protoc-gen-strip=$(abspath $(BIN_PATH)/protoc-gen-strip) \
8787
--strip_out=pkg/api \
8888
--strip_opt=file=strip.go \
89+
--plugin=protoc-gen-owners=$(abspath $(BIN_PATH)/protoc-gen-owners) \
90+
--owners_out=pkg/api \
91+
--owners_opt=file=owners_generated.go \
8992
$$src; \
9093
done
9194
sed -i '1s;^;//go:build !wasip1\n\n;' pkg/api/api_ttrpc.pb.go
@@ -120,6 +123,11 @@ clean-cache:
120123
# plugins build targets
121124
#
122125

126+
.PHONY: build-protoc-gen-owners
127+
build-protoc-gen-owners:
128+
$(Q)echo "Building build/bin/protoc-gen-owners..."; \
129+
$(GO_BUILD) -C tools/protoc-gen-owners -o $(abspath $(BIN_PATH)/protoc-gen-owners) $(GO_BUILD_FLAGS) .
130+
123131
.PHONY: build-protoc-gen-strip
124132
build-protoc-gen-strip:
125133
$(Q)echo "Building build/bin/protoc-gen-strip..."; \

0 commit comments

Comments
 (0)