blob: 23b73c52fcfd94d0f80c067b61ad942b9dd31fc9 [file] [log] [blame]
Joey Armstronge6cdd8e2022-12-29 11:58:15 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong0cbed332024-07-17 18:10:46 -04003# Copyright 2019-2024 Open Networking Foundation 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# -----------------------------------------------------------------------
Joey Armstrong0cbed332024-07-17 18:10:46 -040017# SPDX-FileCopyrightText: 2019-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050020
Joey Armstronge66eaaf2023-01-15 18:58:52 -050021.PHONY: test
Joey Armstrong0cbed332024-07-17 18:10:46 -040022export .DEFAULT_GOAL := test
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050023
Joey Armstronge66eaaf2023-01-15 18:58:52 -050024##-------------------##
25##---] GLOBALS [---##
26##-------------------##
Eric Ballf1055a92024-09-05 11:01:28 -070027TOP ?= .
28MAKEDIR ?= $(TOP)/makefiles
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050029
Eric Ballf1055a92024-09-05 11:01:28 -070030$(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050031
Joey Armstrong761579c2023-05-08 11:59:57 -040032##--------------------------
33## Enable setup.py debugging
34##--------------------------
35# https://docs.python.org/3/distutils/setupscript.html#debugging-the-setup-script
Joey Armstrong56b36782023-05-30 17:30:11 -040036# export DISTUTILS_DEBUG := 1 # verbose: pip
37export DOCKER_DEBUG := 1 # verbose: docker
Joey Armstrong761579c2023-05-08 11:59:57 -040038
Eric Ballf1055a92024-09-05 11:01:28 -070039# Makefile for voltha-protos
40default: test
41
42## Library linting
43# NO-LINT-MAKEFILE := true # cleanup needed
44NO-LINT-SHELL := true # cleanup needed
45
46##--------------------##
47##---] INCLUDES [---##
48##--------------------##
49include $(MAKEDIR)/include.mk
50
Zack Williams43bfd9e2019-04-12 13:09:31 -070051# Function to extract the last path component from go_package line in .proto files
52define go_package_path
53$(shell grep go_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p')
54endef
55
Joey Armstronge05f6492023-05-31 11:27:31 -040056# -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030057# Function to extract the last path component from package line in .proto files
Joey Armstronge05f6492023-05-31 11:27:31 -040058# % grep 'package' will match:
59# o package <name> ;
60# o option java_package='<dot-pkg-fqdn>
61# -----------------------------------------------------------------------
62# RETURN: protos/voltha_protos/common.proto => common
63# -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030064define java_package_path
65$(shell grep package $(1) | sed -n 's/.*\/\(.*\)";/\1/p')
66endef
67
Zack Williams52209662019-02-07 10:15:31 -070068# Variables
Zack Williams43bfd9e2019-04-12 13:09:31 -070069PROTO_FILES := $(sort $(wildcard protos/voltha_protos/*.proto))
70
Zack Williams52209662019-02-07 10:15:31 -070071PROTO_PYTHON_DEST_DIR := python/voltha_protos
72PROTO_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 -050073PROTO_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 -070074PROTO_GO_DEST_DIR := go
75PROTO_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 +030076PROTO_JAVA_DEST_DIR := java
Joey Armstrong670d40c2023-05-11 20:49:26 -040077PROTO_JAVA_PB := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_JAVA_DEST_DIR)/$(call java_package_path,$(f))/%.pb.java,$(f)))
Joey Armstrong761579c2023-05-08 11:59:57 -040078
Eric Ballf1055a92024-09-05 11:01:28 -070079# 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 -050080.PHONY: voltha.pb
Matt Jeanneret15249fa2019-04-12 20:25:31 -040081
Joey Armstronge0c1a8d2023-04-13 15:16:21 -040082##----------------##
83##---] DEPS [---##
84##----------------##
85infra-deps := $(null)
86infra-deps += Makefile
87infra-deps += $(venv-activate-script)
88
89## -----------------------------------------------------------------------
90## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -070091print:
Zack Williams43bfd9e2019-04-12 13:09:31 -070092 @echo "Proto files: $(PROTO_FILES)"
93 @echo "Python PB2 files: $(PROTO_PYTHON_PB2)"
94 @echo "Go PB files: $(PROTO_GO_PB)"
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030095 @echo "JAVA PB files: $(PROTO_JAVA_PB)"
Zack Williams52209662019-02-07 10:15:31 -070096
Joey Armstrong0cbed332024-07-17 18:10:46 -040097## -----------------------------------------------------------------------
98## Generic targets
99## -----------------------------------------------------------------------
100.PHONY: protos
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300101protos: python-protos go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -0700102
Joey Armstrong0cbed332024-07-17 18:10:46 -0400103.PHONY: build
104build: protos python-build
Zack Williams52209662019-02-07 10:15:31 -0700105
Joey Armstrong0cbed332024-07-17 18:10:46 -0400106.PHONY: test
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300107test: python-test go-test java-test
Zack Williams52209662019-02-07 10:15:31 -0700108
Joey Armstrong761579c2023-05-08 11:59:57 -0400109clean :: python-clean java-clean go-clean
Zack Williams52209662019-02-07 10:15:31 -0700110
Joey Armstrong761579c2023-05-08 11:59:57 -0400111sterile :: clean
Joey Armstrongc2277652023-01-11 17:41:36 -0500112
Joey Armstronge0c1a8d2023-04-13 15:16:21 -0400113## -----------------------------------------------------------------------
114## Python targets
115## -----------------------------------------------------------------------
116python-protos: $(infra-deps) $(PROTO_PYTHON_PB2)
Zack Williams52209662019-02-07 10:15:31 -0700117
Joey Armstrong761579c2023-05-08 11:59:57 -0400118## -----------------------------------------------------------------------
119## -----------------------------------------------------------------------
120$(PROTO_PYTHON_DEST_DIR)/%_pb2.py: \
121 protos/voltha_protos/%.proto \
122 Makefile \
123 $(venv-activate-script)
Joey Armstrong670d40c2023-05-11 20:49:26 -0400124
125 @echo
126 @echo "** -----------------------------------------------------------------------"
127 @echo "** $(MAKE): processing target [$@]"
128 @echo "** -----------------------------------------------------------------------"
129
130 $(activate) && python -m grpc_tools.protoc \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700131 -I protos \
132 --python_out=python \
133 --grpc_python_out=python \
134 --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \
135 --include_imports \
136 --include_source_info \
137 $<
Zack Williams52209662019-02-07 10:15:31 -0700138
Joey Armstrong670d40c2023-05-11 20:49:26 -0400139## -----------------------------------------------------------------------
140## Intent:
141## -----------------------------------------------------------------------
142show:
143 $(call banner-enter,target $@)
144 @echo
145 $(call banner-leave,target $@)
146
147## -----------------------------------------------------------------------
148## Intent:
149## -----------------------------------------------------------------------
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400150python-build: setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400151
152 $(call banner-enter,target $@)
153
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500154 $(RM) -r dist/
Joey Armstrong0cbed332024-07-17 18:10:46 -0400155 $(activate) && python ./setup.py sdist
Zack Williams52209662019-02-07 10:15:31 -0700156
Joey Armstrong670d40c2023-05-11 20:49:26 -0400157 $(call banner-leave,target $@)
158
159## -----------------------------------------------------------------------
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400160## Intent: Invoke tox to install a python interpreter then run tests.
161## -----------------------------------------------------------------------
162## See Also:
163## o https://tox.wiki/en/latest/cli_interface.html#tox-verbosity
164## every -v increases, every -q decreases verbosity level,
165## default WARNING (level:2)
166## map 0=CRITICAL|1=ERROR|2=WARNING|3=INFO|4=DEBUG|5=NOTSET
Joey Armstrong670d40c2023-05-11 20:49:26 -0400167## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700168python-test: tox.ini setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400169 $(call banner-enter,target $@)
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400170
Joey Armstrong670d40c2023-05-11 20:49:26 -0400171 $(activate) && python --version
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400172 tox -vvv
173
Joey Armstrong670d40c2023-05-11 20:49:26 -0400174 $(call banner-leave,target $@)
175
176## -----------------------------------------------------------------------
177## Intent:
178## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700179python-clean:
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500180 find python -name '__pycache__' -type d -print0 \
181 | xargs -0 --no-run-if-empty $(RM) -r
Joey Armstrongc2277652023-01-11 17:41:36 -0500182 find python -name '*.pyc' -type f -print0 \
183 | xargs -0 --no-run-if-empty $(RM)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500184 $(RM) -r \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700185 .coverage \
186 .tox \
187 coverage.xml \
188 dist \
189 nose2-results.xml \
190 python/__pycache__ \
191 python/test/__pycache__ \
192 python/voltha_protos.egg-info \
Joey Armstrong761579c2023-05-08 11:59:57 -0400193 "$(venv-abs-path)" \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700194 $(PROTO_PYTHON_DEST_DIR)/*.desc \
195 $(PROTO_PYTHON_PB2) \
196 $(PROTO_PYTHON_PB2_GRPC)
Zack Williams52209662019-02-07 10:15:31 -0700197
Joey Armstrong761579c2023-05-08 11:59:57 -0400198## -----------------------------------------------------------------------
199## Intent: Revert go to a clean state.
200## o TODO - go/ directory should not be placed under revision control.
201## o Build should retrieve versioned sources from a central repo.
202## -----------------------------------------------------------------------
khenaidoo5fc5cea2021-08-11 17:39:16 -0400203go-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500204 $(RM) -r go/*
Joey Armstrong761579c2023-05-08 11:59:57 -0400205 $(HIDE)$(MAKE) repair
206
207## -----------------------------------------------------------------------
208## Intent: Recover from a fatal failed build state:
209## o build removes go/ while regenerating prototypes.
210## o chicken-n-egg: make becomes fatal when go/ is removed and proten fails.
211## -----------------------------------------------------------------------
212repair:
213 /usr/bin/env git checkout go
214
Joey Armstrong670d40c2023-05-11 20:49:26 -0400215## -----------------------------------------------------------------------
216## Intent: Go targets
217## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500218go-protos: voltha.pb
Joey Armstrong670d40c2023-05-11 20:49:26 -0400219
Joey Armstrong56b36782023-05-30 17:30:11 -0400220 $(call banner-enter,target $@)
Joey Armstrong50080092023-07-06 15:18:37 -0400221 @echo "** Creating *.go.pb files"
Joey Armstrong1ff23e92023-07-13 16:24:32 -0400222
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500223 $(if $(LOCAL_FIX_PERMS),chmod -R o+w $(PROTO_GO_DEST_DIR))
224
Joey Armstrong761579c2023-05-08 11:59:57 -0400225 ${PROTOC_SH} $(quote-double)\
Kent Hagerman868dc382020-01-20 11:24:09 -0500226 set -e -o pipefail; \
227 for x in ${PROTO_FILES}; do \
228 echo \$$x; \
229 protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400230 done\
231 $(quote-double)
232
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500233 $(if $(LOCAL_FIX_PERMS),chmod -R o-w $(PROTO_GO_DEST_DIR))
234
Joey Armstrong56b36782023-05-30 17:30:11 -0400235 $(call banner-leave,target $@)
Zack Williams43bfd9e2019-04-12 13:09:31 -0700236
Joey Armstrong670d40c2023-05-11 20:49:26 -0400237## -----------------------------------------------------------------------
Eric Ballf1055a92024-09-05 11:01:28 -0700238## Intent:
Joey Armstrong56b36782023-05-30 17:30:11 -0400239## ----------------------------------------------------------------------
Eric Ballf1055a92024-09-05 11:01:28 -0700240voltha.pb: show-proto-files
Joey Armstrong670d40c2023-05-11 20:49:26 -0400241 $(call banner-enter,target $@)
242
243 ${PROTOC} \
244 -I protos \
245 -I protos/google/api \
246 --include_imports \
247 --include_source_info \
Kent Hagerman868dc382020-01-20 11:24:09 -0500248 --descriptor_set_out=$@ \
249 ${PROTO_FILES}
Zack Williams43bfd9e2019-04-12 13:09:31 -0700250
Joey Armstrong670d40c2023-05-11 20:49:26 -0400251 $(call banner-leave,target $@)
252
253## -----------------------------------------------------------------------
254## Intent:
255## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500256go-test:
Joey Armstrong670d40c2023-05-11 20:49:26 -0400257 $(call banner-enter,target $@)
258
William Kurkianad745652019-03-20 08:45:51 -0400259 test/test-go-proto-consistency.sh
Kent Hagerman868dc382020-01-20 11:24:09 -0500260 ${GO} mod verify
Zack Williams52209662019-02-07 10:15:31 -0700261
Joey Armstrong670d40c2023-05-11 20:49:26 -0400262 $(call banner-leave,target $@)
263
264## -----------------------------------------------------------------------
265## Intent: Java targets
266## -----------------------------------------------------------------------
Joey Armstrong56b36782023-05-30 17:30:11 -0400267
268java-protos-dirs += java_temp/src/main/java
269java-protos-dirs += java_temp/src/main/java/org
270# local docker problem
271java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter
272java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter_service
273
274mkdir-args += -vp
Joey Armstrong56b36782023-05-30 17:30:11 -0400275
Kent Hagerman868dc382020-01-20 11:24:09 -0500276java-protos: voltha.pb
Joey Armstrong56b36782023-05-30 17:30:11 -0400277
Joey Armstrong670d40c2023-05-11 20:49:26 -0400278 $(call banner-enter,target $@)
279
Joey Armstrong56b36782023-05-30 17:30:11 -0400280 mkdir $(mkdir-args) $(java-protos-dirs)
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500281
Joey Armstrong56b36782023-05-30 17:30:11 -0400282 $(docker-sh) $(quote-double) find $(java-protos-dirs) -print0 \
283 | xargs -0 -n1 /bin/ls -ld $(quote-double)
284
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500285 $(if $(LOCAL_FIX_PERMS),chmod -R o+w java_temp)
Joey Armstrong761579c2023-05-08 11:59:57 -0400286 @${PROTOC_SH} $(quote-double) \
Kent Hagerman868dc382020-01-20 11:24:09 -0500287 set -e -o pipefail; \
288 for x in ${PROTO_FILES}; do \
289 echo \$$x; \
290 protoc --java_out=java_temp/src/main/java -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400291 done\
292 $(quote-double)
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500293 $(if $(LOCAL_FIX_PERMS),chmod -R o-w java_temp)
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300294
Joey Armstrong670d40c2023-05-11 20:49:26 -0400295 # Move files into place after all prototypes have generated.
296 # TODO: Remove the extra step, use makefile deps and
297 # generate in-place as needed.
298 @mkdir -p java
Joey Armstrong50080092023-07-06 15:18:37 -0400299 rsync -r --checksum java_temp/src/main/java/. java/.
Joey Armstrong670d40c2023-05-11 20:49:26 -0400300
301 $(call banner-leave,target $@)
302
303## -----------------------------------------------------------------------
304## Intent: Tests if the generated java classes are compilable
305## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300306java-test: java-protos
307 cp test/pom.xml java_temp
308 cd java_temp && mvn compile
309
Joey Armstrong670d40c2023-05-11 20:49:26 -0400310## -----------------------------------------------------------------------
311## Intent: Custodial service
312## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300313java-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500314 $(RM) -r java
315 $(RM) -r java_temp
316
Joey Armstrong56b36782023-05-30 17:30:11 -0400317## -----------------------------------------------------------------------
318## Intent: Placeholder for library targets
319## -----------------------------------------------------------------------
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500320lint :
321
Joey Armstrong56b36782023-05-30 17:30:11 -0400322## -----------------------------------------------------------------------
Joey Armstrong50080092023-07-06 15:18:37 -0400323## Intent: Make sterile is unrecoverable due to handling of java_temp
324## -----------------------------------------------------------------------
325protos-clean:
326 $(MAKE) sterile
327 $(MAKE) build
328 $(MAKE) protos
329 $(MAKE) test
330
331## -----------------------------------------------------------------------
Joey Armstrong56b36782023-05-30 17:30:11 -0400332## Intent: Display/debug targets
333## -----------------------------------------------------------------------
334.PHONY: show-proto-files
335show-proto-files:
Joey Armstrong1ff23e92023-07-13 16:24:32 -0400336
337 $(call banner-enter,Target $@)
338 @echo -e "PROTO_FILES:\n$(PROTO_FILES)" | tr ' ' '\n'
339 $(call banner-leave,Target $@)
Joey Armstrong56b36782023-05-30 17:30:11 -0400340
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500341# [EOF]