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 | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 83 | ifeq ("", "$(shell which protoc)") |
William Kurkian | 6ea97f8 | 2019-03-13 15:51:55 -0400 | [diff] [blame] | 84 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 85 | @echo "It looks like you don't have a version of protocol buffer tools." |
William Kurkian | 6ea97f8 | 2019-03-13 15:51:55 -0400 | [diff] [blame] | 86 | @echo "To install the protocol buffer toolchain, you can run:" |
| 87 | @echo " make install-protoc" |
| 88 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
Matt Jeanneret | 61e9487 | 2019-03-22 16:16:01 -0400 | [diff] [blame^] | 89 | exit 1 |
William Kurkian | 6ea97f8 | 2019-03-13 15:51:55 -0400 | [diff] [blame] | 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: |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 94 | ifneq ("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 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
Matt Jeanneret | 61e9487 | 2019-03-22 16:16:01 -0400 | [diff] [blame^] | 100 | exit 1 |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 101 | endif |
| 102 | test/test-go-proto-consistency.sh |
Zack Williams | 5220966 | 2019-02-07 10:15:31 -0700 | [diff] [blame] | 103 | |
| 104 | go-clean: |
| 105 | echo "FIXME: Add golang cleanup" |
| 106 | |
William Kurkian | 6ea97f8 | 2019-03-13 15:51:55 -0400 | [diff] [blame] | 107 | install-protoc: |
| 108 | @echo "Downloading and installing protocol buffer support." |
Matt Jeanneret | 61e9487 | 2019-03-22 16:16:01 -0400 | [diff] [blame^] | 109 | @echo "Installation will require sudo priviledges" |
William Kurkian | 6ea97f8 | 2019-03-13 15:51:55 -0400 | [diff] [blame] | 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; \ |
Matt Jeanneret | 61e9487 | 2019-03-22 16:16:01 -0400 | [diff] [blame^] | 120 | sudo make install; \ |
William Kurkian | ad74565 | 2019-03-20 08:45:51 -0400 | [diff] [blame] | 121 | sudo ldconfig |