blob: 32d9d23ab95167c799b498aa36402d1466554459 [file] [log] [blame]
Chip Boling67b674a2019-02-08 11:42:18 -06001#
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 Jeanneretf3ad6852019-02-08 18:21:44 -050016
17ifeq ($(TAG),)
18TAG := latest
19endif
20
21ifeq ($(TARGET_TAG),)
22TARGET_TAG := latest
23endif
24
25ifneq ($(http_proxy)$(https_proxy),)
26# Include proxies from the environment
27DOCKER_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)
36endif
37
38DOCKER_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
46DOCKER_IMAGE_LIST = \
47 pyvoltha-base \
48 pyvoltha
49
Chip Boling67b674a2019-02-08 11:42:18 -060050VENVDIR := venv-$(shell uname -s | tr '[:upper:]' '[:lower:]')
51
52VENV_BIN ?= virtualenv
53VENV_OPTS ?=
54
William Kurkianede82e92019-03-05 13:02:57 -050055.PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8 venv rebuild-venv clean distclean build test docker_base_img docker_image
Chip Boling67b674a2019-02-08 11:42:18 -060056
57# This should to be the first and default target in this Makefile
58help:
59 @echo "Usage: make [<target>]"
60 @echo "where available targets are:"
61 @echo
William Kurkianede82e92019-03-05 13:02:57 -050062 @echo "dist : Create the python package"
Matt Jeanneretf3ad6852019-02-08 18:21:44 -050063 @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 Bolingce2daf62019-02-12 13:53:39 -060065 @echo "utest : Run all unit test"
66 @echo "utest-with-coverage : Run all unit test with coverage reporting"
Matt Jeanneretf3ad6852019-02-08 18:21:44 -050067 @echo "clean : Remove files created by the build and tests"
68 @echo "distclean : Remove venv directory"
69 @echo "help : Print this help"
Matt Jeanneretf3ad6852019-02-08 18:21:44 -050070 @echo "rebuild-venv : Rebuild local Python virtualenv from scratch"
71 @echo "venv : Build local Python virtualenv if did not exist yet"
Chip Boling67b674a2019-02-08 11:42:18 -060072 @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
90DIRS_CLEAN = $(addsuffix .clean,$(DIRS))
91$(DIRS_CLEAN):
92 @echo " CLEAN $(basename $@)"
93 $(Q)$(MAKE) -C $(basename $@) clean
94
95# Parallel Flake8
96DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS))
97$(DIRS_FLAKE8):
98 @echo " FLAKE8 $(basename $@)"
99 -$(Q)$(MAKE) -C $(basename $@) flake8
100
William Kurkianede82e92019-03-05 13:02:57 -0500101dist: venv
Chip Boling67b674a2019-02-08 11:42:18 -0600102 @ echo "Creating PyPi artifacts"
103 python setup.py sdist
104
105upload: dist
106 @ echo "Uploading PyPi artifacts"
107 twine upload --repository-url https://test.pypi.org/legacy/ dist/*
108 twine upload dist/*
109
Matt Jeanneretf3ad6852019-02-08 18:21:44 -0500110docker_base_img:
111 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}pyvoltha-base:${TAG} -f docker/Dockerfile.base .
112
113docker_image: docker_base_img dist
114 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}pyvoltha:${TAG} -f docker/Dockerfile.pyvoltha .
115
William Kurkianede82e92019-03-05 13:02:57 -0500116test: venv
Chip Boling67b674a2019-02-08 11:42:18 -0600117 @ echo "Executing all unit tests"
Chip Bolingce2daf62019-02-12 13:53:39 -0600118 @ tox -- --with-xunit
Chip Boling67b674a2019-02-08 11:42:18 -0600119
Chip Bolingce2daf62019-02-12 13:53:39 -0600120COVERAGE_OPTS=--with-coverage --with-xunit --cover-branches --cover-html --cover-html-dir=tmp/cover \
121 --cover-package=pyvoltha.adapters,pyvoltha.common
Chip Boling67b674a2019-02-08 11:42:18 -0600122
123utest-with-coverage: venv protos
124 @ echo "Executing all unit tests and producing coverage results"
Chip Bolingce2daf62019-02-12 13:53:39 -0600125 @ tox -- $(COVERAGE_OPTS)
Chip Boling67b674a2019-02-08 11:42:18 -0600126
127clean:
128 find . -name '*.pyc' | xargs rm -f
129 find . -name 'coverage.xml' | xargs rm -f
130 find . -name 'nosetests.xml' | xargs rm -f
Matt Jeanneret6b6d9362019-02-11 10:48:41 -0500131 make -C pyvoltha/protos clean
Chip Bolingce2daf62019-02-12 13:53:39 -0600132 rm -rf pyvoltha.egg-info
Chip Boling67b674a2019-02-08 11:42:18 -0600133 rm -rf dist
Chip Bolingce2daf62019-02-12 13:53:39 -0600134 rm -rf .tox
135 rm -rf test/unit/tmp
Chip Boling67b674a2019-02-08 11:42:18 -0600136
137distclean: clean
138 rm -rf ${VENVDIR}
139
140purge-venv:
141 rm -fr ${VENVDIR}
142
143rebuild-venv: purge-venv venv
144
145venv: ${VENVDIR}/.built
146
147${VENVDIR}/.built:
148 @ $(VENV_BIN) ${VENV_OPTS} ${VENVDIR}
149 @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR}
150 @ . ${VENVDIR}/bin/activate && \
151 pip install --upgrade pip; \
152 if ! pip install -r requirements.txt; \
153 then \
154 echo "On MAC OS X, if the installation failed with an error \n'<openssl/opensslv.h>': file not found,"; \
155 echo "see the BUILD.md file for a workaround"; \
156 else \
157 uname -s > ${VENVDIR}/.built; \
158 fi
159 @ $(VENV_BIN) ${VENV_OPTS} --relocatable ${VENVDIR}
160
161
162flake8: $(DIRS_FLAKE8)
163
164# end file