From 66db30d466312ac839556415f7b1253774f66123 Mon Sep 17 00:00:00 2001 From: Aditya Chopra <114332875+adityachopra29@users.noreply.github.com> Date: Wed, 22 Jan 2025 04:55:52 +0530 Subject: [PATCH] Clean Makefile (#120) ## Which problem is this PR solving? - Cleans the Makefile as discussed here: https://github.com/jaegertracing/jaeger-idl/pull/116#discussion_r1919052873 ## How was this change tested? ## Description of the changes - Removes the redundant Makefile.Protobuf.mk file ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: adityachopra29 --- .github/workflows/ci-lint-test.yml | 2 +- .gitignore | 2 +- Makefile | 109 ++++++++++++++++++++--------- Makefile.Protobuf.mk | 71 ------------------- 4 files changed, 78 insertions(+), 106 deletions(-) delete mode 100644 Makefile.Protobuf.mk diff --git a/.github/workflows/ci-lint-test.yml b/.github/workflows/ci-lint-test.yml index 8f3a607b..63736530 100644 --- a/.github/workflows/ci-lint-test.yml +++ b/.github/workflows/ci-lint-test.yml @@ -31,4 +31,4 @@ jobs: submodules: recursive - name: Verify Protobuf types are up to date - run: make new-proto && git diff --name-status --exit-code \ No newline at end of file + run: make proto && git diff --name-status --exit-code \ No newline at end of file diff --git a/.gitignore b/.gitignore index 67959fb7..6eae0f3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .idea/ gen-*/ -proto-gen-*/ +.proto-gen-polyglot/ diff --git a/Makefile b/Makefile index e6e0b91c..3c7dc3cb 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ swagger-validate: .PHONY: clean clean: rm -rf *gen-* || true + rm -rf .*gen-* || true .PHONY: thrift thrift: thrift-image clean $(THRIFT_FILES) @@ -71,48 +72,52 @@ PROTO_GOGO_MAPPINGS := $(shell echo \ Mmodel.proto=github.com/jaegertracing/jaeger-idl/model/v1 \ | sed 's/ //g') -PROTO_GEN_GO_DIR ?= proto-gen-go -PROTO_GEN_PYTHON_DIR ?= proto-gen-python -PROTO_GEN_JAVA_DIR ?= proto-gen-java -PROTO_GEN_JS_DIR ?= proto-gen-js -PROTO_GEN_CPP_DIR ?= proto-gen-cpp -PROTO_GEN_CSHARP_DIR ?= proto-gen-csharp +PROTO_GEN_GO_DIR ?= proto-gen +POLYGLOT_DIR_ROOT ?= .proto-gen-polyglot +PROTO_GEN_GO_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-go +PROTO_GEN_PYTHON_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-python +PROTO_GEN_JAVA_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-java +PROTO_GEN_JS_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-js +PROTO_GEN_CPP_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-cpp +PROTO_GEN_CSHARP_DIR_POLYGLOT ?= $(POLYGLOT_DIR_ROOT)/proto-gen-csharp + +API_V2_PATH ?= api_v2 # The jaegertracing/protobuf container image does not # include Java/C#/C++ plugins for Apple Silicon (arm64). PROTOC_WITHOUT_GRPC_common := $(PROTOC) \ $(PROTO_INCLUDES) \ - --gogo_out=plugins=grpc,$(PROTO_GOGO_MAPPINGS):$(PWD)/${PROTO_GEN_GO_DIR} \ - --python_out=${PROTO_GEN_PYTHON_DIR} \ - --js_out=${PROTO_GEN_JS_DIR} + --gogo_out=plugins=grpc,$(PROTO_GOGO_MAPPINGS):$(PWD)/${PROTO_GEN_GO_DIR_POLYGLOT} \ + --python_out=${PROTO_GEN_PYTHON_DIR_POLYGLOT} \ + --js_out=${PROTO_GEN_JS_DIR_POLYGLOT} ifeq ($(shell uname -m),arm64) PROTOC_WITHOUT_GRPC := $(PROTOC_WITHOUT_GRPC_common) else PROTOC_WITHOUT_GRPC := $(PROTOC_WITHOUT_GRPC_common) \ - --java_out=${PROTO_GEN_JAVA_DIR} \ - --cpp_out=${PROTO_GEN_CPP_DIR} \ - --csharp_out=base_namespace:${PROTO_GEN_CSHARP_DIR} + --java_out=${PROTO_GEN_JAVA_DIR_POLYGLOT} \ + --cpp_out=${PROTO_GEN_CPP_DIR_POLYGLOT} \ + --csharp_out=base_namespace:${PROTO_GEN_CSHARP_DIR_POLYGLOT} endif PROTOC_WITH_GRPC_common := $(PROTOC_WITHOUT_GRPC) \ - --grpc-python_out=${PROTO_GEN_PYTHON_DIR} \ - --grpc-js_out=${PROTO_GEN_JS_DIR} + --grpc-python_out=${PROTO_GEN_PYTHON_DIR_POLYGLOT} \ + --grpc-js_out=${PROTO_GEN_JS_DIR_POLYGLOT} ifeq ($(shell uname -m),arm64) PROTOC_WITH_GRPC := $(PROTOC_WITH_GRPC_common) else PROTOC_WITH_GRPC := $(PROTOC_WITH_GRPC_common) \ - --grpc-java_out=${PROTO_GEN_JAVA_DIR} \ - --grpc-cpp_out=${PROTO_GEN_CPP_DIR} \ - --grpc-csharp_out=${PROTO_GEN_CSHARP_DIR} + --grpc-java_out=${PROTO_GEN_JAVA_DIR_POLYGLOT} \ + --grpc-cpp_out=${PROTO_GEN_CPP_DIR_POLYGLOT} \ + --grpc-csharp_out=${PROTO_GEN_CSHARP_DIR_POLYGLOT} endif PROTOC_INTERNAL := $(PROTOC) \ $(PROTO_INCLUDES) \ - --csharp_out=internal_access,base_namespace:${PROTO_GEN_CSHARP_DIR} \ - --python_out=${PROTO_GEN_PYTHON_DIR} + --csharp_out=internal_access,base_namespace:${PROTO_GEN_CSHARP_DIR_POLYGLOT} \ + --python_out=${PROTO_GEN_PYTHON_DIR_POLYGLOT} GO=go GOOS ?= $(shell $(GO) env GOOS) @@ -126,27 +131,64 @@ else SED=sed endif -# import other Makefiles after the variables are defined -include Makefile.Protobuf.mk +# DO NOT DELETE EMPTY LINE at the end of the macro, it's required to separate commands. +define print_caption + @echo "🏗️ " + @echo "🏗️ " $1 + @echo "🏗️ " + +endef + +# Macro to compile Protobuf $(2) into directory $(1). $(3) can provide additional flags. +# DO NOT DELETE EMPTY LINE at the end of the macro, it's required to separate commands. +# Arguments: +# $(1) - output directory +# $(2) - path to the .proto file +# $(3) - additional flags to pass to protoc, e.g. extra -Ixxx +# $(4) - additional options to pass to gogo plugin +define proto_compile + $(call print_caption, "Processing $(2) --> $(1)") + + $(PROTOC) \ + $(PROTO_INCLUDES) \ + --gogo_out=plugins=grpc,$(strip $(4)),$(PROTO_GOGO_MAPPINGS):$(PWD)/$(strip $(1)) \ + $(3) $(2) + +endef .PHONY: test-ci test-ci: go test -v -coverprofile=coverage.txt ./... -.PHONY: proto -proto: proto-prepare proto-api-v2 proto-api-v3 +# proto target is used to generate source code that is released as part of this library +proto: proto-prepare proto-api-v2 + +# proto-all target is used to generate code for all languages as a validation step. +proto-all: proto-prepare-all proto-api-v2-all proto-api-v3-all + +.PHONY: proto-prepare-all +proto-prepare-all: + mkdir -p ${PROTO_GEN_GO_DIR_POLYGLOT} \ + ${PROTO_GEN_JAVA_DIR_POLYGLOT} \ + ${PROTO_GEN_PYTHON_DIR_POLYGLOT} \ + ${PROTO_GEN_JS_DIR_POLYGLOT} \ + ${PROTO_GEN_CPP_DIR_POLYGLOT} \ + ${PROTO_GEN_CSHARP_DIR_POLYGLOT} .PHONY: proto-prepare proto-prepare: - mkdir -p ${PROTO_GEN_GO_DIR} \ - ${PROTO_GEN_JAVA_DIR} \ - ${PROTO_GEN_PYTHON_DIR} \ - ${PROTO_GEN_JS_DIR} \ - ${PROTO_GEN_CPP_DIR} \ - ${PROTO_GEN_CSHARP_DIR} + mkdir -p ${PROTO_GEN_GO_DIR} .PHONY: proto-api-v2 proto-api-v2: + mkdir -p ${PROTO_GEN_GO_DIR}/${API_V2_PATH} + $(call proto_compile, model/v1, proto/api_v2/model.proto) + $(call proto_compile, ${PROTO_GEN_GO_DIR}/${API_V2_PATH}, proto/api_v2/query.proto) + $(call proto_compile, ${PROTO_GEN_GO_DIR}/${API_V2_PATH}, proto/api_v2/collector.proto) + $(call proto_compile, ${PROTO_GEN_GO_DIR}/${API_V2_PATH}, proto/api_v2/sampling.proto) + +.PHONY: proto-api-v2-all +proto-api-v2-all: $(PROTOC_WITHOUT_GRPC) \ proto/api_v2/model.proto @@ -155,15 +197,16 @@ proto-api-v2: proto/api_v2/collector.proto \ proto/api_v2/sampling.proto -.PHONY: proto-api-v3 -proto-api-v3: + +.PHONY: proto-api-v3-all +proto-api-v3-all: # API v3 $(PROTOC_WITH_GRPC) \ proto/api_v3/query_service.proto # GRPC gateway $(PROTOC) \ $(PROTO_INCLUDES) \ - --grpc-gateway_out=logtostderr=true,grpc_api_configuration=proto/api_v3/query_service_http.yaml,$(PROTO_GOGO_MAPPINGS):${PROTO_GEN_GO_DIR} \ + --grpc-gateway_out=logtostderr=true,grpc_api_configuration=proto/api_v3/query_service_http.yaml,$(PROTO_GOGO_MAPPINGS):${PROTO_GEN_GO_DIR_POLYGLOT} \ proto/api_v3/query_service.proto # Swagger $(PROTOC) \ @@ -179,7 +222,7 @@ proto-api-v3: gogoproto/gogo.proto .PHONY: proto-zipkin -proto-zipkin: +proto-zipkin: proto-prepare-all $(PROTOC_WITHOUT_GRPC) \ proto/zipkin.proto diff --git a/Makefile.Protobuf.mk b/Makefile.Protobuf.mk deleted file mode 100644 index bd7f62f0..00000000 --- a/Makefile.Protobuf.mk +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2023 The Jaeger Authors. -# SPDX-License-Identifier: Apache-2.0 - -# Generate gogo, swagger, go-validators, gRPC-storage-plugin output. -# -# -I declares import folders, in order of importance. This is how proto resolves the protofile imports. -# It will check for the protofile relative to each of thesefolders and use the first one it finds. -# -# --gogo_out generates GoGo Protobuf output with gRPC plugin enabled. -# --govalidators_out generates Go validation files for our messages types, if specified. -# -# The lines starting with Mgoogle/... are proto import replacements, -# which cause the generated file to import the specified packages -# instead of the go_package's declared by the imported protof files. -# - -DOCKER_PROTOBUF_VERSION=0.5.0 -DOCKER_PROTOBUF=jaegertracing/protobuf:$(DOCKER_PROTOBUF_VERSION) -# PROTOC := ${DOCKER} run --rm -u ${shell id -u} -v${PWD}:${PWD} -w${PWD} ${DOCKER_PROTOBUF} --proto_path=${PWD} - -PATCHED_OTEL_PROTO_DIR = proto-gen/.patched-otel-proto - -# The source directory for OTLP Protobufs from the sub-sub-module. -OTEL_PROTO_SRC_DIR=opentelemetry-proto/opentelemetry/proto - -# Find all OTEL .proto files, remove leading path (only keep relevant namespace dirs). -OTEL_PROTO_FILES=$(subst $(OTEL_PROTO_SRC_DIR)/,,\ - $(shell ls $(OTEL_PROTO_SRC_DIR)/{common,resource,trace}/v1/*.proto)) - -# Macro to execute a command passed as argument. -# DO NOT DELETE EMPTY LINE at the end of the macro, it's required to separate commands. -define exec-command -$(1) - -endef - -# DO NOT DELETE EMPTY LINE at the end of the macro, it's required to separate commands. -define print_caption - @echo "🏗️ " - @echo "🏗️ " $1 - @echo "🏗️ " - -endef - -# Macro to compile Protobuf $(2) into directory $(1). $(3) can provide additional flags. -# DO NOT DELETE EMPTY LINE at the end of the macro, it's required to separate commands. -# Arguments: -# $(1) - output directory -# $(2) - path to the .proto file -# $(3) - additional flags to pass to protoc, e.g. extra -Ixxx -# $(4) - additional options to pass to gogo plugin -define proto_compile - $(call print_caption, "Processing $(2) --> $(1)") - - $(PROTOC) \ - $(PROTO_INCLUDES) \ - --gogo_out=plugins=grpc,$(strip $(4)),$(PROTO_GOGO_MAPPINGS):$(PWD)/$(strip $(1)) \ - $(3) $(2) - -endef - -.PHONY: new-proto -new-proto: new-proto-api-v2 - -.PHONY: new-proto-api-v2 -new-proto-api-v2: - mkdir -p proto-gen/api_v2 - $(call proto_compile, model/v1, proto/api_v2/model.proto) - $(call proto_compile, proto-gen/api_v2, proto/api_v2/query.proto) - $(call proto_compile, proto-gen/api_v2, proto/api_v2/collector.proto) - $(call proto_compile, proto-gen/api_v2, proto/api_v2/sampling.proto)