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 | |
| 27 | $(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s) |
| 28 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 29 | ##-------------------------- |
| 30 | ## Enable setup.py debugging |
| 31 | ##-------------------------- |
| 32 | # https://docs.python.org/3/distutils/setupscript.html#debugging-the-setup-script |
| 33 | export DISTUTILS_DEBUG := 1 |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 34 | export DOCKER_DEBUG := 1 |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 35 | |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 36 | # Makefile for voltha-protos |
| 37 | default: test |
| 38 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 39 | ## Library linting |
| 40 | # NO-LINT-MAKEFILE := true # cleanup needed |
| 41 | NO-LINT-SHELL := true # cleanup needed |
| 42 | |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 43 | ##--------------------## |
| 44 | ##---] INCLUDES [---## |
| 45 | ##--------------------## |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 46 | include $(MAKEDIR)/include.mk |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 47 | |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 48 | # Function to extract the last path component from go_package line in .proto files |
| 49 | define go_package_path |
| 50 | $(shell grep go_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p') |
| 51 | endef |
| 52 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 53 | # Function to extract the last path component from package line in .proto files |
| 54 | define java_package_path |
| 55 | $(shell grep package $(1) | sed -n 's/.*\/\(.*\)";/\1/p') |
| 56 | endef |
| 57 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 58 | # Variables |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 59 | PROTO_FILES := $(sort $(wildcard protos/voltha_protos/*.proto)) |
| 60 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 61 | PROTO_PYTHON_DEST_DIR := python/voltha_protos |
| 62 | 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] | 63 | 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] | 64 | PROTO_GO_DEST_DIR := go |
| 65 | 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] | 66 | PROTO_JAVA_DEST_DIR := java |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 67 | PROTO_JAVA_PB := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_JAVA_DEST_DIR)/$(call java_package_path,$(f))/%.pb.java,$(f))) |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 68 | |
Zack Williams | 25e0a32 | 2019-06-07 14:07:21 -0700 | [diff] [blame] | 69 | # 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] | 70 | .PHONY: voltha.pb |
Matt Jeanneret | 15249fa | 2019-04-12 20:25:31 -0400 | [diff] [blame] | 71 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 72 | print: |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 73 | @echo "Proto files: $(PROTO_FILES)" |
| 74 | @echo "Python PB2 files: $(PROTO_PYTHON_PB2)" |
| 75 | @echo "Go PB files: $(PROTO_GO_PB)" |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 76 | @echo "JAVA PB files: $(PROTO_JAVA_PB)" |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 77 | |
| 78 | # Generic targets |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 79 | protos: python-protos go-protos java-protos |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 80 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 81 | build: protos python-build go-protos java-protos |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 82 | |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 83 | test: python-test go-test java-test |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 84 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 85 | clean :: python-clean java-clean go-clean |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 86 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 87 | sterile :: clean |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 88 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 89 | # Python targets |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 90 | python-protos: $(PROTO_PYTHON_PB2) |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 91 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 92 | ## ----------------------------------------------------------------------- |
| 93 | ## ----------------------------------------------------------------------- |
| 94 | $(PROTO_PYTHON_DEST_DIR)/%_pb2.py: \ |
| 95 | protos/voltha_protos/%.proto \ |
| 96 | Makefile \ |
| 97 | $(venv-activate-script) |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 98 | |
| 99 | @echo |
| 100 | @echo "** -----------------------------------------------------------------------" |
| 101 | @echo "** $(MAKE): processing target [$@]" |
| 102 | @echo "** -----------------------------------------------------------------------" |
| 103 | |
| 104 | $(activate) && python -m grpc_tools.protoc \ |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 105 | -I protos \ |
| 106 | --python_out=python \ |
| 107 | --grpc_python_out=python \ |
| 108 | --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \ |
| 109 | --include_imports \ |
| 110 | --include_source_info \ |
| 111 | $< |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 112 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 113 | ## ----------------------------------------------------------------------- |
| 114 | ## Intent: |
| 115 | ## ----------------------------------------------------------------------- |
| 116 | show: |
| 117 | $(call banner-enter,target $@) |
| 118 | @echo |
| 119 | $(call banner-leave,target $@) |
| 120 | |
| 121 | ## ----------------------------------------------------------------------- |
| 122 | ## Intent: |
| 123 | ## ----------------------------------------------------------------------- |
| 124 | python-build: setup.py python-protos |
| 125 | |
| 126 | $(call banner-enter,target $@) |
| 127 | |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 128 | $(RM) -r dist/ |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 129 | python ./setup.py sdist |
| 130 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 131 | $(call banner-leave,target $@) |
| 132 | |
| 133 | ## ----------------------------------------------------------------------- |
| 134 | ## Intent: |
| 135 | ## ----------------------------------------------------------------------- |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 136 | python-test: tox.ini setup.py python-protos |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 137 | $(call banner-enter,target $@) |
| 138 | |
| 139 | $(activate) && python --version |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 140 | tox |
| 141 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 142 | $(call banner-leave,target $@) |
| 143 | |
| 144 | ## ----------------------------------------------------------------------- |
| 145 | ## Intent: |
| 146 | ## ----------------------------------------------------------------------- |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 147 | python-clean: |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 148 | find python -name '__pycache__' -type d -print0 \ |
| 149 | | xargs -0 --no-run-if-empty $(RM) -r |
Joey Armstrong | c227765 | 2023-01-11 17:41:36 -0500 | [diff] [blame] | 150 | find python -name '*.pyc' -type f -print0 \ |
| 151 | | xargs -0 --no-run-if-empty $(RM) |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 152 | $(RM) -r \ |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 153 | .coverage \ |
| 154 | .tox \ |
| 155 | coverage.xml \ |
| 156 | dist \ |
| 157 | nose2-results.xml \ |
| 158 | python/__pycache__ \ |
| 159 | python/test/__pycache__ \ |
| 160 | python/voltha_protos.egg-info \ |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 161 | "$(venv-abs-path)" \ |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 162 | $(PROTO_PYTHON_DEST_DIR)/*.desc \ |
| 163 | $(PROTO_PYTHON_PB2) \ |
| 164 | $(PROTO_PYTHON_PB2_GRPC) |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 165 | |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 166 | ## ----------------------------------------------------------------------- |
| 167 | ## Intent: Revert go to a clean state. |
| 168 | ## o TODO - go/ directory should not be placed under revision control. |
| 169 | ## o Build should retrieve versioned sources from a central repo. |
| 170 | ## ----------------------------------------------------------------------- |
khenaidoo | 5fc5cea | 2021-08-11 17:39:16 -0400 | [diff] [blame] | 171 | go-clean: |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 172 | $(RM) -r go/* |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 173 | $(HIDE)$(MAKE) repair |
| 174 | |
| 175 | ## ----------------------------------------------------------------------- |
| 176 | ## Intent: Recover from a fatal failed build state: |
| 177 | ## o build removes go/ while regenerating prototypes. |
| 178 | ## o chicken-n-egg: make becomes fatal when go/ is removed and proten fails. |
| 179 | ## ----------------------------------------------------------------------- |
| 180 | repair: |
| 181 | /usr/bin/env git checkout go |
| 182 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 183 | ## ----------------------------------------------------------------------- |
| 184 | ## Intent: Go targets |
| 185 | ## ----------------------------------------------------------------------- |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 186 | go-protos: voltha.pb |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 187 | |
| 188 | @echo |
| 189 | @echo "** -----------------------------------------------------------------------" |
| 190 | @echo "** $(MAKE): processing target [$@]" |
| 191 | @echo "** Creating *.go.pb files" |
| 192 | @echo "** -----------------------------------------------------------------------" |
| 193 | |
| 194 | @echo |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 195 | @echo "PROTO_FILES=$(PROTO_FILES)" | tr ' ' '\n' |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 196 | |
| 197 | @echo |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 198 | ${PROTOC_SH} $(quote-double)\ |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 199 | set -e -o pipefail; \ |
| 200 | for x in ${PROTO_FILES}; do \ |
| 201 | echo \$$x; \ |
| 202 | protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \ |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 203 | done$(quote-double) |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 204 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 205 | ## ----------------------------------------------------------------------- |
| 206 | ## Intent: |
| 207 | ## ----------------------------------------------------------------------- |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 208 | voltha.pb: |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 209 | $(call banner-enter,target $@) |
| 210 | |
| 211 | ${PROTOC} \ |
| 212 | -I protos \ |
| 213 | -I protos/google/api \ |
| 214 | --include_imports \ |
| 215 | --include_source_info \ |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 216 | --descriptor_set_out=$@ \ |
| 217 | ${PROTO_FILES} |
Zack Williams | 43bfd9e | 2019-04-12 13:09:31 -0700 | [diff] [blame] | 218 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 219 | $(call banner-leave,target $@) |
| 220 | |
| 221 | ## ----------------------------------------------------------------------- |
| 222 | ## Intent: |
| 223 | ## ----------------------------------------------------------------------- |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 224 | go-test: |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 225 | $(call banner-enter,target $@) |
| 226 | |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 227 | test/test-go-proto-consistency.sh |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 228 | ${GO} mod verify |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 229 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 230 | $(call banner-leave,target $@) |
| 231 | |
| 232 | ## ----------------------------------------------------------------------- |
| 233 | ## Intent: Java targets |
| 234 | ## ----------------------------------------------------------------------- |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 235 | java-protos: voltha.pb |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 236 | $(call banner-enter,target $@) |
| 237 | |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 238 | @mkdir -p java_temp/src/main/java |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 239 | @${PROTOC_SH} $(quote-double) \ |
Kent Hagerman | 868dc38 | 2020-01-20 11:24:09 -0500 | [diff] [blame] | 240 | set -e -o pipefail; \ |
| 241 | for x in ${PROTO_FILES}; do \ |
| 242 | echo \$$x; \ |
| 243 | protoc --java_out=java_temp/src/main/java -I protos \$$x; \ |
Joey Armstrong | 761579c | 2023-05-08 11:59:57 -0400 | [diff] [blame] | 244 | done$(quote-double) |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 245 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 246 | # Move files into place after all prototypes have generated. |
| 247 | # TODO: Remove the extra step, use makefile deps and |
| 248 | # generate in-place as needed. |
| 249 | @mkdir -p java |
| 250 | cp -r java_temp/src/main/java/* java |
| 251 | |
| 252 | $(call banner-leave,target $@) |
| 253 | |
| 254 | ## ----------------------------------------------------------------------- |
| 255 | ## Intent: Tests if the generated java classes are compilable |
| 256 | ## ----------------------------------------------------------------------- |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 257 | java-test: java-protos |
| 258 | cp test/pom.xml java_temp |
| 259 | cd java_temp && mvn compile |
| 260 | |
Joey Armstrong | 670d40c | 2023-05-11 20:49:26 -0400 | [diff] [blame] | 261 | ## ----------------------------------------------------------------------- |
| 262 | ## Intent: Custodial service |
| 263 | ## ----------------------------------------------------------------------- |
Serkant Uluderya | cbcfaa4 | 2019-10-18 13:25:08 +0300 | [diff] [blame] | 264 | java-clean: |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 265 | $(RM) -r java |
| 266 | $(RM) -r java_temp |
| 267 | |
Joey Armstrong | e66eaaf | 2023-01-15 18:58:52 -0500 | [diff] [blame] | 268 | # placeholder for library targets |
| 269 | lint : |
| 270 | |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 271 | # [EOF] |