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 | # |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 16 | |
| 17 | ifeq ($(TAG),) |
| 18 | TAG := latest |
| 19 | endif |
| 20 | |
| 21 | ifeq ($(TARGET_TAG),) |
| 22 | TARGET_TAG := latest |
| 23 | endif |
| 24 | |
| 25 | ifneq ($(http_proxy)$(https_proxy),) |
| 26 | # Include proxies from the environment |
| 27 | DOCKER_PROXY_ARGS = \ |
| 28 | --build-arg http_proxy=$(http_proxy) \ |
| 29 | --build-arg https_proxy=$(https_proxy) \ |
| 30 | --build-arg ftp_proxy=$(ftp_proxy) \ |
| 31 | --build-arg no_proxy=$(no_proxy) \ |
| 32 | --build-arg HTTP_PROXY=$(HTTP_PROXY) \ |
| 33 | --build-arg HTTPS_PROXY=$(HTTPS_PROXY) \ |
| 34 | --build-arg FTP_PROXY=$(FTP_PROXY) \ |
| 35 | --build-arg NO_PROXY=$(NO_PROXY) |
| 36 | endif |
| 37 | |
| 38 | DOCKER_BUILD_ARGS = \ |
| 39 | --build-arg TAG=$(TAG) \ |
| 40 | --build-arg REGISTRY=$(REGISTRY) \ |
| 41 | --build-arg REPOSITORY=$(REPOSITORY) \ |
| 42 | $(DOCKER_PROXY_ARGS) $(DOCKER_CACHE_ARG) \ |
| 43 | --rm --force-rm \ |
| 44 | $(DOCKER_BUILD_EXTRA_ARGS) |
| 45 | |
| 46 | DOCKER_IMAGE_LIST = \ |
| 47 | pyvoltha-base \ |
| 48 | pyvoltha |
| 49 | |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 50 | VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 51 | |
| 52 | VENV_BIN ?= virtualenv |
| 53 | VENV_OPTS ?= |
| 54 | |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 55 | .PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8 protos venv rebuild-venv clean distclean build test docker_base_img docker_image |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 56 | |
| 57 | # This should to be the first and default target in this Makefile |
| 58 | help: |
| 59 | @echo "Usage: make [<target>]" |
| 60 | @echo "where available targets are:" |
| 61 | @echo |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 62 | @echo "build : Build the protos" |
| 63 | @echo "dist : Build the protos and create the python package" |
| 64 | @echo "docker_base_img : Build a base docker image with a modern version of pip and requirements.txt installed" |
| 65 | @echo "docker_image : Build a docker image with pyvoltha installed" |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame^] | 66 | @echo "utest : Run all unit test" |
| 67 | @echo "utest-with-coverage : Run all unit test with coverage reporting" |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 68 | @echo "clean : Remove files created by the build and tests" |
| 69 | @echo "distclean : Remove venv directory" |
| 70 | @echo "help : Print this help" |
| 71 | @echo "protos : Compile all grpc/protobuf files" |
| 72 | @echo "rebuild-venv : Rebuild local Python virtualenv from scratch" |
| 73 | @echo "venv : Build local Python virtualenv if did not exist yet" |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 74 | @echo |
| 75 | |
| 76 | ## New directories can be added here |
| 77 | #DIRS:= |
| 78 | |
| 79 | ## If one directory depends on another directory that |
| 80 | ## dependency can be expressed here |
| 81 | ## |
| 82 | ## For example, if the Tibit directory depended on the eoam |
| 83 | ## directory being built first, then that can be expressed here. |
| 84 | ## driver/tibit: eoam |
| 85 | |
| 86 | # Parallel Build |
| 87 | $(DIRS): |
| 88 | @echo " MK $@" |
| 89 | $(Q)$(MAKE) -C $@ |
| 90 | |
| 91 | # Parallel Clean |
| 92 | DIRS_CLEAN = $(addsuffix .clean,$(DIRS)) |
| 93 | $(DIRS_CLEAN): |
| 94 | @echo " CLEAN $(basename $@)" |
| 95 | $(Q)$(MAKE) -C $(basename $@) clean |
| 96 | |
| 97 | # Parallel Flake8 |
| 98 | DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS)) |
| 99 | $(DIRS_FLAKE8): |
| 100 | @echo " FLAKE8 $(basename $@)" |
| 101 | -$(Q)$(MAKE) -C $(basename $@) flake8 |
| 102 | |
| 103 | build: protos |
| 104 | |
| 105 | protos: |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame^] | 106 | @ . ${VENVDIR}/bin/activate && make -C pyvoltha/protos |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 107 | |
| 108 | dist: venv protos |
| 109 | @ echo "Creating PyPi artifacts" |
| 110 | python setup.py sdist |
| 111 | |
| 112 | upload: dist |
| 113 | @ echo "Uploading PyPi artifacts" |
| 114 | twine upload --repository-url https://test.pypi.org/legacy/ dist/* |
| 115 | twine upload dist/* |
| 116 | |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 117 | docker_base_img: |
| 118 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}pyvoltha-base:${TAG} -f docker/Dockerfile.base . |
| 119 | |
| 120 | docker_image: docker_base_img dist |
| 121 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}pyvoltha:${TAG} -f docker/Dockerfile.pyvoltha . |
| 122 | |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 123 | install-protoc: |
| 124 | make -C pyvoltha/protos install-protoc |
| 125 | |
| 126 | test: venv protos |
| 127 | @ echo "Executing all unit tests" |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame^] | 128 | @ tox -- --with-xunit |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 129 | |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame^] | 130 | COVERAGE_OPTS=--with-coverage --with-xunit --cover-branches --cover-html --cover-html-dir=tmp/cover \ |
| 131 | --cover-package=pyvoltha.adapters,pyvoltha.common |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 132 | |
| 133 | utest-with-coverage: venv protos |
| 134 | @ echo "Executing all unit tests and producing coverage results" |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame^] | 135 | @ tox -- $(COVERAGE_OPTS) |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 136 | |
| 137 | clean: |
| 138 | find . -name '*.pyc' | xargs rm -f |
| 139 | find . -name 'coverage.xml' | xargs rm -f |
| 140 | find . -name 'nosetests.xml' | xargs rm -f |
Matt Jeanneret | 6b6d936 | 2019-02-11 10:48:41 -0500 | [diff] [blame] | 141 | make -C pyvoltha/protos clean |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame^] | 142 | rm -rf pyvoltha.egg-info |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 143 | rm -rf dist |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame^] | 144 | rm -rf .tox |
| 145 | rm -rf test/unit/tmp |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 146 | |
| 147 | distclean: clean |
| 148 | rm -rf ${VENVDIR} |
| 149 | |
| 150 | purge-venv: |
| 151 | rm -fr ${VENVDIR} |
| 152 | |
| 153 | rebuild-venv: purge-venv venv |
| 154 | |
| 155 | venv: ${VENVDIR}/.built |
| 156 | |
| 157 | ${VENVDIR}/.built: |
| 158 | @ $(VENV_BIN) ${VENV_OPTS} ${VENVDIR} |
| 159 | @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR} |
| 160 | @ . ${VENVDIR}/bin/activate && \ |
| 161 | pip install --upgrade pip; \ |
| 162 | if ! pip install -r requirements.txt; \ |
| 163 | then \ |
| 164 | echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \ |
| 165 | echo "see the BUILD.md file for a workaround"; \ |
| 166 | else \ |
| 167 | uname -s > ${VENVDIR}/.built; \ |
| 168 | fi |
| 169 | @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR} |
| 170 | |
| 171 | |
| 172 | flake8: $(DIRS_FLAKE8) |
| 173 | |
| 174 | # end file |