blob: 16a495eb71d94509c9d3801d08d83b5b61198d28 [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 Kurkian6ea97f82019-03-13 15:51:55 -040083ifeq (, $(shell which protoc))
84 @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
85 @echo "It looks like you don't have protocol buffer tools installed."
86 @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:
94 echo "FIXME: Add golang tests"
95
96go-clean:
97 echo "FIXME: Add golang cleanup"
98
William Kurkian6ea97f82019-03-13 15:51:55 -040099install-protoc:
100 @echo "Downloading and installing protocol buffer support."
101 @echo "Installation will require sodo priviledges"
102 @echo "This will take a few minutes."
103 mkdir -p $(PROTOC_BUILD_TMP_DIR)
104 @echo "We ask for sudo credentials now so we can install at the end"; \
105 sudo echo "Thanks"; \
106 cd $(PROTOC_BUILD_TMP_DIR); \
107 wget $(PROTOC_DOWNLOAD_URI); \
108 tar xzvf $(PROTOC_TARBALL); \
109 cd $(PROTOC_DIR); \
110 ./configure --prefix=$(PROTOC_PREFIX); \
111 make; \
112 sudo make install
113