blob: b8dae50c6d6283d914b2a9601033ec03b5960ca1 [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
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050019.DEFAULT_GOAL := test
20
Joey Armstronge66eaaf2023-01-15 18:58:52 -050021##-------------------##
22##---] GLOBALS [---##
23##-------------------##
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050024TOP ?= .
25MAKEDIR ?= $(TOP)/makefiles
26
27$(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s)
28
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
Joey Armstrongc2277652023-01-11 17:41:36 -050036# Makefile for voltha-protos
37default: test
38
Joey Armstronge66eaaf2023-01-15 18:58:52 -050039## Library linting
40# NO-LINT-MAKEFILE := true # cleanup needed
41NO-LINT-SHELL := true # cleanup needed
42
Joey Armstronge6cdd8e2022-12-29 11:58:15 -050043##--------------------##
44##---] INCLUDES [---##
45##--------------------##
Joey Armstronge66eaaf2023-01-15 18:58:52 -050046include $(MAKEDIR)/include.mk
Zack Williams52209662019-02-07 10:15:31 -070047
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
Zack Williams25e0a322019-06-07 14:07:21 -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 Armstrong56b36782023-05-30 17:30:11 -0400104 $(RM) -r java_temp
Joey Armstrongc2277652023-01-11 17:41:36 -0500105
Joey Armstronge0c1a8d2023-04-13 15:16:21 -0400106## -----------------------------------------------------------------------
107## Python targets
108## -----------------------------------------------------------------------
109python-protos: $(infra-deps) $(PROTO_PYTHON_PB2)
Zack Williams52209662019-02-07 10:15:31 -0700110
Joey Armstrong761579c2023-05-08 11:59:57 -0400111## -----------------------------------------------------------------------
112## -----------------------------------------------------------------------
113$(PROTO_PYTHON_DEST_DIR)/%_pb2.py: \
114 protos/voltha_protos/%.proto \
115 Makefile \
116 $(venv-activate-script)
Joey Armstrong670d40c2023-05-11 20:49:26 -0400117
118 @echo
119 @echo "** -----------------------------------------------------------------------"
120 @echo "** $(MAKE): processing target [$@]"
121 @echo "** -----------------------------------------------------------------------"
122
123 $(activate) && python -m grpc_tools.protoc \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700124 -I protos \
125 --python_out=python \
126 --grpc_python_out=python \
127 --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \
128 --include_imports \
129 --include_source_info \
130 $<
Zack Williams52209662019-02-07 10:15:31 -0700131
Joey Armstrong670d40c2023-05-11 20:49:26 -0400132## -----------------------------------------------------------------------
133## Intent:
134## -----------------------------------------------------------------------
135show:
136 $(call banner-enter,target $@)
137 @echo
138 $(call banner-leave,target $@)
139
140## -----------------------------------------------------------------------
141## Intent:
142## -----------------------------------------------------------------------
143python-build: setup.py python-protos
144
145 $(call banner-enter,target $@)
146
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500147 $(RM) -r dist/
Zack Williams52209662019-02-07 10:15:31 -0700148 python ./setup.py sdist
149
Joey Armstrong670d40c2023-05-11 20:49:26 -0400150 $(call banner-leave,target $@)
151
152## -----------------------------------------------------------------------
153## Intent:
154## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700155python-test: tox.ini setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400156 $(call banner-enter,target $@)
157
158 $(activate) && python --version
Zack Williams52209662019-02-07 10:15:31 -0700159 tox
160
Joey Armstrong670d40c2023-05-11 20:49:26 -0400161 $(call banner-leave,target $@)
162
163## -----------------------------------------------------------------------
164## Intent:
165## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700166python-clean:
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500167 find python -name '__pycache__' -type d -print0 \
168 | xargs -0 --no-run-if-empty $(RM) -r
Joey Armstrongc2277652023-01-11 17:41:36 -0500169 find python -name '*.pyc' -type f -print0 \
170 | xargs -0 --no-run-if-empty $(RM)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500171 $(RM) -r \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700172 .coverage \
173 .tox \
174 coverage.xml \
175 dist \
176 nose2-results.xml \
177 python/__pycache__ \
178 python/test/__pycache__ \
179 python/voltha_protos.egg-info \
Joey Armstrong761579c2023-05-08 11:59:57 -0400180 "$(venv-abs-path)" \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700181 $(PROTO_PYTHON_DEST_DIR)/*.desc \
182 $(PROTO_PYTHON_PB2) \
183 $(PROTO_PYTHON_PB2_GRPC)
Zack Williams52209662019-02-07 10:15:31 -0700184
Joey Armstrong761579c2023-05-08 11:59:57 -0400185## -----------------------------------------------------------------------
186## Intent: Revert go to a clean state.
187## o TODO - go/ directory should not be placed under revision control.
188## o Build should retrieve versioned sources from a central repo.
189## -----------------------------------------------------------------------
khenaidoo5fc5cea2021-08-11 17:39:16 -0400190go-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500191 $(RM) -r go/*
Joey Armstrong761579c2023-05-08 11:59:57 -0400192 $(HIDE)$(MAKE) repair
193
194## -----------------------------------------------------------------------
195## Intent: Recover from a fatal failed build state:
196## o build removes go/ while regenerating prototypes.
197## o chicken-n-egg: make becomes fatal when go/ is removed and proten fails.
198## -----------------------------------------------------------------------
199repair:
200 /usr/bin/env git checkout go
201
Joey Armstrong670d40c2023-05-11 20:49:26 -0400202## -----------------------------------------------------------------------
203## Intent: Go targets
204## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500205go-protos: voltha.pb
Joey Armstrong670d40c2023-05-11 20:49:26 -0400206
207 @echo
208 @echo "** -----------------------------------------------------------------------"
209 @echo "** $(MAKE): processing target [$@]"
210 @echo "** Creating *.go.pb files"
211 @echo "** -----------------------------------------------------------------------"
212
Joey Armstrong56b36782023-05-30 17:30:11 -0400213 $(docker-sh) $(quote-double) /bin/ls -ld /go/src $(quote-double)
Joey Armstrong670d40c2023-05-11 20:49:26 -0400214
Joey Armstrong56b36782023-05-30 17:30:11 -0400215 ${PROTOC_SH} $(quote-double) \
216 find /go/src -print0 | xargs -0 /bin/ls -ld \
217 $(quote-double)
218
219 $(call banner-enter,target $@)
220
Joey Armstrong761579c2023-05-08 11:59:57 -0400221 ${PROTOC_SH} $(quote-double)\
Kent Hagerman868dc382020-01-20 11:24:09 -0500222 set -e -o pipefail; \
223 for x in ${PROTO_FILES}; do \
224 echo \$$x; \
225 protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400226 done\
227 $(quote-double)
228
229 $(call banner-leave,target $@)
Zack Williams43bfd9e2019-04-12 13:09:31 -0700230
Joey Armstrong670d40c2023-05-11 20:49:26 -0400231## -----------------------------------------------------------------------
232## Intent:
Joey Armstrong56b36782023-05-30 17:30:11 -0400233## ----------------------------------------------------------------------
234voltha.pb: show-proto-files
Joey Armstrong670d40c2023-05-11 20:49:26 -0400235 $(call banner-enter,target $@)
236
237 ${PROTOC} \
238 -I protos \
239 -I protos/google/api \
240 --include_imports \
241 --include_source_info \
Kent Hagerman868dc382020-01-20 11:24:09 -0500242 --descriptor_set_out=$@ \
243 ${PROTO_FILES}
Zack Williams43bfd9e2019-04-12 13:09:31 -0700244
Joey Armstrong670d40c2023-05-11 20:49:26 -0400245 $(call banner-leave,target $@)
246
247## -----------------------------------------------------------------------
248## Intent:
249## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500250go-test:
Joey Armstrong670d40c2023-05-11 20:49:26 -0400251 $(call banner-enter,target $@)
252
William Kurkianad745652019-03-20 08:45:51 -0400253 test/test-go-proto-consistency.sh
Kent Hagerman868dc382020-01-20 11:24:09 -0500254 ${GO} mod verify
Zack Williams52209662019-02-07 10:15:31 -0700255
Joey Armstrong670d40c2023-05-11 20:49:26 -0400256 $(call banner-leave,target $@)
257
258## -----------------------------------------------------------------------
259## Intent: Java targets
260## -----------------------------------------------------------------------
Joey Armstrong56b36782023-05-30 17:30:11 -0400261
262java-protos-dirs += java_temp/src/main/java
263java-protos-dirs += java_temp/src/main/java/org
264# local docker problem
265java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter
266java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter_service
267
268mkdir-args += -vp
Joey Armstronge0c1a8d2023-04-13 15:16:21 -0400269# mkdir-args += --mode=0777# # Only a problem for local docker builds
Joey Armstrong56b36782023-05-30 17:30:11 -0400270
Kent Hagerman868dc382020-01-20 11:24:09 -0500271java-protos: voltha.pb
Joey Armstrong56b36782023-05-30 17:30:11 -0400272
Joey Armstrong670d40c2023-05-11 20:49:26 -0400273 $(call banner-enter,target $@)
274
Joey Armstrong56b36782023-05-30 17:30:11 -0400275# $(RM) -fr java_temp
276 mkdir $(mkdir-args) $(java-protos-dirs)
277 $(docker-sh) $(quote-double) find $(java-protos-dirs) -print0 \
278 | xargs -0 -n1 /bin/ls -ld $(quote-double)
279
Joey Armstrong761579c2023-05-08 11:59:57 -0400280 @${PROTOC_SH} $(quote-double) \
Kent Hagerman868dc382020-01-20 11:24:09 -0500281 set -e -o pipefail; \
282 for x in ${PROTO_FILES}; do \
283 echo \$$x; \
284 protoc --java_out=java_temp/src/main/java -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400285 done\
286 $(quote-double)
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300287
Joey Armstrong670d40c2023-05-11 20:49:26 -0400288 # Move files into place after all prototypes have generated.
289 # TODO: Remove the extra step, use makefile deps and
290 # generate in-place as needed.
291 @mkdir -p java
292 cp -r java_temp/src/main/java/* java
293
294 $(call banner-leave,target $@)
295
296## -----------------------------------------------------------------------
297## Intent: Tests if the generated java classes are compilable
298## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300299java-test: java-protos
300 cp test/pom.xml java_temp
301 cd java_temp && mvn compile
302
Joey Armstrong670d40c2023-05-11 20:49:26 -0400303## -----------------------------------------------------------------------
304## Intent: Custodial service
305## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300306java-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500307 $(RM) -r java
308 $(RM) -r java_temp
309
Joey Armstrong56b36782023-05-30 17:30:11 -0400310## -----------------------------------------------------------------------
311## Intent: Placeholder for library targets
312## -----------------------------------------------------------------------
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500313lint :
314
Joey Armstrong56b36782023-05-30 17:30:11 -0400315## -----------------------------------------------------------------------
316## Intent: Display/debug targets
317## -----------------------------------------------------------------------
318.PHONY: show-proto-files
319show-proto-files:
320 echo -e "PROTO_FILES:\n$(PROTO_FILES)" | tr ' ' '\n'
321
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500322# [EOF]
Joey Armstrong56b36782023-05-30 17:30:11 -0400323