Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 3 | # Copyright 2019-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 4 | # |
| 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 Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
| 17 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 18 | .PHONY: test |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 19 | .DEFAULT_GOAL := test |
| 20 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 21 | ##-------------------## |
| 22 | ##---] GLOBALS [---## |
| 23 | ##-------------------## |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 24 | TOP ?= . |
| 25 | MAKEDIR ?= $(TOP)/makefiles |
| 26 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 27 | export SHELL := bash -e -o pipefail |
| 28 | |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 29 | $(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s) |
| 30 | |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 31 | # Makefile for voltha-protos |
| 32 | default: test |
| 33 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 34 | ## Library linting |
| 35 | # NO-LINT-MAKEFILE := true # cleanup needed |
| 36 | NO-LINT-SHELL := true # cleanup needed |
| 37 | |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 38 | ##--------------------## |
| 39 | ##---] INCLUDES [---## |
| 40 | ##--------------------## |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 41 | include $(MAKEDIR)/include.mk |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 42 | |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 43 | # tool containers |
David K. Bainbridge | c4bf538 | 2021-04-08 16:06:54 +0000 | [diff] [blame] | 44 | VOLTHA_TOOLS_VERSION ?= 2.4.0 |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 45 | |
Kent Hagerman | ea09e42 | 2020-02-20 18:56:54 -0500 | [diff] [blame] | 46 | 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 |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 47 | PROTOC_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 Hagerman | ea09e42 | 2020-02-20 18:56:54 -0500 | [diff] [blame] | 48 | 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 |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 49 | |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 50 | # Function to extract the last path component from go_package line in .proto files |
| 51 | define go_package_path |
| 52 | $(shell grep go_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p') |
| 53 | endef |
| 54 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 55 | # Function to extract the last path component from package line in .proto files |
| 56 | define java_package_path |
| 57 | $(shell grep package $(1) | sed -n 's/.*\/\(.*\)";/\1/p') |
| 58 | endef |
| 59 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 60 | # Variables |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 61 | PROTO_FILES := $(sort $(wildcard protos/voltha_protos/*.proto)) |
| 62 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 63 | PROTO_PYTHON_DEST_DIR := python/voltha_protos |
| 64 | PROTO_PYTHON_PB2 := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2.py,$(f))) |
Matt Jeanneret | 37e0fc6 | 2019-03-07 12:33:21 -0500 | [diff] [blame] | 65 | PROTO_PYTHON_PB2_GRPC := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2_grpc.py,$(f))) |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 66 | PROTO_GO_DEST_DIR := go |
| 67 | PROTO_GO_PB:= $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_GO_DEST_DIR)/$(call go_package_path,$(f))/%.pb.go,$(f))) |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 68 | PROTO_JAVA_DEST_DIR := java |
| 69 | PROTO_JAVA_PB := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_JAVA_DEST_DIR)/$(call java_package_path,$(f))/%.pb.java,$(f))) |
Zack Williams | 25e0a32 | 2019-06-07 14:07:21 -0700 | [diff] [blame] | 70 | # Force pb file to be regenrated every time. Otherwise the make process assumes generated version is still valid |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 71 | .PHONY: voltha.pb |
Matt Jeanneret | 15249fa | 2019-04-12 20:25:31 -0400 | [diff] [blame] | 72 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 73 | print: |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 74 | @echo "Proto files: $(PROTO_FILES)" |
| 75 | @echo "Python PB2 files: $(PROTO_PYTHON_PB2)" |
| 76 | @echo "Go PB files: $(PROTO_GO_PB)" |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 77 | @echo "JAVA PB files: $(PROTO_JAVA_PB)" |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 78 | |
| 79 | # Generic targets |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 80 | protos: python-protos go-protos java-protos |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 81 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 82 | build: protos python-build go-protos java-protos |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 83 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 84 | test: python-test go-test java-test |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 85 | |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 86 | clean: python-clean java-clean go-clean |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 87 | |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 88 | sterile: clean |
| 89 | $(RM) -r venv_protos |
| 90 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 91 | # Python targets |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 92 | python-protos: $(PROTO_PYTHON_PB2) |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 93 | |
| 94 | venv_protos: |
Dinesh Belwalkar | ed6da5e | 2020-02-25 11:23:57 -0800 | [diff] [blame] | 95 | virtualenv -p python3 $@;\ |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 96 | source ./$@/bin/activate ; set -u ;\ |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 97 | pip install grpcio==1.39.0 protobuf==3.17.3 grpcio-tools==1.39.0 googleapis-common-protos==1.52.0 |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 98 | |
| 99 | $(PROTO_PYTHON_DEST_DIR)/%_pb2.py: protos/voltha_protos/%.proto Makefile venv_protos |
| 100 | source ./venv_protos/bin/activate ; set -u ;\ |
| 101 | python -m grpc_tools.protoc \ |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 102 | -I protos \ |
| 103 | --python_out=python \ |
| 104 | --grpc_python_out=python \ |
| 105 | --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \ |
| 106 | --include_imports \ |
| 107 | --include_source_info \ |
| 108 | $< |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 109 | |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 110 | python-build: setup.py python-protos |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 111 | $(RM) -r dist/ |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 112 | python ./setup.py sdist |
| 113 | |
| 114 | python-test: tox.ini setup.py python-protos |
| 115 | tox |
| 116 | |
| 117 | python-clean: |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 118 | find python -name '__pycache__' -type d -print0 \ |
| 119 | | xargs -0 --no-run-if-empty $(RM) -r |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 120 | find python -name '*.pyc' -type f -print0 \ |
| 121 | | xargs -0 --no-run-if-empty $(RM) |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 122 | $(RM) -r \ |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 123 | .coverage \ |
| 124 | .tox \ |
| 125 | coverage.xml \ |
| 126 | dist \ |
| 127 | nose2-results.xml \ |
| 128 | python/__pycache__ \ |
| 129 | python/test/__pycache__ \ |
| 130 | python/voltha_protos.egg-info \ |
| 131 | venv_protos \ |
| 132 | $(PROTO_PYTHON_DEST_DIR)/*.desc \ |
| 133 | $(PROTO_PYTHON_PB2) \ |
| 134 | $(PROTO_PYTHON_PB2_GRPC) |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 135 | |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 136 | # Why are we removing files under revision control ? |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 137 | go-clean: |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 138 | $(RM) -r go/* |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 139 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 140 | # Go targets |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 141 | go-protos: voltha.pb |
| 142 | @echo "Creating *.go.pb files" |
| 143 | @${PROTOC_SH} " \ |
| 144 | set -e -o pipefail; \ |
| 145 | for x in ${PROTO_FILES}; do \ |
| 146 | echo \$$x; \ |
| 147 | protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \ |
| 148 | done" |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 149 | |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 150 | voltha.pb: |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 151 | @echo "Creating $@" |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 152 | @${PROTOC} -I protos -I protos/google/api \ |
| 153 | --include_imports --include_source_info \ |
| 154 | --descriptor_set_out=$@ \ |
| 155 | ${PROTO_FILES} |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 156 | |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 157 | go-test: |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 158 | test/test-go-proto-consistency.sh |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 159 | ${GO} mod verify |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 160 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 161 | # Java targets |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 162 | java-protos: voltha.pb |
| 163 | @echo "Creating java files" |
| 164 | @mkdir -p java_temp/src/main/java |
| 165 | @${PROTOC_SH} " \ |
| 166 | set -e -o pipefail; \ |
| 167 | for x in ${PROTO_FILES}; do \ |
| 168 | echo \$$x; \ |
| 169 | protoc --java_out=java_temp/src/main/java -I protos \$$x; \ |
| 170 | done" |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 171 | #TODO: generate directly to the final location |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 172 | @mkdir -p java |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 173 | cp -r java_temp/src/main/java/* java/ |
| 174 | |
| 175 | # Tests if the generated java classes are compilable |
| 176 | java-test: java-protos |
| 177 | cp test/pom.xml java_temp |
| 178 | cd java_temp && mvn compile |
| 179 | |
| 180 | java-clean: |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 181 | $(RM) -r java |
| 182 | $(RM) -r java_temp |
| 183 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 184 | # placeholder for library targets |
| 185 | lint : |
| 186 | |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 187 | # [EOF] |