blob: b7673e0a4e67081e2773fca4e0a047dc1ec4b805 [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
33export DISTUTILS_DEBUG := 1
Joey Armstrong670d40c2023-05-11 20:49:26 -040034export DOCKER_DEBUG := 1
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
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030053# Function to extract the last path component from package line in .proto files
54define java_package_path
55$(shell grep package $(1) | sed -n 's/.*\/\(.*\)";/\1/p')
56endef
57
Zack Williams52209662019-02-07 10:15:31 -070058# Variables
Zack Williams43bfd9e2019-04-12 13:09:31 -070059PROTO_FILES := $(sort $(wildcard protos/voltha_protos/*.proto))
60
Zack Williams52209662019-02-07 10:15:31 -070061PROTO_PYTHON_DEST_DIR := python/voltha_protos
62PROTO_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 -050063PROTO_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 -070064PROTO_GO_DEST_DIR := go
65PROTO_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 +030066PROTO_JAVA_DEST_DIR := java
Joey Armstrong670d40c2023-05-11 20:49:26 -040067PROTO_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 -040068
Zack Williams25e0a322019-06-07 14:07:21 -070069# 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 -050070.PHONY: voltha.pb
Matt Jeanneret15249fa2019-04-12 20:25:31 -040071
Zack Williams52209662019-02-07 10:15:31 -070072print:
Zack Williams43bfd9e2019-04-12 13:09:31 -070073 @echo "Proto files: $(PROTO_FILES)"
74 @echo "Python PB2 files: $(PROTO_PYTHON_PB2)"
75 @echo "Go PB files: $(PROTO_GO_PB)"
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030076 @echo "JAVA PB files: $(PROTO_JAVA_PB)"
Zack Williams52209662019-02-07 10:15:31 -070077
78# Generic targets
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030079protos: python-protos go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -070080
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030081build: protos python-build go-protos java-protos
Zack Williams52209662019-02-07 10:15:31 -070082
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +030083test: python-test go-test java-test
Zack Williams52209662019-02-07 10:15:31 -070084
Joey Armstrong761579c2023-05-08 11:59:57 -040085clean :: python-clean java-clean go-clean
Zack Williams52209662019-02-07 10:15:31 -070086
Joey Armstrong761579c2023-05-08 11:59:57 -040087sterile :: clean
Joey Armstrongc2277652023-01-11 17:41:36 -050088
Zack Williams52209662019-02-07 10:15:31 -070089# Python targets
Kent Hagerman868dc382020-01-20 11:24:09 -050090python-protos: $(PROTO_PYTHON_PB2)
Zack Williams52209662019-02-07 10:15:31 -070091
Joey Armstrong761579c2023-05-08 11:59:57 -040092## -----------------------------------------------------------------------
93## -----------------------------------------------------------------------
94$(PROTO_PYTHON_DEST_DIR)/%_pb2.py: \
95 protos/voltha_protos/%.proto \
96 Makefile \
97 $(venv-activate-script)
Joey Armstrong670d40c2023-05-11 20:49:26 -040098
99 @echo
100 @echo "** -----------------------------------------------------------------------"
101 @echo "** $(MAKE): processing target [$@]"
102 @echo "** -----------------------------------------------------------------------"
103
104 $(activate) && python -m grpc_tools.protoc \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700105 -I protos \
106 --python_out=python \
107 --grpc_python_out=python \
108 --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \
109 --include_imports \
110 --include_source_info \
111 $<
Zack Williams52209662019-02-07 10:15:31 -0700112
Joey Armstrong670d40c2023-05-11 20:49:26 -0400113## -----------------------------------------------------------------------
114## Intent:
115## -----------------------------------------------------------------------
116show:
117 $(call banner-enter,target $@)
118 @echo
119 $(call banner-leave,target $@)
120
121## -----------------------------------------------------------------------
122## Intent:
123## -----------------------------------------------------------------------
124python-build: setup.py python-protos
125
126 $(call banner-enter,target $@)
127
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500128 $(RM) -r dist/
Zack Williams52209662019-02-07 10:15:31 -0700129 python ./setup.py sdist
130
Joey Armstrong670d40c2023-05-11 20:49:26 -0400131 $(call banner-leave,target $@)
132
133## -----------------------------------------------------------------------
134## Intent:
135## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700136python-test: tox.ini setup.py python-protos
Joey Armstrong670d40c2023-05-11 20:49:26 -0400137 $(call banner-enter,target $@)
138
139 $(activate) && python --version
Zack Williams52209662019-02-07 10:15:31 -0700140 tox
141
Joey Armstrong670d40c2023-05-11 20:49:26 -0400142 $(call banner-leave,target $@)
143
144## -----------------------------------------------------------------------
145## Intent:
146## -----------------------------------------------------------------------
Zack Williams52209662019-02-07 10:15:31 -0700147python-clean:
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500148 find python -name '__pycache__' -type d -print0 \
149 | xargs -0 --no-run-if-empty $(RM) -r
Joey Armstrongc2277652023-01-11 17:41:36 -0500150 find python -name '*.pyc' -type f -print0 \
151 | xargs -0 --no-run-if-empty $(RM)
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500152 $(RM) -r \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700153 .coverage \
154 .tox \
155 coverage.xml \
156 dist \
157 nose2-results.xml \
158 python/__pycache__ \
159 python/test/__pycache__ \
160 python/voltha_protos.egg-info \
Joey Armstrong761579c2023-05-08 11:59:57 -0400161 "$(venv-abs-path)" \
Zack Williams43bfd9e2019-04-12 13:09:31 -0700162 $(PROTO_PYTHON_DEST_DIR)/*.desc \
163 $(PROTO_PYTHON_PB2) \
164 $(PROTO_PYTHON_PB2_GRPC)
Zack Williams52209662019-02-07 10:15:31 -0700165
Joey Armstrong761579c2023-05-08 11:59:57 -0400166## -----------------------------------------------------------------------
167## Intent: Revert go to a clean state.
168## o TODO - go/ directory should not be placed under revision control.
169## o Build should retrieve versioned sources from a central repo.
170## -----------------------------------------------------------------------
khenaidoo5fc5cea2021-08-11 17:39:16 -0400171go-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500172 $(RM) -r go/*
Joey Armstrong761579c2023-05-08 11:59:57 -0400173 $(HIDE)$(MAKE) repair
174
175## -----------------------------------------------------------------------
176## Intent: Recover from a fatal failed build state:
177## o build removes go/ while regenerating prototypes.
178## o chicken-n-egg: make becomes fatal when go/ is removed and proten fails.
179## -----------------------------------------------------------------------
180repair:
181 /usr/bin/env git checkout go
182
Joey Armstrong670d40c2023-05-11 20:49:26 -0400183## -----------------------------------------------------------------------
184## Intent: Go targets
185## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500186go-protos: voltha.pb
Joey Armstrong670d40c2023-05-11 20:49:26 -0400187
188 @echo
189 @echo "** -----------------------------------------------------------------------"
190 @echo "** $(MAKE): processing target [$@]"
191 @echo "** Creating *.go.pb files"
192 @echo "** -----------------------------------------------------------------------"
193
194 @echo
Joey Armstrong761579c2023-05-08 11:59:57 -0400195 @echo "PROTO_FILES=$(PROTO_FILES)" | tr ' ' '\n'
Joey Armstrong670d40c2023-05-11 20:49:26 -0400196
197 @echo
Joey Armstrong761579c2023-05-08 11:59:57 -0400198 ${PROTOC_SH} $(quote-double)\
Kent Hagerman868dc382020-01-20 11:24:09 -0500199 set -e -o pipefail; \
200 for x in ${PROTO_FILES}; do \
201 echo \$$x; \
202 protoc --go_out=plugins=grpc:/go/src -I protos \$$x; \
Joey Armstrong761579c2023-05-08 11:59:57 -0400203 done$(quote-double)
Zack Williams43bfd9e2019-04-12 13:09:31 -0700204
Joey Armstrong670d40c2023-05-11 20:49:26 -0400205## -----------------------------------------------------------------------
206## Intent:
207## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500208voltha.pb:
Joey Armstrong670d40c2023-05-11 20:49:26 -0400209 $(call banner-enter,target $@)
210
211 ${PROTOC} \
212 -I protos \
213 -I protos/google/api \
214 --include_imports \
215 --include_source_info \
Kent Hagerman868dc382020-01-20 11:24:09 -0500216 --descriptor_set_out=$@ \
217 ${PROTO_FILES}
Zack Williams43bfd9e2019-04-12 13:09:31 -0700218
Joey Armstrong670d40c2023-05-11 20:49:26 -0400219 $(call banner-leave,target $@)
220
221## -----------------------------------------------------------------------
222## Intent:
223## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500224go-test:
Joey Armstrong670d40c2023-05-11 20:49:26 -0400225 $(call banner-enter,target $@)
226
William Kurkianad745652019-03-20 08:45:51 -0400227 test/test-go-proto-consistency.sh
Kent Hagerman868dc382020-01-20 11:24:09 -0500228 ${GO} mod verify
Zack Williams52209662019-02-07 10:15:31 -0700229
Joey Armstrong670d40c2023-05-11 20:49:26 -0400230 $(call banner-leave,target $@)
231
232## -----------------------------------------------------------------------
233## Intent: Java targets
234## -----------------------------------------------------------------------
Kent Hagerman868dc382020-01-20 11:24:09 -0500235java-protos: voltha.pb
Joey Armstrong670d40c2023-05-11 20:49:26 -0400236 $(call banner-enter,target $@)
237
Kent Hagerman868dc382020-01-20 11:24:09 -0500238 @mkdir -p java_temp/src/main/java
Joey Armstrong761579c2023-05-08 11:59:57 -0400239 @${PROTOC_SH} $(quote-double) \
Kent Hagerman868dc382020-01-20 11:24:09 -0500240 set -e -o pipefail; \
241 for x in ${PROTO_FILES}; do \
242 echo \$$x; \
243 protoc --java_out=java_temp/src/main/java -I protos \$$x; \
Joey Armstrong761579c2023-05-08 11:59:57 -0400244 done$(quote-double)
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300245
Joey Armstrong670d40c2023-05-11 20:49:26 -0400246 # Move files into place after all prototypes have generated.
247 # TODO: Remove the extra step, use makefile deps and
248 # generate in-place as needed.
249 @mkdir -p java
250 cp -r java_temp/src/main/java/* java
251
252 $(call banner-leave,target $@)
253
254## -----------------------------------------------------------------------
255## Intent: Tests if the generated java classes are compilable
256## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300257java-test: java-protos
258 cp test/pom.xml java_temp
259 cd java_temp && mvn compile
260
Joey Armstrong670d40c2023-05-11 20:49:26 -0400261## -----------------------------------------------------------------------
262## Intent: Custodial service
263## -----------------------------------------------------------------------
Serkant Uluderyacbcfaa42019-10-18 13:25:08 +0300264java-clean:
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500265 $(RM) -r java
266 $(RM) -r java_temp
267
Joey Armstronge66eaaf2023-01-15 18:58:52 -0500268# placeholder for library targets
269lint :
270
Joey Armstronge6cdd8e2022-12-29 11:58:15 -0500271# [EOF]