-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Generate go protobuf types/source from .proto files imported as git submodule #935
Changes from all commits
625a2cd
1cb3e51
ead45fc
9caee6c
342f87e
c43563b
fc6ce5c
8870f97
eb3e590
a07b920
1a39c2d
05eee55
6754b3d
2798fc2
3fc20b8
fbb8d4a
9604001
b190c24
8d43620
8769439
fec0341
b4770bf
916bc72
fe84e51
d02fd7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "opentelemetry-proto"] | ||
path = internal/opentelemetry-proto | ||
url = https://github.com/open-telemetry/opentelemetry-proto |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,9 +31,10 @@ ifeq ($(UNAME_S),Darwin) | |||||
endif | ||||||
endif | ||||||
|
||||||
GOCOVER_PKGS = $(shell go list ./... | grep -v 'internal/opentelemetry-proto' | paste -s -d, - ) | ||||||
GOTEST_MIN = go test -timeout 30s | ||||||
GOTEST = $(GOTEST_MIN) -race | ||||||
GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... | ||||||
GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(GOCOVER_PKGS) | ||||||
|
||||||
.DEFAULT_GOAL := precommit | ||||||
|
||||||
|
@@ -134,7 +135,11 @@ lint: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell | |||||
go mod tidy); \ | ||||||
done | ||||||
|
||||||
generate: $(TOOLS_DIR)/stringer | ||||||
.PHONY: generate | ||||||
generate: stringer protobuf | ||||||
|
||||||
.PHONY: stringer | ||||||
stringer: $(TOOLS_DIR)/stringer | ||||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \ | ||||||
echo "running generators in $${dir}"; \ | ||||||
(cd "$${dir}" && \ | ||||||
|
@@ -143,10 +148,82 @@ generate: $(TOOLS_DIR)/stringer | |||||
|
||||||
.PHONY: license-check | ||||||
license-check: | ||||||
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path './vendor/*') ; do \ | ||||||
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path './vendor/*' ! -path './internal/opentelemetry-proto/*') ; do \ | ||||||
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \ | ||||||
done); \ | ||||||
if [ -n "$${licRes}" ]; then \ | ||||||
echo "license header checking failed:"; echo "$${licRes}"; \ | ||||||
exit 1; \ | ||||||
fi | ||||||
|
||||||
# Find all .proto files. | ||||||
OTEL_PROTO_SUBMODULE := internal/opentelemetry-proto | ||||||
PROTO_GEN_DIR := internal/opentelemetry-proto-gen | ||||||
PROTOBUF_TEMP_DIR := gen/pb-go | ||||||
PROTOBUF_SOURCE_DIR := gen/proto | ||||||
ORIG_PROTO_FILES := $(wildcard $(OTEL_PROTO_SUBMODULE)/opentelemetry/proto/*/v1/*.proto \ | ||||||
$(OTEL_PROTO_SUBMODULE)/opentelemetry/proto/collector/*/v1/*.proto) | ||||||
Comment on lines
+164
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
SOURCE_PROTO_FILES := $(subst $(OTEL_PROTO_SUBMODULE),$(PROTOBUF_SOURCE_DIR),$(ORIG_PROTO_FILES)) | ||||||
|
||||||
ifeq ($(CIRCLECI),true) | ||||||
copy-protos-to: | ||||||
# create a dummy container to hold the protobufs | ||||||
docker create -v /defs --name proto-orig alpine:3.4 /bin/true | ||||||
# copy from here into the proto-src directory | ||||||
docker cp ./gen proto-orig:/defs | ||||||
|
||||||
copy-protobuf-from: | ||||||
rm -fr ./$(PROTO_GEN_DIR) | ||||||
# copy from dummy volume back to our source directory | ||||||
docker cp proto-orig:/defs/$(PROTOBUF_TEMP_DIR)/go.opentelemetry.io/otel/$(PROTO_GEN_DIR) ./$(PROTO_GEN_DIR) | ||||||
|
||||||
else | ||||||
copy-protos-to: | ||||||
@: # nop | ||||||
|
||||||
copy-protobuf-from: | ||||||
rm -fr ./$(PROTO_GEN_DIR) | ||||||
mv ./$(PROTOBUF_TEMP_DIR)/go.opentelemetry.io/otel/$(PROTO_GEN_DIR) ./$(PROTO_GEN_DIR) | ||||||
endif | ||||||
|
||||||
|
||||||
# This step can be omitted assuming go_package changes are made in opentelemetry-proto repo | ||||||
define exec-replace-pkgname | ||||||
sed 's+go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go+go_package = "go.opentelemetry.io/otel/internal/opentelemetry-proto-gen+' < $(1) > $(2) | ||||||
|
||||||
endef | ||||||
|
||||||
.PHONY: protobuf make-protobufs | ||||||
protobuf: protobuf-source copy-protos-to make-protobufs copy-protobuf-from | ||||||
|
||||||
.PHONY: protobuf-source | ||||||
protobuf-source: $(SOURCE_PROTO_FILES) | $(PROTOBUF_SOURCE_DIR)/ | ||||||
|
||||||
# replace opentelemetry-proto v0.4.0 package name by repo-local version | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the upgrade path look? Does it include bumping the submodule and going through all the go.mod files? Also, might not want to include the version in the comment.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the new PR #938, it will look as follows:
|
||||||
$(SOURCE_PROTO_FILES): $(PROTOBUF_SOURCE_DIR)/%.proto: $(OTEL_PROTO_SUBMODULE)/%.proto | ||||||
@mkdir -p $(@D) | ||||||
$(call exec-replace-pkgname,$<,$@) | ||||||
|
||||||
ifeq ($(CIRCLECI),true) | ||||||
VOLUMES_MOUNT=--volumes-from proto-orig | ||||||
else | ||||||
VOLUMES_MOUNT=-v `pwd`:/defs | ||||||
endif | ||||||
|
||||||
define exec-protoc-all | ||||||
docker run $(VOLUMES_MOUNT) namely/protoc-all $(1) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This container needs to be versioned to a tag so when latest is updated it doesn't break things. E.g.
Suggested change
Though, it probably makes sense to keep the version as a variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps better, pin the image to a digest:
|
||||||
|
||||||
endef | ||||||
|
||||||
make-protobufs: $(SOURCE_PROTO_FILES) | $(PROTOBUF_GEN_DIR)/ | ||||||
$(foreach file,$(subst ${PROTOBUF_SOURCE_DIR}/,,$(SOURCE_PROTO_FILES)),$(call exec-protoc-all, -i $(PROTOBUF_SOURCE_DIR) -f ${file} -l go -o ${PROTOBUF_TEMP_DIR})) | ||||||
rm -fr ./gen/go | ||||||
|
||||||
|
||||||
$(PROTOBUF_SOURCE_DIR)/ $(PROTO_GEN_DIR)/: | ||||||
mkdir -p $@ | ||||||
|
||||||
.PHONY: protobuf-clean | ||||||
protobuf-clean: | ||||||
rm -rf ./gen ./$(PROTO_GEN_DIR) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.