Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 1 | # 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 |
| 16 | default: test |
| 17 | |
| 18 | # Variables |
| 19 | PROTO_FILES := $(wildcard protos/voltha_protos/*.proto) |
| 20 | PROTO_PYTHON_DEST_DIR := python/voltha_protos |
| 21 | PROTO_PYTHON_PB2 := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2.py,$(f))) |
Matt Jeanneret | 37e0fc6 | 2019-03-07 12:33:21 -0500 | [diff] [blame] | 22 | PROTO_PYTHON_PB2_GRPC := $(foreach f, $(PROTO_FILES), $(patsubst protos/voltha_protos/%.proto,$(PROTO_PYTHON_DEST_DIR)/%_pb2_grpc.py,$(f))) |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 23 | |
William Kurkian | 6ea97f8 | 2019-03-13 15:51:55 -0400 | [diff] [blame^] | 24 | PROTOC_PREFIX := /usr/local |
| 25 | PROTOC_VERSION := "3.7.0" |
| 26 | PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download" |
| 27 | PROTOC_DIR := protobuf-$(PROTOC_VERSION) |
| 28 | PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz |
| 29 | PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL) |
| 30 | PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')" |
| 31 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 32 | print: |
| 33 | echo "Proto files: $(PROTO_FILES)" |
| 34 | echo "Python PB2 files: $(PROTO_PYTHON_PB2)" |
William Kurkian | bd3736d | 2019-03-08 12:20:40 -0500 | [diff] [blame] | 35 | |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 36 | # set default shell |
| 37 | SHELL = bash -e -o pipefail |
| 38 | |
| 39 | # Generic targets |
| 40 | protos: python-protos go-protos |
| 41 | |
William Kurkian | bd3736d | 2019-03-08 12:20:40 -0500 | [diff] [blame] | 42 | build: protos python-build go-protos |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 43 | |
| 44 | test: python-test go-test |
| 45 | |
| 46 | clean: python-clean go-clean |
| 47 | |
| 48 | # Python targets |
| 49 | python-protos: $(PROTO_PYTHON_PB2) |
| 50 | |
| 51 | venv_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 | |
| 67 | python-build: setup.py |
| 68 | python ./setup.py sdist |
| 69 | |
| 70 | python-test: tox.ini setup.py python-protos |
| 71 | tox |
| 72 | |
| 73 | python-clean: |
Matt Jeanneret | 37e0fc6 | 2019-03-07 12:33:21 -0500 | [diff] [blame] | 74 | 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 Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 80 | |
| 81 | # Go targets |
| 82 | go-protos: |
William Kurkian | 6ea97f8 | 2019-03-13 15:51:55 -0400 | [diff] [blame^] | 83 | ifeq (, $(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 |
| 90 | endif |
William Kurkian | bd3736d | 2019-03-08 12:20:40 -0500 | [diff] [blame] | 91 | ./build_go_protos.sh protos |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 92 | |
| 93 | go-test: |
| 94 | echo "FIXME: Add golang tests" |
| 95 | |
| 96 | go-clean: |
| 97 | echo "FIXME: Add golang cleanup" |
| 98 | |
William Kurkian | 6ea97f8 | 2019-03-13 15:51:55 -0400 | [diff] [blame^] | 99 | install-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 | |