Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 1 | # Copyright 2020-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | # Makefile for device-management-interface |
| 16 | default: test |
| 17 | |
Shivanagouda Malaginahalli | 335fe4d | 2021-03-31 16:52:28 +0530 | [diff] [blame^] | 18 | # initialize path of grpc_cpp_plugin binary |
| 19 | GRPC_CPP_PLUGIN_PATH ?= $(shell which grpc_cpp_plugin) |
| 20 | |
Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 21 | # set default shell options |
| 22 | SHELL = bash -e -o pipefail |
| 23 | |
| 24 | # tool containers |
| 25 | VOLTHA_TOOLS_VERSION ?= 2.0.0 |
| 26 | |
| 27 | PROTOC = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-protoc protoc |
| 28 | PROTOC_SH = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/go/src/github.com/opencord/device-management-interface/v3 $(shell test -t 0 && echo "-it") --workdir=/go/src/github.com/opencord/device-management-interface/v3 voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-protoc sh -c |
| 29 | GO = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang go |
| 30 | |
uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 31 | # Function to extract the last path component from package line in .proto files |
| 32 | define if_package_path |
| 33 | $(shell grep if_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p') |
Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 34 | endef |
| 35 | |
| 36 | # Variables |
| 37 | PROTO_FILES := $(sort $(wildcard protos/dmi/*.proto)) |
| 38 | |
| 39 | PROTO_GO_DEST_DIR := go |
uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 40 | PROTO_GO_PB:= $(foreach f, $(PROTO_FILES), $(patsubst protos/dmi/%.proto,$(PROTO_GO_DEST_DIR)/$(call if_package_path,$(f))/%.pb.go,$(f))) |
| 41 | |
Andrea Campanella | add9944 | 2020-10-02 12:02:42 +0200 | [diff] [blame] | 42 | PROTO_PYTHON_DEST_DIR := python/dmi |
| 43 | PROTO_PYTHON_PB2 := $(foreach f, $(PROTO_FILES), $(patsubst protos/dmi/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2.py,$(f))) |
uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 44 | |
Shivanagouda Malaginahalli | 335fe4d | 2021-03-31 16:52:28 +0530 | [diff] [blame^] | 45 | PROTO_CPP_DEST_DIR := cpp |
| 46 | PROTO_CPP_PB := $(foreach f, $(PROTO_FILES), $(patsubst protos/dmi/%.proto,$(PROTO_CPP_DEST_DIR)/$(call if_package_path,$(f))/%.pb.cc,$(f))) |
Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 47 | # Force pb file to be regenrated every time. Otherwise the make process assumes generated version is still valid |
| 48 | .PHONY: dmi.pb |
| 49 | |
| 50 | print: |
| 51 | @echo "Proto files: $(PROTO_FILES)" |
| 52 | @echo "Go PB files: $(PROTO_GO_PB)" |
uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 53 | @echo "python PB files: $(PROTO_PYTHON_PB)" |
Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 54 | |
| 55 | # Generic targets |
Shivanagouda Malaginahalli | 335fe4d | 2021-03-31 16:52:28 +0530 | [diff] [blame^] | 56 | protos: go-protos python-protos cpp-protos |
Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 57 | |
| 58 | build: protos |
| 59 | |
Shivanagouda Malaginahalli | 335fe4d | 2021-03-31 16:52:28 +0530 | [diff] [blame^] | 60 | test: go-test python-test cpp-test |
uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 61 | |
Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 62 | |
| 63 | venv_protos: |
| 64 | virtualenv -p python3 $@;\ |
| 65 | source ./$@/bin/activate ; set -u ;\ |
| 66 | pip install grpcio-tools googleapis-common-protos |
| 67 | |
Andrea Campanella | add9944 | 2020-10-02 12:02:42 +0200 | [diff] [blame] | 68 | # Python targets |
| 69 | python-protos: $(PROTO_PYTHON_PB2) |
| 70 | |
| 71 | $(PROTO_PYTHON_DEST_DIR)/%_pb2.py: protos/dmi/%.proto Makefile venv_protos |
uwe ottrembka | 5ea5c0a | 2020-08-31 10:37:35 +0200 | [diff] [blame] | 72 | source ./venv_protos/bin/activate ; set -u ;\ |
Andrea Campanella | add9944 | 2020-10-02 12:02:42 +0200 | [diff] [blame] | 73 | python -m grpc_tools.protoc \ |
| 74 | -I protos \ |
| 75 | --python_out=python \ |
| 76 | --grpc_python_out=python \ |
| 77 | --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \ |
| 78 | --include_imports \ |
| 79 | --include_source_info \ |
| 80 | $< |
uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 81 | |
Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 82 | # Go targets |
| 83 | go-protos: dmi.pb |
| 84 | @echo "Creating *.go.pb files" |
| 85 | @${PROTOC_SH} " \ |
| 86 | set -e -o pipefail; \ |
| 87 | for x in ${PROTO_FILES}; do \ |
| 88 | echo \$$x; \ |
| 89 | protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \ |
| 90 | done" |
| 91 | |
| 92 | dmi.pb: |
| 93 | @echo "Creating $@" |
| 94 | @${PROTOC} -I protos \ |
| 95 | --include_imports --include_source_info \ |
| 96 | --descriptor_set_out=$@ \ |
| 97 | ${PROTO_FILES} |
| 98 | |
Shivanagouda Malaginahalli | 335fe4d | 2021-03-31 16:52:28 +0530 | [diff] [blame^] | 99 | # Cpp targets |
| 100 | cpp-protos: |
| 101 | echo "Creating *.pb.cpp files" |
| 102 | @${PROTOC_SH} " \ |
| 103 | set -e -o pipefail; \ |
| 104 | for x in ${PROTO_FILES}; do \ |
| 105 | echo \$$x; \ |
| 106 | protoc --cpp_out=\$(PROTO_CPP_DEST_DIR) --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` -I protos \$$x; \ |
| 107 | done" |
| 108 | |
Andrea Campanella | 031ea1e | 2020-06-08 11:37:44 +0200 | [diff] [blame] | 109 | go-test: |
| 110 | test/test-go-proto-consistency.sh |
| 111 | ${GO} mod verify |
uwe ottrembka | 66d91ea | 2020-08-11 10:50:55 +0200 | [diff] [blame] | 112 | |
| 113 | python-test: tox.ini |
| 114 | test/test-python-proto-consistency.sh |
Andrea Campanella | add9944 | 2020-10-02 12:02:42 +0200 | [diff] [blame] | 115 | tox |
| 116 | |
| 117 | python-build: setup.py python-protos |
| 118 | rm -rf dist/ |
| 119 | python ./setup.py sdist |
Shivanagouda Malaginahalli | 335fe4d | 2021-03-31 16:52:28 +0530 | [diff] [blame^] | 120 | |
| 121 | cpp-test: |
| 122 | test/test-cpp-proto-consistency.sh |