blob: 688a925518c3f8942845c0f4da51a005a2b44c93 [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
Zack Williams52209662019-02-07 10:15:31 -070079print:
Zack Williams43bfd9e2019-04-12 13:09:31 -070080 @echo "Proto files: $(PROTO_FILES)"
81 @echo "Python PB2 files: $(PROTO_PYTHON_PB2)"
82 @echo "Go PB files: $(PROTO_GO_PB)"
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030083 @echo "JAVA PB files: $(PROTO_JAVA_PB)"
Zack Williams52209662019-02-07 10:15:31 -070084
85# Generic targets
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030086protos: python-protos go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -070087
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030088build: protos python-build go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -070089
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030090test: python-test go-test java-test
Zack Williams52209662019-02-07 10:15:31 -070091
Joey Armstrong761579c2023-05-08 11:59:57 -040092clean :: python-clean java-clean go-clean
Zack Williams52209662019-02-07 10:15:31 -070093
Joey Armstrong761579c2023-05-08 11:59:57 -040094sterile :: clean
Joey Armstrong56b36782023-05-30 17:30:11 -040095 $(RM) -r java_temp
Joey Armstrongc2277652023-01-11 17:41:36 -050096
Zack Williams52209662019-02-07 10:15:31 -070097# Python targets
Kent Hagerman868dc382020-01-20 11:24:09 -050098python-protos: $(PROTO_PYTHON_PB2)
Zack Williams52209662019-02-07 10:15:31 -070099
Joey Armstrong761579c2023-05-08 11:59:57 -0400100## -----------------------------------------------------------------------
101## -----------------------------------------------------------------------
102$(PROTO_PYTHON_DEST_DIR)/%_pb2.py: \
103 protos/voltha_protos/%.proto \
104 Makefile \
105 $(venv-activate-script)
Joey Armstrong670d40c2023-05-11 20:49:26 -0400106
107 @echo
108 @echo "** -----------------------------------------------------------------------"
109 @echo "** $(MAKE): processing target [$@]"
110 @echo "** -----------------------------------------------------------------------"
111
112 $(activate) && python -m grpc_tools.protoc \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700113 -I protos \
114 --python_out=python \
115 --grpc_python_out=python \
116 --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \
117 --include_imports \
118 --include_source_info \
119 $<
Zack Williams52209662019-02-07 10:15:31 -0700120
Joey Armstrong670d40c2023-05-11 20:49:26 -0400121## -----------------------------------------------------------------------
122## Intent:
123## -----------------------------------------------------------------------
124show:
125 $(call banner-enter,target $@)
126 @echo
127 $(call banner-leave,target $@)
128
129## -----------------------------------------------------------------------
130## Intent:
131## -----------------------------------------------------------------------
132python-build: setup.py python-protos
133
134 $(call banner-enter,target $@)
135
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500136 $(RM) -r dist/
Zack Williams52209662019-02-07 10:15:31 -0700137 python ./setup.py sdist
138
Joey Armstrong670d40c2023-05-11 20:49:26 -0400139 $(call banner-leave,target $@)
140
141## -----------------------------------------------------------------------
142## Intent:
143## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700144python-test: tox.ini setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400145 $(call banner-enter,target $@)
146
147 $(activate) && python --version
Zack Williams52209662019-02-07 10:15:31 -0700148 tox
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-clean:
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500156 find python -name '__pycache__' -type d -print0 \
157 | xargs -0 --no-run-if-empty $(RM) -r
Joey Armstrongc2277652023-01-11 17:41:36 -0500158 find python -name '*.pyc' -type f -print0 \
159 | xargs -0 --no-run-if-empty $(RM)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500160 $(RM) -r \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700161 .coverage \
162 .tox \
163 coverage.xml \
164 dist \
165 nose2-results.xml \
166 python/__pycache__ \
167 python/test/__pycache__ \
168 python/voltha_protos.egg-info \
Joey Armstrong761579c2023-05-08 11:59:57 -0400169 "$(venv-abs-path)" \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700170 $(PROTO_PYTHON_DEST_DIR)/*.desc \
171 $(PROTO_PYTHON_PB2) \
172 $(PROTO_PYTHON_PB2_GRPC)
Zack Williams52209662019-02-07 10:15:31 -0700173
Joey Armstrong761579c2023-05-08 11:59:57 -0400174## -----------------------------------------------------------------------
175## Intent: Revert go to a clean state.
176## o TODO - go/ directory should not be placed under revision control.
177## o Build should retrieve versioned sources from a central repo.
178## -----------------------------------------------------------------------
khenaidoo5fc5cea2021-08-11 17:39:16 -0400179go-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500180 $(RM) -r go/*
Joey Armstrong761579c2023-05-08 11:59:57 -0400181 $(HIDE)$(MAKE) repair
182
183## -----------------------------------------------------------------------
184## Intent: Recover from a fatal failed build state:
185## o build removes go/ while regenerating prototypes.
186## o chicken-n-egg: make becomes fatal when go/ is removed and proten fails.
187## -----------------------------------------------------------------------
188repair:
189 /usr/bin/env git checkout go
190
Joey Armstrong670d40c2023-05-11 20:49:26 -0400191## -----------------------------------------------------------------------
192## Intent: Go targets
193## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500194go-protos: voltha.pb
Joey Armstrong670d40c2023-05-11 20:49:26 -0400195
196 @echo
197 @echo "** -----------------------------------------------------------------------"
198 @echo "** $(MAKE): processing target [$@]"
199 @echo "** Creating *.go.pb files"
200 @echo "** -----------------------------------------------------------------------"
201
Joey Armstrong56b36782023-05-30 17:30:11 -0400202 $(docker-sh) $(quote-double) /bin/ls -ld /go/src $(quote-double)
Joey Armstrong670d40c2023-05-11 20:49:26 -0400203
Joey Armstrong56b36782023-05-30 17:30:11 -0400204 ${PROTOC_SH} $(quote-double) \
205 find /go/src -print0 | xargs -0 /bin/ls -ld \
206 $(quote-double)
207
208 $(call banner-enter,target $@)
209
Joey Armstrong761579c2023-05-08 11:59:57 -0400210 ${PROTOC_SH} $(quote-double)\
Kent Hagerman868dc382020-01-20 11:24:09 -0500211 set -e -o pipefail; \
212 for x in ${PROTO_FILES}; do \
213 echo \$$x; \
214 protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400215 done\
216 $(quote-double)
217
218 $(call banner-leave,target $@)
Zack Williams43bfd9e2019-04-12 13:09:31 -0700219
Joey Armstrong670d40c2023-05-11 20:49:26 -0400220## -----------------------------------------------------------------------
221## Intent:
Joey Armstrong56b36782023-05-30 17:30:11 -0400222## ----------------------------------------------------------------------
223voltha.pb: show-proto-files
Joey Armstrong670d40c2023-05-11 20:49:26 -0400224 $(call banner-enter,target $@)
225
226 ${PROTOC} \
227 -I protos \
228 -I protos/google/api \
229 --include_imports \
230 --include_source_info \
Kent Hagerman868dc382020-01-20 11:24:09 -0500231 --descriptor_set_out=$@ \
232 ${PROTO_FILES}
Zack Williams43bfd9e2019-04-12 13:09:31 -0700233
Joey Armstrong670d40c2023-05-11 20:49:26 -0400234 $(call banner-leave,target $@)
235
236## -----------------------------------------------------------------------
237## Intent:
238## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500239go-test:
Joey Armstrong670d40c2023-05-11 20:49:26 -0400240 $(call banner-enter,target $@)
241
William Kurkianad745652019-03-20 08:45:51 -0400242 test/test-go-proto-consistency.sh
Kent Hagerman868dc382020-01-20 11:24:09 -0500243 ${GO} mod verify
Zack Williams52209662019-02-07 10:15:31 -0700244
Joey Armstrong670d40c2023-05-11 20:49:26 -0400245 $(call banner-leave,target $@)
246
247## -----------------------------------------------------------------------
248## Intent: Java targets
249## -----------------------------------------------------------------------
Joey Armstrong56b36782023-05-30 17:30:11 -0400250
251java-protos-dirs += java_temp/src/main/java
252java-protos-dirs += java_temp/src/main/java/org
253# local docker problem
254java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter
255java-protos-dirs += java_temp/src/main/java/org/opencord/voltha/adapter_service
256
257mkdir-args += -vp
Joey Armstronge05f6492023-05-31 11:27:31 -0400258# mkdir-args += --mode=0777
Joey Armstrong56b36782023-05-30 17:30:11 -0400259
Kent Hagerman868dc382020-01-20 11:24:09 -0500260java-protos: voltha.pb
Joey Armstrong56b36782023-05-30 17:30:11 -0400261
Joey Armstrong670d40c2023-05-11 20:49:26 -0400262 $(call banner-enter,target $@)
263
Joey Armstrong56b36782023-05-30 17:30:11 -0400264# $(RM) -fr java_temp
265 mkdir $(mkdir-args) $(java-protos-dirs)
266 $(docker-sh) $(quote-double) find $(java-protos-dirs) -print0 \
267 | xargs -0 -n1 /bin/ls -ld $(quote-double)
268
Joey Armstrong761579c2023-05-08 11:59:57 -0400269 @${PROTOC_SH} $(quote-double) \
Kent Hagerman868dc382020-01-20 11:24:09 -0500270 set -e -o pipefail; \
271 for x in ${PROTO_FILES}; do \
272 echo \$$x; \
273 protoc --java_out=java_temp/src/main/java -I protos \$$x; \
Joey Armstrong56b36782023-05-30 17:30:11 -0400274 done\
275 $(quote-double)
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300276
Joey Armstrong670d40c2023-05-11 20:49:26 -0400277 # Move files into place after all prototypes have generated.
278 # TODO: Remove the extra step, use makefile deps and
279 # generate in-place as needed.
280 @mkdir -p java
281 cp -r java_temp/src/main/java/* java
282
283 $(call banner-leave,target $@)
284
285## -----------------------------------------------------------------------
286## Intent: Tests if the generated java classes are compilable
287## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300288java-test: java-protos
289 cp test/pom.xml java_temp
290 cd java_temp && mvn compile
291
Joey Armstrong670d40c2023-05-11 20:49:26 -0400292## -----------------------------------------------------------------------
293## Intent: Custodial service
294## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300295java-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500296 $(RM) -r java
297 $(RM) -r java_temp
298
Joey Armstrong56b36782023-05-30 17:30:11 -0400299## -----------------------------------------------------------------------
300## Intent: Placeholder for library targets
301## -----------------------------------------------------------------------
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500302lint :
303
Joey Armstrong56b36782023-05-30 17:30:11 -0400304## -----------------------------------------------------------------------
305## Intent: Display/debug targets
306## -----------------------------------------------------------------------
307.PHONY: show-proto-files
308show-proto-files:
309 echo -e "PROTO_FILES:\n$(PROTO_FILES)" | tr ' ' '\n'
310
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500311# [EOF]
Joey Armstrong56b36782023-05-30 17:30:11 -0400312