blob: 5cbd2b993fedc5939757cced8475c6507711ced5 [file] [log] [blame]
Joey Armstronge6cdd8e2022-12-29 11:58:15 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstronge66eaaf2023-01-15 18:58:52 -05003# Copyright 2019-2023 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 Armstronge66eaaf2023-01-15 18:58:52 -050018.PHONY: test
Eric Ballf1055a92024-09-05 11:01:28 -070019.DEFAULT_GOAL := test
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050020
Joey Armstronge66eaaf2023-01-15 18:58:52 -050021##-------------------##
22##---] GLOBALS [---##
23##-------------------##
Eric Ballf1055a92024-09-05 11:01:28 -070024TOP ?= .
25MAKEDIR ?= $(TOP)/makefiles
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050026
Eric Ballf1055a92024-09-05 11:01:28 -070027$(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050028
Joey Armstrong761579c2023-05-08 11:59:57 -040029##--------------------------
30## Enable setup.py debugging
31##--------------------------
32# https://docs.python.org/3/distutils/setupscript.html#debugging-the-setup-script
Joey Armstrong56b36782023-05-30 17:30:11 -040033# export DISTUTILS_DEBUG := 1 # verbose: pip
34export DOCKER_DEBUG := 1 # verbose: docker
Joey Armstrong761579c2023-05-08 11:59:57 -040035
Eric Ballf1055a92024-09-05 11:01:28 -070036# Makefile for voltha-protos
37default: test
38
39## Library linting
40# NO-LINT-MAKEFILE := true # cleanup needed
41NO-LINT-SHELL := true # cleanup needed
42
43##--------------------##
44##---] INCLUDES [---##
45##--------------------##
46include $(MAKEDIR)/include.mk
47
Zack Williams43bfd9e2019-04-12 13:09:31 -070048# Function to extract the last path component from go_package line in .proto files
49define go_package_path
50$(shell grep go_package $(1) | sed -n 's/.*\/\(.*\)";/\1/p')
51endef
52
Joey Armstronge05f6492023-05-31 11:27:31 -040053# -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030054# Function to extract the last path component from package line in .proto files
Joey Armstronge05f6492023-05-31 11:27:31 -040055# % grep 'package' will match:
56# o package <name> ;
57# o option java_package='<dot-pkg-fqdn>
58# -----------------------------------------------------------------------
59# RETURN: protos/voltha_protos/common.proto => common
60# -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030061define java_package_path
62$(shell grep package $(1) | sed -n 's/.*\/\(.*\)";/\1/p')
63endef
64
Zack Williams52209662019-02-07 10:15:31 -070065# Variables
Zack Williams43bfd9e2019-04-12 13:09:31 -070066PROTO_FILES := $(sort $(wildcard protos/voltha_protos/*.proto))
67
Zack Williams52209662019-02-07 10:15:31 -070068PROTO_PYTHON_DEST_DIR := python/voltha_protos
69PROTO_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 -050070PROTO_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 -070071PROTO_GO_DEST_DIR := go
72PROTO_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 +030073PROTO_JAVA_DEST_DIR := java
Joey Armstrong670d40c2023-05-11 20:49:26 -040074PROTO_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 -040075
Eric Ballf1055a92024-09-05 11:01:28 -070076# 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 -050077.PHONY: voltha.pb
Matt Jeanneret15249fa2019-04-12 20:25:31 -040078
Joey Armstronge0c1a8d2023-04-13 15:16:21 -040079##----------------##
80##---] DEPS [---##
81##----------------##
82infra-deps := $(null)
83infra-deps += Makefile
84infra-deps += $(venv-activate-script)
85
86## -----------------------------------------------------------------------
87## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -070088print:
Zack Williams43bfd9e2019-04-12 13:09:31 -070089 @echo "Proto files: $(PROTO_FILES)"
90 @echo "Python PB2 files: $(PROTO_PYTHON_PB2)"
91 @echo "Go PB files: $(PROTO_GO_PB)"
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030092 @echo "JAVA PB files: $(PROTO_JAVA_PB)"
Zack Williams52209662019-02-07 10:15:31 -070093
94# Generic targets
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030095protos: python-protos go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -070096
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030097build: protos python-build go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -070098
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030099test: python-test go-test java-test
Zack Williams52209662019-02-07 10:15:31 -0700100
Joey Armstrong761579c2023-05-08 11:59:57 -0400101clean :: python-clean java-clean go-clean
Zack Williams52209662019-02-07 10:15:31 -0700102
Joey Armstrong761579c2023-05-08 11:59:57 -0400103sterile :: clean
Joey Armstrongc2277652023-01-11 17:41:36 -0500104
Joey Armstronge0c1a8d2023-04-13 15:16:21 -0400105## -----------------------------------------------------------------------
106## Python targets
107## -----------------------------------------------------------------------
108python-protos: $(infra-deps) $(PROTO_PYTHON_PB2)
Zack Williams52209662019-02-07 10:15:31 -0700109
Joey Armstrong761579c2023-05-08 11:59:57 -0400110## -----------------------------------------------------------------------
111## -----------------------------------------------------------------------
112$(PROTO_PYTHON_DEST_DIR)/%_pb2.py: \
113 protos/voltha_protos/%.proto \
114 Makefile \
115 $(venv-activate-script)
Joey Armstrong670d40c2023-05-11 20:49:26 -0400116
117 @echo
118 @echo "** -----------------------------------------------------------------------"
119 @echo "** $(MAKE): processing target [$@]"
120 @echo "** -----------------------------------------------------------------------"
121
122 $(activate) && python -m grpc_tools.protoc \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700123 -I protos \
124 --python_out=python \
125 --grpc_python_out=python \
126 --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \
127 --include_imports \
128 --include_source_info \
129 $<
Zack Williams52209662019-02-07 10:15:31 -0700130
Joey Armstrong670d40c2023-05-11 20:49:26 -0400131## -----------------------------------------------------------------------
132## Intent:
133## -----------------------------------------------------------------------
134show:
135 $(call banner-enter,target $@)
136 @echo
137 $(call banner-leave,target $@)
138
139## -----------------------------------------------------------------------
140## Intent:
141## -----------------------------------------------------------------------
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400142python-build: setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400143
144 $(call banner-enter,target $@)
145
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500146 $(RM) -r dist/
Zack Williams52209662019-02-07 10:15:31 -0700147 python ./setup.py sdist
148
Joey Armstrong670d40c2023-05-11 20:49:26 -0400149 $(call banner-leave,target $@)
150
151## -----------------------------------------------------------------------
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400152## Intent: Invoke tox to install a python interpreter then run tests.
153## -----------------------------------------------------------------------
154## See Also:
155## o https://tox.wiki/en/latest/cli_interface.html#tox-verbosity
156## every -v increases, every -q decreases verbosity level,
157## default WARNING (level:2)
158## map 0=CRITICAL|1=ERROR|2=WARNING|3=INFO|4=DEBUG|5=NOTSET
Joey Armstrong670d40c2023-05-11 20:49:26 -0400159## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700160python-test: tox.ini setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400161 $(call banner-enter,target $@)
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400162
Joey Armstrong670d40c2023-05-11 20:49:26 -0400163 $(activate) && python --version
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400164 tox -vvv
165
Joey Armstrong670d40c2023-05-11 20:49:26 -0400166 $(call banner-leave,target $@)
167
168## -----------------------------------------------------------------------
169## Intent:
170## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700171python-clean:
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500172 find python -name '__pycache__' -type d -print0 \
173 | xargs -0 --no-run-if-empty $(RM) -r
Joey Armstrongc2277652023-01-11 17:41:36 -0500174 find python -name '*.pyc' -type f -print0 \
175 | xargs -0 --no-run-if-empty $(RM)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500176 $(RM) -r \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700177 .coverage \
178 .tox \
179 coverage.xml \
180 dist \
181 nose2-results.xml \
182 python/__pycache__ \
183 python/test/__pycache__ \
184 python/voltha_protos.egg-info \
Joey Armstrong761579c2023-05-08 11:59:57 -0400185 "$(venv-abs-path)" \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700186 $(PROTO_PYTHON_DEST_DIR)/*.desc \
187 $(PROTO_PYTHON_PB2) \
188 $(PROTO_PYTHON_PB2_GRPC)
Zack Williams52209662019-02-07 10:15:31 -0700189
Joey Armstrong761579c2023-05-08 11:59:57 -0400190## -----------------------------------------------------------------------
191## Intent: Revert go to a clean state.
192## o TODO - go/ directory should not be placed under revision control.
193## o Build should retrieve versioned sources from a central repo.
194## -----------------------------------------------------------------------
khenaidoo5fc5cea2021-08-11 17:39:16 -0400195go-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500196 $(RM) -r go/*
Joey Armstrong761579c2023-05-08 11:59:57 -0400197 $(HIDE)$(MAKE) repair
198
199## -----------------------------------------------------------------------
200## Intent: Recover from a fatal failed build state:
201## o build removes go/ while regenerating prototypes.
202## o chicken-n-egg: make becomes fatal when go/ is removed and proten fails.
203## -----------------------------------------------------------------------
204repair:
205 /usr/bin/env git checkout go
206
Joey Armstrong670d40c2023-05-11 20:49:26 -0400207## -----------------------------------------------------------------------
208## Intent: Go targets
209## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500210go-protos: voltha.pb
Joey Armstrong670d40c2023-05-11 20:49:26 -0400211
Joey Armstrong56b36782023-05-30 17:30:11 -0400212 $(call banner-enter,target $@)
Joey Armstrong50080092023-07-06 15:18:37 -0400213 @echo "** Creating *.go.pb files"
Joey Armstrong1ff23e92023-07-13 16:24:32 -0400214
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500215 $(if $(LOCAL_FIX_PERMS),chmod -R o+w $(PROTO_GO_DEST_DIR))
216
Joey Armstrong761579c2023-05-08 11:59:57 -0400217 ${PROTOC_SH} $(quote-double)\
Kent Hagerman868dc382020-01-20 11:24:09 -0500218 set -e -o pipefail; \
219 for x in ${PROTO_FILES}; do \
220 echo \$$x; \
221 protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400222 done\
223 $(quote-double)
224
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500225 $(if $(LOCAL_FIX_PERMS),chmod -R o-w $(PROTO_GO_DEST_DIR))
226
Joey Armstrong56b36782023-05-30 17:30:11 -0400227 $(call banner-leave,target $@)
Zack Williams43bfd9e2019-04-12 13:09:31 -0700228
Joey Armstrong670d40c2023-05-11 20:49:26 -0400229## -----------------------------------------------------------------------
Eric Ballf1055a92024-09-05 11:01:28 -0700230## Intent:
Joey Armstrong56b36782023-05-30 17:30:11 -0400231## ----------------------------------------------------------------------
Eric Ballf1055a92024-09-05 11:01:28 -0700232voltha.pb: show-proto-files
Joey Armstrong670d40c2023-05-11 20:49:26 -0400233 $(call banner-enter,target $@)
234
235 ${PROTOC} \
236 -I protos \
237 -I protos/google/api \
238 --include_imports \
239 --include_source_info \
Kent Hagerman868dc382020-01-20 11:24:09 -0500240 --descriptor_set_out=$@ \
241 ${PROTO_FILES}
Zack Williams43bfd9e2019-04-12 13:09:31 -0700242
Joey Armstrong670d40c2023-05-11 20:49:26 -0400243 $(call banner-leave,target $@)
244
245## -----------------------------------------------------------------------
246## Intent:
247## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500248go-test:
Joey Armstrong670d40c2023-05-11 20:49:26 -0400249 $(call banner-enter,target $@)
250
William Kurkianad745652019-03-20 08:45:51 -0400251 test/test-go-proto-consistency.sh
Kent Hagerman868dc382020-01-20 11:24:09 -0500252 ${GO} mod verify
Zack Williams52209662019-02-07 10:15:31 -0700253
Joey Armstrong670d40c2023-05-11 20:49:26 -0400254 $(call banner-leave,target $@)
255
256## -----------------------------------------------------------------------
257## Intent: Java targets
258## -----------------------------------------------------------------------
Joey Armstrong56b36782023-05-30 17:30:11 -0400259
260java-protos-dirs += java_temp/src/main/java
261java-protos-dirs += java_temp/src/main/java/org
262# local docker problem
263java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter
264java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter_service
265
266mkdir-args += -vp
Joey Armstrong56b36782023-05-30 17:30:11 -0400267
Kent Hagerman868dc382020-01-20 11:24:09 -0500268java-protos: voltha.pb
Joey Armstrong56b36782023-05-30 17:30:11 -0400269
Joey Armstrong670d40c2023-05-11 20:49:26 -0400270 $(call banner-enter,target $@)
271
Joey Armstrong56b36782023-05-30 17:30:11 -0400272 mkdir $(mkdir-args) $(java-protos-dirs)
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500273
Joey Armstrong56b36782023-05-30 17:30:11 -0400274 $(docker-sh) $(quote-double) find $(java-protos-dirs) -print0 \
275 | xargs -0 -n1 /bin/ls -ld $(quote-double)
276
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500277 $(if $(LOCAL_FIX_PERMS),chmod -R o+w java_temp)
Joey Armstrong761579c2023-05-08 11:59:57 -0400278 @${PROTOC_SH} $(quote-double) \
Kent Hagerman868dc382020-01-20 11:24:09 -0500279 set -e -o pipefail; \
280 for x in ${PROTO_FILES}; do \
281 echo \$$x; \
282 protoc --java_out=java_temp/src/main/java -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400283 done\
284 $(quote-double)
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500285 $(if $(LOCAL_FIX_PERMS),chmod -R o-w java_temp)
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300286
Joey Armstrong670d40c2023-05-11 20:49:26 -0400287 # Move files into place after all prototypes have generated.
288 # TODO: Remove the extra step, use makefile deps and
289 # generate in-place as needed.
290 @mkdir -p java
Joey Armstrong50080092023-07-06 15:18:37 -0400291 rsync -r --checksum java_temp/src/main/java/. java/.
Joey Armstrong670d40c2023-05-11 20:49:26 -0400292
293 $(call banner-leave,target $@)
294
295## -----------------------------------------------------------------------
296## Intent: Tests if the generated java classes are compilable
297## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300298java-test: java-protos
299 cp test/pom.xml java_temp
300 cd java_temp && mvn compile
301
Joey Armstrong670d40c2023-05-11 20:49:26 -0400302## -----------------------------------------------------------------------
303## Intent: Custodial service
304## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300305java-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500306 $(RM) -r java
307 $(RM) -r java_temp
308
Joey Armstrong56b36782023-05-30 17:30:11 -0400309## -----------------------------------------------------------------------
310## Intent: Placeholder for library targets
311## -----------------------------------------------------------------------
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500312lint :
313
Joey Armstrong56b36782023-05-30 17:30:11 -0400314## -----------------------------------------------------------------------
Joey Armstrong50080092023-07-06 15:18:37 -0400315## Intent: Make sterile is unrecoverable due to handling of java_temp
316## -----------------------------------------------------------------------
317protos-clean:
318 $(MAKE) sterile
319 $(MAKE) build
320 $(MAKE) protos
321 $(MAKE) test
322
323## -----------------------------------------------------------------------
Joey Armstrong56b36782023-05-30 17:30:11 -0400324## Intent: Display/debug targets
325## -----------------------------------------------------------------------
326.PHONY: show-proto-files
327show-proto-files:
Joey Armstrong1ff23e92023-07-13 16:24:32 -0400328
329 $(call banner-enter,Target $@)
330 @echo -e "PROTO_FILES:\n$(PROTO_FILES)" | tr ' ' '\n'
331 $(call banner-leave,Target $@)
Joey Armstrong56b36782023-05-30 17:30:11 -0400332
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500333# [EOF]