blob: 70b26ae50ab451bdffc729e5fca8f4571934d166 [file] [log] [blame]
Joey Armstronge6cdd8e2022-12-29 11:58:15 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrongc2277652023-01-11 17:41:36 -05003# Copyright 2019-2022 Open Networking Foundation (ONF) and the ONF Contributors
Zack Williams52209662019-02-07 10:15:31 -07004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050016# -----------------------------------------------------------------------
17
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050018.DEFAULT_GOAL := test
19
20TOP ?= .
21MAKEDIR ?= $(TOP)/makefiles
22
23$(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s)
24
Joey Armstrongc2277652023-01-11 17:41:36 -050025# Makefile for voltha-protos
26default: test
27
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050028##--------------------##
29##---] INCLUDES [---##
30##--------------------##
Joey Armstrongc2277652023-01-11 17:41:36 -050031include $(MAKEDIR)/consts.mk
32include $(MAKEDIR)/help/include.mk
33include $(MAKEDIR)/help/variables.mk
Zack Williams52209662019-02-07 10:15:31 -070034
Kent Hagerman868dc382020-01-20 11:24:09 -050035# tool containers
David K. Bainbridgec4bf5382021-04-08 16:06:54 +000036VOLTHA_TOOLS_VERSION ?= 2.4.0
Kent Hagerman868dc382020-01-20 11:24:09 -050037
Kent Hagermanea09e422020-02-20 18:56:54 -050038PROTOC = 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
khenaidoo5fc5cea2021-08-11 17:39:16 -040039PROTOC_SH = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/go/src/github.com/opencord/voltha-protos/v5 $(shell test -t 0 && echo "-it") --workdir=/go/src/github.com/opencord/voltha-protos/v5 voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-protoc sh -c
Kent Hagermanea09e422020-02-20 18:56:54 -050040GO = 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
Kent Hagerman868dc382020-01-20 11:24:09 -050041
Zack Williams43bfd9e2019-04-12 13:09:31 -070042# Function to extract the last path component from go_package line in .proto files
43define go_package_path
44$(shell grep go_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p')
45endef
46
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030047# Function to extract the last path component from package line in .proto files
48define java_package_path
49$(shell grep package $(1) | sed -n 's/.*\/\(.*\)";/\1/p')
50endef
51
Zack Williams52209662019-02-07 10:15:31 -070052# Variables
Zack Williams43bfd9e2019-04-12 13:09:31 -070053PROTO_FILES := $(sort $(wildcard protos/voltha_protos/*.proto))
54
Zack Williams52209662019-02-07 10:15:31 -070055PROTO_PYTHON_DEST_DIR := python/voltha_protos
56PROTO_PYTHON_PB2 := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2.py,$(f)))
Matt Jeanneret37e0fc62019-03-07 12:33:21 -050057PROTO_PYTHON_PB2_GRPC := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2_grpc.py,$(f)))
Zack Williams43bfd9e2019-04-12 13:09:31 -070058PROTO_GO_DEST_DIR := go
59PROTO_GO_PB:= $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_GO_DEST_DIR)/$(call go_package_path,$(f))/%.pb.go,$(f)))
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030060PROTO_JAVA_DEST_DIR := java
61PROTO_JAVA_PB := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_JAVA_DEST_DIR)/$(call java_package_path,$(f))/%.pb.java,$(f)))
Zack Williams25e0a322019-06-07 14:07:21 -070062# Force pb file to be regenrated every time. Otherwise the make process assumes generated version is still valid
Kent Hagerman868dc382020-01-20 11:24:09 -050063.PHONY: voltha.pb
Matt Jeanneret15249fa2019-04-12 20:25:31 -040064
Zack Williams52209662019-02-07 10:15:31 -070065print:
Zack Williams43bfd9e2019-04-12 13:09:31 -070066 @echo "Proto files: $(PROTO_FILES)"
67 @echo "Python PB2 files: $(PROTO_PYTHON_PB2)"
68 @echo "Go PB files: $(PROTO_GO_PB)"
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030069 @echo "JAVA PB files: $(PROTO_JAVA_PB)"
Zack Williams52209662019-02-07 10:15:31 -070070
71# Generic targets
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030072protos: python-protos go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -070073
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030074build: protos python-build go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -070075
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030076test: python-test go-test java-test
Zack Williams52209662019-02-07 10:15:31 -070077
Joey Armstrongc2277652023-01-11 17:41:36 -050078clean: python-clean java-clean go-clean
Zack Williams52209662019-02-07 10:15:31 -070079
Joey Armstrongc2277652023-01-11 17:41:36 -050080sterile: clean
81 $(RM) -r venv_protos
82
Zack Williams52209662019-02-07 10:15:31 -070083# Python targets
Kent Hagerman868dc382020-01-20 11:24:09 -050084python-protos: $(PROTO_PYTHON_PB2)
Zack Williams52209662019-02-07 10:15:31 -070085
86venv_protos:
Dinesh Belwalkared6da5e2020-02-25 11:23:57 -080087 virtualenv -p python3 $@;\
Zack Williams52209662019-02-07 10:15:31 -070088 source ./$@/bin/activate ; set -u ;\
khenaidoo5fc5cea2021-08-11 17:39:16 -040089 pip install grpcio==1.39.0 protobuf==3.17.3 grpcio-tools==1.39.0 googleapis-common-protos==1.52.0
Zack Williams52209662019-02-07 10:15:31 -070090
91$(PROTO_PYTHON_DEST_DIR)/%_pb2.py: protos/voltha_protos/%.proto Makefile venv_protos
92 source ./venv_protos/bin/activate ; set -u ;\
93 python -m grpc_tools.protoc \
Zack Williams43bfd9e2019-04-12 13:09:31 -070094 -I protos \
95 --python_out=python \
96 --grpc_python_out=python \
97 --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \
98 --include_imports \
99 --include_source_info \
100 $<
Zack Williams52209662019-02-07 10:15:31 -0700101
Zack Williams43bfd9e2019-04-12 13:09:31 -0700102python-build: setup.py python-protos
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500103 $(RM) -r dist/
Zack Williams52209662019-02-07 10:15:31 -0700104 python ./setup.py sdist
105
106python-test: tox.ini setup.py python-protos
107 tox
108
109python-clean:
Joey Armstrongc2277652023-01-11 17:41:36 -0500110# find python -name '__pycache__' -type d -print0 \
111# | xargs -0 --no-run-if-empty $(RM) -r
112 find python -name '*.pyc' -type f -print0 \
113 | xargs -0 --no-run-if-empty $(RM)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500114 $(RM) -r \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700115 .coverage \
116 .tox \
117 coverage.xml \
118 dist \
119 nose2-results.xml \
120 python/__pycache__ \
121 python/test/__pycache__ \
122 python/voltha_protos.egg-info \
123 venv_protos \
124 $(PROTO_PYTHON_DEST_DIR)/*.desc \
125 $(PROTO_PYTHON_PB2) \
126 $(PROTO_PYTHON_PB2_GRPC)
Zack Williams52209662019-02-07 10:15:31 -0700127
Joey Armstrongc2277652023-01-11 17:41:36 -0500128# Why are we removing files under revision control ?
khenaidoo5fc5cea2021-08-11 17:39:16 -0400129go-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500130 $(RM) -r go/*
khenaidoo5fc5cea2021-08-11 17:39:16 -0400131
Zack Williams52209662019-02-07 10:15:31 -0700132# Go targets
Kent Hagerman868dc382020-01-20 11:24:09 -0500133go-protos: voltha.pb
134 @echo "Creating *.go.pb files"
135 @${PROTOC_SH} " \
136 set -e -o pipefail; \
137 for x in ${PROTO_FILES}; do \
138 echo \$$x; \
139 protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \
140 done"
Zack Williams43bfd9e2019-04-12 13:09:31 -0700141
Kent Hagerman868dc382020-01-20 11:24:09 -0500142voltha.pb:
Zack Williams43bfd9e2019-04-12 13:09:31 -0700143 @echo "Creating $@"
Kent Hagerman868dc382020-01-20 11:24:09 -0500144 @${PROTOC} -I protos -I protos/google/api \
145 --include_imports --include_source_info \
146 --descriptor_set_out=$@ \
147 ${PROTO_FILES}
Zack Williams43bfd9e2019-04-12 13:09:31 -0700148
Kent Hagerman868dc382020-01-20 11:24:09 -0500149go-test:
William Kurkianad745652019-03-20 08:45:51 -0400150 test/test-go-proto-consistency.sh
Kent Hagerman868dc382020-01-20 11:24:09 -0500151 ${GO} mod verify
Zack Williams52209662019-02-07 10:15:31 -0700152
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300153# Java targets
Kent Hagerman868dc382020-01-20 11:24:09 -0500154java-protos: voltha.pb
155 @echo "Creating java files"
156 @mkdir -p java_temp/src/main/java
157 @${PROTOC_SH} " \
158 set -e -o pipefail; \
159 for x in ${PROTO_FILES}; do \
160 echo \$$x; \
161 protoc --java_out=java_temp/src/main/java -I protos \$$x; \
162 done"
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500163 #TODO: generate directly to the final location
Kent Hagerman868dc382020-01-20 11:24:09 -0500164 @mkdir -p java
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300165 cp -r java_temp/src/main/java/* java/
166
167# Tests if the generated java classes are compilable
168java-test: java-protos
169 cp test/pom.xml java_temp
170 cd java_temp && mvn compile
171
172java-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500173 $(RM) -r java
174 $(RM) -r java_temp
175
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500176# [EOF]