blob: 1825bae8386fc0b60201e79cde5d602d0e146e1a [file] [log] [blame]
Zack Williams52209662019-02-07 10:15:31 -07001# Copyright 2019-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Makefile for voltha-protos
16default: test
17
18# Variables
19PROTO_FILES := $(wildcard protos/voltha_protos/*.proto)
20PROTO_PYTHON_DEST_DIR := python/voltha_protos
21PROTO_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 -050022PROTO_PYTHON_PB2_GRPC := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2_grpc.py,$(f)))
Zack Williams52209662019-02-07 10:15:31 -070023
William Kurkian6ea97f82019-03-13 15:51:55 -040024PROTOC_PREFIX := /usr/local
25PROTOC_VERSION := "3.7.0"
26PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download"
27PROTOC_DIR := protobuf-$(PROTOC_VERSION)
28PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz
29PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL)
30PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')"
31
Zack Williams52209662019-02-07 10:15:31 -070032print:
33 echo "Proto files: $(PROTO_FILES)"
34 echo "Python PB2 files: $(PROTO_PYTHON_PB2)"
William Kurkianbd3736d2019-03-08 12:20:40 -050035
Zack Williams52209662019-02-07 10:15:31 -070036# set default shell
37SHELL = bash -e -o pipefail
38
39# Generic targets
40protos: python-protos go-protos
41
William Kurkianbd3736d2019-03-08 12:20:40 -050042build: protos python-build go-protos
Zack Williams52209662019-02-07 10:15:31 -070043
44test: python-test go-test
45
46clean: python-clean go-clean
47
48# Python targets
49python-protos: $(PROTO_PYTHON_PB2)
50
51venv_protos:
52 virtualenv $@;\
53 source ./$@/bin/activate ; set -u ;\
54 pip install grpcio-tools googleapis-common-protos
55
56$(PROTO_PYTHON_DEST_DIR)/%_pb2.py: protos/voltha_protos/%.proto Makefile venv_protos
57 source ./venv_protos/bin/activate ; set -u ;\
58 python -m grpc_tools.protoc \
59 -I protos \
60 --python_out=python \
61 --grpc_python_out=python \
62 --descriptor_set_out=$(PROTO_PYTHON_DEST_DIR)/$(basename $(notdir $<)).desc \
63 --include_imports \
64 --include_source_info \
65 $<
66
67python-build: setup.py
68 python ./setup.py sdist
69
70python-test: tox.ini setup.py python-protos
71 tox
72
73python-clean:
Matt Jeanneret37e0fc62019-03-07 12:33:21 -050074 rm -rf venv_protos .coverage coverage.xml nose2-results.xml dist $(PROTO_PYTHON_PB2) $(PROTO_PYTHON_PB2_GRPC) $(PROTO_PYTHON_DEST_DIR)/*.desc
75 find python/ -name '*.pyc' | xargs rm -f
76 rm -rf python/voltha_protos.egg-info
77 rm -rf .tox
78 rm -rf python/__pycache__/
79 rm -rf python/test/__pycache__/
Zack Williams52209662019-02-07 10:15:31 -070080
81# Go targets
82go-protos:
William Kurkianad745652019-03-20 08:45:51 -040083ifeq ("", "$(shell which protoc)")
William Kurkian6ea97f82019-03-13 15:51:55 -040084 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
William Kurkianad745652019-03-20 08:45:51 -040085 @echo "It looks like you don't have a version of protocol buffer tools."
William Kurkian6ea97f82019-03-13 15:51:55 -040086 @echo "To install the protocol buffer toolchain, you can run:"
87 @echo " make install-protoc"
88 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
89 false
90endif
William Kurkianbd3736d2019-03-08 12:20:40 -050091 ./build_go_protos.sh protos
Zack Williams52209662019-02-07 10:15:31 -070092
93go-test:
William Kurkianad745652019-03-20 08:45:51 -040094ifneq ("libprotoc 3.7.0", "$(shell protoc --version)")
95 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
96 @echo "It looks like you don't have protocol buffer tools ${PROTOC_VERSION} installed."
97>---@echo "To install this version, you can run:"
98 @echo " make install-protoc"
99 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
100 false
101endif
102 test/test-go-proto-consistency.sh
Zack Williams52209662019-02-07 10:15:31 -0700103
104go-clean:
105 echo "FIXME: Add golang cleanup"
106
William Kurkian6ea97f82019-03-13 15:51:55 -0400107install-protoc:
108 @echo "Downloading and installing protocol buffer support."
109 @echo "Installation will require sodo priviledges"
110 @echo "This will take a few minutes."
111 mkdir -p $(PROTOC_BUILD_TMP_DIR)
112 @echo "We ask for sudo credentials now so we can install at the end"; \
113 sudo echo "Thanks"; \
114 cd $(PROTOC_BUILD_TMP_DIR); \
115 wget $(PROTOC_DOWNLOAD_URI); \
116 tar xzvf $(PROTOC_TARBALL); \
117 cd $(PROTOC_DIR); \
118 ./configure --prefix=$(PROTOC_PREFIX); \
119 make; \
William Kurkianad745652019-03-20 08:45:51 -0400120 sudo make install; \
121 sudo ldconfig