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 | |
| 18 | # set default shell options |
| 19 | SHELL = bash -e -o pipefail |
| 20 | |
| 21 | # tool containers |
| 22 | VOLTHA_TOOLS_VERSION ?= 2.0.0 |
| 23 | |
| 24 | 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 |
| 25 | 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 |
| 26 | 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 |
| 27 | |
| 28 | # Function to extract the last path component from go_package line in .proto files |
| 29 | define go_package_path |
| 30 | $(shell grep go_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p') |
| 31 | endef |
| 32 | |
| 33 | # Variables |
| 34 | PROTO_FILES := $(sort $(wildcard protos/dmi/*.proto)) |
| 35 | |
| 36 | PROTO_GO_DEST_DIR := go |
| 37 | PROTO_GO_PB:= $(foreach f, $(PROTO_FILES), $(patsubst protos/dmi/%.proto,$(PROTO_GO_DEST_DIR)/$(call go_package_path,$(f))/%.pb.go,$(f))) |
| 38 | # Force pb file to be regenrated every time. Otherwise the make process assumes generated version is still valid |
| 39 | .PHONY: dmi.pb |
| 40 | |
| 41 | print: |
| 42 | @echo "Proto files: $(PROTO_FILES)" |
| 43 | @echo "Go PB files: $(PROTO_GO_PB)" |
| 44 | |
| 45 | # Generic targets |
| 46 | protos: go-protos |
| 47 | |
| 48 | build: protos |
| 49 | |
| 50 | test: go-test |
| 51 | |
| 52 | venv_protos: |
| 53 | virtualenv -p python3 $@;\ |
| 54 | source ./$@/bin/activate ; set -u ;\ |
| 55 | pip install grpcio-tools googleapis-common-protos |
| 56 | |
| 57 | # Go targets |
| 58 | go-protos: dmi.pb |
| 59 | @echo "Creating *.go.pb files" |
| 60 | @${PROTOC_SH} " \ |
| 61 | set -e -o pipefail; \ |
| 62 | for x in ${PROTO_FILES}; do \ |
| 63 | echo \$$x; \ |
| 64 | protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \ |
| 65 | done" |
| 66 | |
| 67 | dmi.pb: |
| 68 | @echo "Creating $@" |
| 69 | @${PROTOC} -I protos \ |
| 70 | --include_imports --include_source_info \ |
| 71 | --descriptor_set_out=$@ \ |
| 72 | ${PROTO_FILES} |
| 73 | |
| 74 | go-test: |
| 75 | test/test-go-proto-consistency.sh |
| 76 | ${GO} mod verify |