blob: fa6ca536eac3e2642376e96888b364843f3775a3 [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 Armstrong88270df2024-08-23 11:46:15 -040018$(if $(DEBUG),$(warning ENTER))
19
Joey Armstronge66eaaf2023-01-15 18:58:52 -050020.PHONY: test
Joey Armstrong88270df2024-08-23 11:46:15 -040021.DEFAULT_GOAL := test
22MAKECMDGOALS ?= test
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050023
Joey Armstronge66eaaf2023-01-15 18:58:52 -050024##-------------------##
25##---] GLOBALS [---##
26##-------------------##
Joey Armstrong88270df2024-08-23 11:46:15 -040027$(if $(findstring joey,$(USER)),\
28 $(eval USE_LF_MK := 1)) # special snowflake
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050029
Joey Armstrong88270df2024-08-23 11:46:15 -040030##--------------------##
31##---] INCLUDES [---##
32##--------------------##
33ifdef USE_LF_MK
34 include lf/include.mk
35else
36 include lf/transition.mk
37 include $(legacy-mk)/include.mk
38endif # ifdef USE_LF_MK
39
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050040
Joey Armstrong761579c2023-05-08 11:59:57 -040041##--------------------------
42## Enable setup.py debugging
43##--------------------------
44# https://docs.python.org/3/distutils/setupscript.html#debugging-the-setup-script
Joey Armstrong56b36782023-05-30 17:30:11 -040045# export DISTUTILS_DEBUG := 1 # verbose: pip
46export DOCKER_DEBUG := 1 # verbose: docker
Joey Armstrong761579c2023-05-08 11:59:57 -040047
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
Joey Armstrong66bb4c42024-07-31 12:35:45 -040076# -----------------------------------------------------------------------
77# Force pb file to be regenerated every time. Otherwise the make process
78# assumes generated version is still valid.
79# -----------------------------------------------------------------------
80# [TODO]
81# - Revisit: fix target to be dependency driven.
82# - When source not modified make "voltha.pb" behavior always a NOP
83# -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -050084.PHONY: voltha.pb
Matt Jeanneret15249fa2019-04-12 20:25:31 -040085
Joey Armstronge0c1a8d2023-04-13 15:16:21 -040086##----------------##
87##---] DEPS [---##
88##----------------##
89infra-deps := $(null)
90infra-deps += Makefile
91infra-deps += $(venv-activate-script)
92
93## -----------------------------------------------------------------------
94## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -070095print:
Zack Williams43bfd9e2019-04-12 13:09:31 -070096 @echo "Proto files: $(PROTO_FILES)"
97 @echo "Python PB2 files: $(PROTO_PYTHON_PB2)"
98 @echo "Go PB files: $(PROTO_GO_PB)"
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030099 @echo "JAVA PB files: $(PROTO_JAVA_PB)"
Zack Williams52209662019-02-07 10:15:31 -0700100
101# Generic targets
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300102protos: python-protos go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -0700103
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300104build: protos python-build go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -0700105
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300106test: python-test go-test java-test
Zack Williams52209662019-02-07 10:15:31 -0700107
Joey Armstrong761579c2023-05-08 11:59:57 -0400108clean :: python-clean java-clean go-clean
Zack Williams52209662019-02-07 10:15:31 -0700109
Joey Armstrong761579c2023-05-08 11:59:57 -0400110sterile :: clean
Joey Armstrongc2277652023-01-11 17:41:36 -0500111
Joey Armstronge0c1a8d2023-04-13 15:16:21 -0400112## -----------------------------------------------------------------------
113## Python targets
114## -----------------------------------------------------------------------
115python-protos: $(infra-deps) $(PROTO_PYTHON_PB2)
Zack Williams52209662019-02-07 10:15:31 -0700116
Joey Armstrong761579c2023-05-08 11:59:57 -0400117## -----------------------------------------------------------------------
118## -----------------------------------------------------------------------
119$(PROTO_PYTHON_DEST_DIR)/%_pb2.py: \
120 protos/voltha_protos/%.proto \
121 Makefile \
122 $(venv-activate-script)
Joey Armstrong670d40c2023-05-11 20:49:26 -0400123
124 @echo
125 @echo "** -----------------------------------------------------------------------"
126 @echo "** $(MAKE): processing target [$@]"
127 @echo "** -----------------------------------------------------------------------"
128
129 $(activate) && python -m grpc_tools.protoc \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700130 -I protos \
131 --python_out=python \
132 --grpc_python_out=python \
133 --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \
134 --include_imports \
135 --include_source_info \
136 $<
Zack Williams52209662019-02-07 10:15:31 -0700137
Joey Armstrong670d40c2023-05-11 20:49:26 -0400138## -----------------------------------------------------------------------
139## Intent:
140## -----------------------------------------------------------------------
141show:
142 $(call banner-enter,target $@)
143 @echo
144 $(call banner-leave,target $@)
145
146## -----------------------------------------------------------------------
147## Intent:
148## -----------------------------------------------------------------------
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400149python-build: setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400150
151 $(call banner-enter,target $@)
152
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500153 $(RM) -r dist/
Zack Williams52209662019-02-07 10:15:31 -0700154 python ./setup.py sdist
155
Joey Armstrong670d40c2023-05-11 20:49:26 -0400156 $(call banner-leave,target $@)
157
158## -----------------------------------------------------------------------
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400159## Intent: Invoke tox to install a python interpreter then run tests.
160## -----------------------------------------------------------------------
161## See Also:
162## o https://tox.wiki/en/latest/cli_interface.html#tox-verbosity
163## every -v increases, every -q decreases verbosity level,
164## default WARNING (level:2)
165## map 0=CRITICAL|1=ERROR|2=WARNING|3=INFO|4=DEBUG|5=NOTSET
Joey Armstrong670d40c2023-05-11 20:49:26 -0400166## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700167python-test: tox.ini setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400168 $(call banner-enter,target $@)
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400169
Joey Armstrong670d40c2023-05-11 20:49:26 -0400170 $(activate) && python --version
Joey Armstrong6a6c6292024-04-30 16:07:38 -0400171 tox -vvv
172
Joey Armstrong670d40c2023-05-11 20:49:26 -0400173 $(call banner-leave,target $@)
174
175## -----------------------------------------------------------------------
176## Intent:
177## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700178python-clean:
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500179 find python -name '__pycache__' -type d -print0 \
180 | xargs -0 --no-run-if-empty $(RM) -r
Joey Armstrongc2277652023-01-11 17:41:36 -0500181 find python -name '*.pyc' -type f -print0 \
182 | xargs -0 --no-run-if-empty $(RM)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500183 $(RM) -r \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700184 .coverage \
185 .tox \
186 coverage.xml \
187 dist \
188 nose2-results.xml \
189 python/__pycache__ \
190 python/test/__pycache__ \
191 python/voltha_protos.egg-info \
Joey Armstrong761579c2023-05-08 11:59:57 -0400192 "$(venv-abs-path)" \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700193 $(PROTO_PYTHON_DEST_DIR)/*.desc \
194 $(PROTO_PYTHON_PB2) \
195 $(PROTO_PYTHON_PB2_GRPC)
Zack Williams52209662019-02-07 10:15:31 -0700196
Joey Armstrong761579c2023-05-08 11:59:57 -0400197## -----------------------------------------------------------------------
198## Intent: Revert go to a clean state.
199## o TODO - go/ directory should not be placed under revision control.
200## o Build should retrieve versioned sources from a central repo.
201## -----------------------------------------------------------------------
khenaidoo5fc5cea2021-08-11 17:39:16 -0400202go-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500203 $(RM) -r go/*
Joey Armstrong761579c2023-05-08 11:59:57 -0400204 $(HIDE)$(MAKE) repair
205
206## -----------------------------------------------------------------------
207## Intent: Recover from a fatal failed build state:
208## o build removes go/ while regenerating prototypes.
209## o chicken-n-egg: make becomes fatal when go/ is removed and proten fails.
210## -----------------------------------------------------------------------
211repair:
212 /usr/bin/env git checkout go
213
Joey Armstrong670d40c2023-05-11 20:49:26 -0400214## -----------------------------------------------------------------------
215## Intent: Go targets
216## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500217go-protos: voltha.pb
Joey Armstrong670d40c2023-05-11 20:49:26 -0400218
Joey Armstrong56b36782023-05-30 17:30:11 -0400219 $(call banner-enter,target $@)
Joey Armstrong50080092023-07-06 15:18:37 -0400220 @echo "** Creating *.go.pb files"
Joey Armstrong1ff23e92023-07-13 16:24:32 -0400221
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500222 $(if $(LOCAL_FIX_PERMS),chmod -R o+w $(PROTO_GO_DEST_DIR))
223
Joey Armstrong761579c2023-05-08 11:59:57 -0400224 ${PROTOC_SH} $(quote-double)\
Kent Hagerman868dc382020-01-20 11:24:09 -0500225 set -e -o pipefail; \
226 for x in ${PROTO_FILES}; do \
227 echo \$$x; \
228 protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400229 done\
230 $(quote-double)
231
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500232 $(if $(LOCAL_FIX_PERMS),chmod -R o-w $(PROTO_GO_DEST_DIR))
233
Joey Armstrong56b36782023-05-30 17:30:11 -0400234 $(call banner-leave,target $@)
Zack Williams43bfd9e2019-04-12 13:09:31 -0700235
Joey Armstrong670d40c2023-05-11 20:49:26 -0400236## -----------------------------------------------------------------------
Joey Armstrong66bb4c42024-07-31 12:35:45 -0400237## Intent: Regenerate voltha.pb
Joey Armstrong56b36782023-05-30 17:30:11 -0400238## ----------------------------------------------------------------------
Joey Armstrong66bb4c42024-07-31 12:35:45 -0400239voltha-pb += show-proto-files
240voltha-pb += docker-debug-joey
241
242voltha.pb: $(voltha-pb)
Joey Armstrong670d40c2023-05-11 20:49:26 -0400243 $(call banner-enter,target $@)
244
245 ${PROTOC} \
246 -I protos \
247 -I protos/google/api \
248 --include_imports \
249 --include_source_info \
Kent Hagerman868dc382020-01-20 11:24:09 -0500250 --descriptor_set_out=$@ \
251 ${PROTO_FILES}
Zack Williams43bfd9e2019-04-12 13:09:31 -0700252
Joey Armstrong670d40c2023-05-11 20:49:26 -0400253 $(call banner-leave,target $@)
254
255## -----------------------------------------------------------------------
256## Intent:
257## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500258go-test:
Joey Armstrong670d40c2023-05-11 20:49:26 -0400259 $(call banner-enter,target $@)
260
William Kurkianad745652019-03-20 08:45:51 -0400261 test/test-go-proto-consistency.sh
Kent Hagerman868dc382020-01-20 11:24:09 -0500262 ${GO} mod verify
Zack Williams52209662019-02-07 10:15:31 -0700263
Joey Armstrong670d40c2023-05-11 20:49:26 -0400264 $(call banner-leave,target $@)
265
266## -----------------------------------------------------------------------
267## Intent: Java targets
268## -----------------------------------------------------------------------
Joey Armstrong56b36782023-05-30 17:30:11 -0400269
270java-protos-dirs += java_temp/src/main/java
271java-protos-dirs += java_temp/src/main/java/org
272# local docker problem
273java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter
274java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter_service
275
276mkdir-args += -vp
Joey Armstrong56b36782023-05-30 17:30:11 -0400277
Kent Hagerman868dc382020-01-20 11:24:09 -0500278java-protos: voltha.pb
Joey Armstrong56b36782023-05-30 17:30:11 -0400279
Joey Armstrong670d40c2023-05-11 20:49:26 -0400280 $(call banner-enter,target $@)
281
Joey Armstrong56b36782023-05-30 17:30:11 -0400282 mkdir $(mkdir-args) $(java-protos-dirs)
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500283
Joey Armstrong56b36782023-05-30 17:30:11 -0400284 $(docker-sh) $(quote-double) find $(java-protos-dirs) -print0 \
285 | xargs -0 -n1 /bin/ls -ld $(quote-double)
286
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500287 $(if $(LOCAL_FIX_PERMS),chmod -R o+w java_temp)
Joey Armstrong761579c2023-05-08 11:59:57 -0400288 @${PROTOC_SH} $(quote-double) \
Kent Hagerman868dc382020-01-20 11:24:09 -0500289 set -e -o pipefail; \
290 for x in ${PROTO_FILES}; do \
291 echo \$$x; \
292 protoc --java_out=java_temp/src/main/java -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400293 done\
294 $(quote-double)
Joey Armstrongcb986bf2023-12-12 17:22:05 -0500295 $(if $(LOCAL_FIX_PERMS),chmod -R o-w java_temp)
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300296
Joey Armstrong670d40c2023-05-11 20:49:26 -0400297 # Move files into place after all prototypes have generated.
298 # TODO: Remove the extra step, use makefile deps and
299 # generate in-place as needed.
300 @mkdir -p java
Joey Armstrong50080092023-07-06 15:18:37 -0400301 rsync -r --checksum java_temp/src/main/java/. java/.
Joey Armstrong670d40c2023-05-11 20:49:26 -0400302
303 $(call banner-leave,target $@)
304
305## -----------------------------------------------------------------------
306## Intent: Tests if the generated java classes are compilable
307## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300308java-test: java-protos
309 cp test/pom.xml java_temp
310 cd java_temp && mvn compile
311
Joey Armstrong670d40c2023-05-11 20:49:26 -0400312## -----------------------------------------------------------------------
313## Intent: Custodial service
314## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300315java-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500316 $(RM) -r java
317 $(RM) -r java_temp
318
Joey Armstrong56b36782023-05-30 17:30:11 -0400319## -----------------------------------------------------------------------
320## Intent: Placeholder for library targets
321## -----------------------------------------------------------------------
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500322lint :
323
Joey Armstrong56b36782023-05-30 17:30:11 -0400324## -----------------------------------------------------------------------
Joey Armstrong50080092023-07-06 15:18:37 -0400325## Intent: Make sterile is unrecoverable due to handling of java_temp
326## -----------------------------------------------------------------------
327protos-clean:
328 $(MAKE) sterile
329 $(MAKE) build
330 $(MAKE) protos
331 $(MAKE) test
332
333## -----------------------------------------------------------------------
Joey Armstrong56b36782023-05-30 17:30:11 -0400334## Intent: Display/debug targets
335## -----------------------------------------------------------------------
336.PHONY: show-proto-files
337show-proto-files:
Joey Armstrong1ff23e92023-07-13 16:24:32 -0400338
339 $(call banner-enter,Target $@)
340 @echo -e "PROTO_FILES:\n$(PROTO_FILES)" | tr ' ' '\n'
341 $(call banner-leave,Target $@)
Joey Armstrong56b36782023-05-30 17:30:11 -0400342
Joey Armstrong66bb4c42024-07-31 12:35:45 -0400343## -----------------------------------------------------------------------
344## Intent: Debug mode
345## - New image not logging ssh connections while job is running (?!?)
346## - We should be on label=voltha-1804-micro.
347## - Let(s) see what the reality is while checking configs.
348## -----------------------------------------------------------------------
349.PHONY: docker-debug-joey
350docker-debug-joey:
351
352 $(call banner-enter,Target $@)
353 ip --brief addr
354 $(call banner-leave,Target $@)
355
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500356# [EOF]