blob: f6cf50a141dc4104f100661a25fccc6b060e88dc [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
Matt Jeanneret29989eb2019-03-07 06:40:12 -0500123utest-with-coverage: venv
Chip Boling67b674a2019-02-08 11:42:18 -0600124 @ 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
Chip Bolingce2daf62019-02-12 13:53:39 -0600131 rm -rf pyvoltha.egg-info
Chip Boling67b674a2019-02-08 11:42:18 -0600132 rm -rf dist
Chip Bolingce2daf62019-02-12 13:53:39 -0600133 rm -rf .tox
134 rm -rf test/unit/tmp
Chip Boling67b674a2019-02-08 11:42:18 -0600135
136distclean: clean
137 rm -rf ${VENVDIR}
138
139purge-venv:
140 rm -fr ${VENVDIR}
141
142rebuild-venv: purge-venv venv
143
144venv: ${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
161flake8: $(DIRS_FLAKE8)
162
163# end file