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 | |
William Kurkian | ede82e9 | 2019-03-05 13:02:57 -0500 | [diff] [blame] | 55 | .PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8 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 |
William Kurkian | ede82e9 | 2019-03-05 13:02:57 -0500 | [diff] [blame] | 62 | @echo "dist : Create the python package" |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 63 | @echo "docker_base_img : Build a base docker image with a modern version of pip and requirements.txt installed" |
| 64 | @echo "docker_image : Build a docker image with pyvoltha installed" |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame] | 65 | @echo "utest : Run all unit test" |
| 66 | @echo "utest-with-coverage : Run all unit test with coverage reporting" |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 67 | @echo "clean : Remove files created by the build and tests" |
| 68 | @echo "distclean : Remove venv directory" |
| 69 | @echo "help : Print this help" |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 70 | @echo "rebuild-venv : Rebuild local Python virtualenv from scratch" |
| 71 | @echo "venv : Build local Python virtualenv if did not exist yet" |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 72 | @echo |
| 73 | |
| 74 | ## New directories can be added here |
| 75 | #DIRS:= |
| 76 | |
| 77 | ## If one directory depends on another directory that |
| 78 | ## dependency can be expressed here |
| 79 | ## |
| 80 | ## For example, if the Tibit directory depended on the eoam |
| 81 | ## directory being built first, then that can be expressed here. |
| 82 | ## driver/tibit: eoam |
| 83 | |
| 84 | # Parallel Build |
| 85 | $(DIRS): |
| 86 | @echo " MK $@" |
| 87 | $(Q)$(MAKE) -C $@ |
| 88 | |
| 89 | # Parallel Clean |
| 90 | DIRS_CLEAN = $(addsuffix .clean,$(DIRS)) |
| 91 | $(DIRS_CLEAN): |
| 92 | @echo " CLEAN $(basename $@)" |
| 93 | $(Q)$(MAKE) -C $(basename $@) clean |
| 94 | |
| 95 | # Parallel Flake8 |
| 96 | DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS)) |
| 97 | $(DIRS_FLAKE8): |
| 98 | @echo " FLAKE8 $(basename $@)" |
| 99 | -$(Q)$(MAKE) -C $(basename $@) flake8 |
| 100 | |
William Kurkian | ede82e9 | 2019-03-05 13:02:57 -0500 | [diff] [blame] | 101 | dist: venv |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 102 | @ echo "Creating PyPi artifacts" |
| 103 | python setup.py sdist |
| 104 | |
| 105 | upload: dist |
| 106 | @ echo "Uploading PyPi artifacts" |
| 107 | twine upload --repository-url https://test.pypi.org/legacy/ dist/* |
| 108 | twine upload dist/* |
| 109 | |
Matt Jeanneret | f3ad685 | 2019-02-08 18:21:44 -0500 | [diff] [blame] | 110 | docker_base_img: |
| 111 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}pyvoltha-base:${TAG} -f docker/Dockerfile.base . |
| 112 | |
| 113 | docker_image: docker_base_img dist |
| 114 | docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}pyvoltha:${TAG} -f docker/Dockerfile.pyvoltha . |
| 115 | |
William Kurkian | ede82e9 | 2019-03-05 13:02:57 -0500 | [diff] [blame] | 116 | test: venv |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 117 | @ echo "Executing all unit tests" |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame] | 118 | @ tox -- --with-xunit |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 119 | |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame] | 120 | COVERAGE_OPTS=--with-coverage --with-xunit --cover-branches --cover-html --cover-html-dir=tmp/cover \ |
| 121 | --cover-package=pyvoltha.adapters,pyvoltha.common |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 122 | |
Matt Jeanneret | 29989eb | 2019-03-07 06:40:12 -0500 | [diff] [blame] | 123 | utest-with-coverage: venv |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 124 | @ echo "Executing all unit tests and producing coverage results" |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame] | 125 | @ tox -- $(COVERAGE_OPTS) |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 126 | |
| 127 | clean: |
| 128 | find . -name '*.pyc' | xargs rm -f |
| 129 | find . -name 'coverage.xml' | xargs rm -f |
| 130 | find . -name 'nosetests.xml' | xargs rm -f |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame] | 131 | rm -rf pyvoltha.egg-info |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 132 | rm -rf dist |
Chip Boling | ce2daf6 | 2019-02-12 13:53:39 -0600 | [diff] [blame] | 133 | rm -rf .tox |
| 134 | rm -rf test/unit/tmp |
Chip Boling | 67b674a | 2019-02-08 11:42:18 -0600 | [diff] [blame] | 135 | |
| 136 | distclean: clean |
| 137 | rm -rf ${VENVDIR} |
| 138 | |
| 139 | purge-venv: |
| 140 | rm -fr ${VENVDIR} |
| 141 | |
| 142 | rebuild-venv: purge-venv venv |
| 143 | |
| 144 | venv: ${VENVDIR}/.built |
| 145 | |
| 146 | ${VENVDIR}/.built: |
| 147 | @ $(VENV_BIN) ${VENV_OPTS} ${VENVDIR} |
| 148 | @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR} |
| 149 | @ . ${VENVDIR}/bin/activate && \ |
| 150 | pip install --upgrade pip; \ |
| 151 | if ! pip install -r requirements.txt; \ |
| 152 | then \ |
| 153 | echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \ |
| 154 | echo "see the BUILD.md file for a workaround"; \ |
| 155 | else \ |
| 156 | uname -s > ${VENVDIR}/.built; \ |
| 157 | fi |
| 158 | @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR} |
| 159 | |
| 160 | |
| 161 | flake8: $(DIRS_FLAKE8) |
| 162 | |
| 163 | # end file |