Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame^] | 1 | # |
| 2 | # Copyright 2018 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 17 | |
| 18 | VENV_BIN ?= virtualenv |
| 19 | VENV_OPTS ?= |
| 20 | |
| 21 | .PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8 protos venv rebuild-venv clean distclean build test |
| 22 | |
| 23 | # This should to be the first and default target in this Makefile |
| 24 | help: |
| 25 | @echo "Usage: make [<target>]" |
| 26 | @echo "where available targets are:" |
| 27 | @echo |
| 28 | @echo "build : Build the protos" |
| 29 | @echo "dist : Build the protos and create the python package" |
| 30 | @echo "test : Run all unit test" |
| 31 | @echo "clean : Remove files created by the build and tests" |
| 32 | @echo "distclean : Remove venv directory" |
| 33 | @echo "help : Print this help" |
| 34 | @echo "protos : Compile all grpc/protobuf files" |
| 35 | @echo "rebuild-venv : Rebuild local Python virtualenv from scratch" |
| 36 | @echo "venv : Build local Python virtualenv if did not exist yet" |
| 37 | @echo |
| 38 | |
| 39 | ## New directories can be added here |
| 40 | #DIRS:= |
| 41 | |
| 42 | ## If one directory depends on another directory that |
| 43 | ## dependency can be expressed here |
| 44 | ## |
| 45 | ## For example, if the Tibit directory depended on the eoam |
| 46 | ## directory being built first, then that can be expressed here. |
| 47 | ## driver/tibit: eoam |
| 48 | |
| 49 | # Parallel Build |
| 50 | $(DIRS): |
| 51 | @echo " MK $@" |
| 52 | $(Q)$(MAKE) -C $@ |
| 53 | |
| 54 | # Parallel Clean |
| 55 | DIRS_CLEAN = $(addsuffix .clean,$(DIRS)) |
| 56 | $(DIRS_CLEAN): |
| 57 | @echo " CLEAN $(basename $@)" |
| 58 | $(Q)$(MAKE) -C $(basename $@) clean |
| 59 | |
| 60 | # Parallel Flake8 |
| 61 | DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS)) |
| 62 | $(DIRS_FLAKE8): |
| 63 | @echo " FLAKE8 $(basename $@)" |
| 64 | -$(Q)$(MAKE) -C $(basename $@) flake8 |
| 65 | |
| 66 | build: protos |
| 67 | |
| 68 | protos: |
| 69 | make -C pyvoltha/protos |
| 70 | |
| 71 | dist: venv protos |
| 72 | @ echo "Creating PyPi artifacts" |
| 73 | python setup.py sdist |
| 74 | |
| 75 | upload: dist |
| 76 | @ echo "Uploading PyPi artifacts" |
| 77 | twine upload --repository-url https://test.pypi.org/legacy/ dist/* |
| 78 | twine upload dist/* |
| 79 | |
| 80 | install-protoc: |
| 81 | make -C pyvoltha/protos install-protoc |
| 82 | |
| 83 | test: venv protos |
| 84 | @ echo "Executing all unit tests" |
| 85 | @ . ${VENVDIR}/bin/activate && tox |
| 86 | # @ . ${VENVDIR}/bin/activate && make -C test utest |
| 87 | |
| 88 | COVERAGE_OPTS=--with-xcoverage --with-xunit --cover-package=voltha,common,ofagent --cover-html\ |
| 89 | --cover-html-dir=tmp/cover |
| 90 | |
| 91 | utest-with-coverage: venv protos |
| 92 | @ echo "Executing all unit tests and producing coverage results" |
| 93 | @ . ${VENVDIR}/bin/activate && nosetests $(COVERAGE_OPTS) pyvoltha/tests/utests |
| 94 | |
| 95 | clean: |
| 96 | find . -name '*.pyc' | xargs rm -f |
| 97 | find . -name 'coverage.xml' | xargs rm -f |
| 98 | find . -name 'nosetests.xml' | xargs rm -f |
| 99 | rm -f pyvoltha/protos/*_pb2.py |
| 100 | rm -f pyvoltha/protos/*_pb2_grpc.py |
| 101 | rm -f pyvoltha/protos/*.desc |
| 102 | rm -rf PyVoltha.egg-info |
| 103 | rm -rf dist |
| 104 | |
| 105 | distclean: clean |
| 106 | rm -rf ${VENVDIR} |
| 107 | |
| 108 | purge-venv: |
| 109 | rm -fr ${VENVDIR} |
| 110 | |
| 111 | rebuild-venv: purge-venv venv |
| 112 | |
| 113 | venv: ${VENVDIR}/.built |
| 114 | |
| 115 | ${VENVDIR}/.built: |
| 116 | @ $(VENV_BIN) ${VENV_OPTS} ${VENVDIR} |
| 117 | @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR} |
| 118 | @ . ${VENVDIR}/bin/activate && \ |
| 119 | pip install --upgrade pip; \ |
| 120 | if ! pip install -r requirements.txt; \ |
| 121 | then \ |
| 122 | echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \ |
| 123 | echo "see the BUILD.md file for a workaround"; \ |
| 124 | else \ |
| 125 | uname -s > ${VENVDIR}/.built; \ |
| 126 | fi |
| 127 | @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR} |
| 128 | |
| 129 | |
| 130 | flake8: $(DIRS_FLAKE8) |
| 131 | |
| 132 | # end file |