blob: dfed6637ae90795decf8ef625393cdec2695ab9d [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
Matt Jeanneretf3ad6852019-02-08 18:21:44 -050055.PHONY: $(DIRS) $(DIRS_CLEAN) $(DIRS_FLAKE8) flake8 protos 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
Matt Jeanneretf3ad6852019-02-08 18:21:44 -050062 @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"
66 @echo "test : Run all unit test"
67 @echo "clean : Remove files created by the build and tests"
68 @echo "distclean : Remove venv directory"
69 @echo "help : Print this help"
70 @echo "protos : Compile all grpc/protobuf files"
71 @echo "rebuild-venv : Rebuild local Python virtualenv from scratch"
72 @echo "venv : Build local Python virtualenv if did not exist yet"
Chip Boling67b674a2019-02-08 11:42:18 -060073 @echo
74
75## New directories can be added here
76#DIRS:=
77
78## If one directory depends on another directory that
79## dependency can be expressed here
80##
81## For example, if the Tibit directory depended on the eoam
82## directory being built first, then that can be expressed here.
83## driver/tibit: eoam
84
85# Parallel Build
86$(DIRS):
87 @echo " MK $@"
88 $(Q)$(MAKE) -C $@
89
90# Parallel Clean
91DIRS_CLEAN = $(addsuffix .clean,$(DIRS))
92$(DIRS_CLEAN):
93 @echo " CLEAN $(basename $@)"
94 $(Q)$(MAKE) -C $(basename $@) clean
95
96# Parallel Flake8
97DIRS_FLAKE8 = $(addsuffix .flake8,$(DIRS))
98$(DIRS_FLAKE8):
99 @echo " FLAKE8 $(basename $@)"
100 -$(Q)$(MAKE) -C $(basename $@) flake8
101
102build: protos
103
104protos:
105 make -C pyvoltha/protos
106
107dist: venv protos
108 @ echo "Creating PyPi artifacts"
109 python setup.py sdist
110
111upload: dist
112 @ echo "Uploading PyPi artifacts"
113 twine upload --repository-url https://test.pypi.org/legacy/ dist/*
114 twine upload dist/*
115
Matt Jeanneretf3ad6852019-02-08 18:21:44 -0500116docker_base_img:
117 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}pyvoltha-base:${TAG} -f docker/Dockerfile.base .
118
119docker_image: docker_base_img dist
120 docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}pyvoltha:${TAG} -f docker/Dockerfile.pyvoltha .
121
Chip Boling67b674a2019-02-08 11:42:18 -0600122install-protoc:
123 make -C pyvoltha/protos install-protoc
124
125test: venv protos
126 @ echo "Executing all unit tests"
127 @ . ${VENVDIR}/bin/activate && tox
128# @ . ${VENVDIR}/bin/activate && make -C test utest
129
130COVERAGE_OPTS=--with-xcoverage --with-xunit --cover-package=voltha,common,ofagent --cover-html\
131 --cover-html-dir=tmp/cover
132
133utest-with-coverage: venv protos
134 @ echo "Executing all unit tests and producing coverage results"
135 @ . ${VENVDIR}/bin/activate && nosetests $(COVERAGE_OPTS) pyvoltha/tests/utests
136
137clean:
138 find . -name '*.pyc' | xargs rm -f
139 find . -name 'coverage.xml' | xargs rm -f
140 find . -name 'nosetests.xml' | xargs rm -f
141 rm -f pyvoltha/protos/*_pb2.py
142 rm -f pyvoltha/protos/*_pb2_grpc.py
143 rm -f pyvoltha/protos/*.desc
144 rm -rf PyVoltha.egg-info
145 rm -rf dist
146
147distclean: clean
148 rm -rf ${VENVDIR}
149
150purge-venv:
151 rm -fr ${VENVDIR}
152
153rebuild-venv: purge-venv venv
154
155venv: ${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
172flake8: $(DIRS_FLAKE8)
173
174# end file