blob: 8f65d9d819e72aa51716e6c185eab66659cf0560 [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001# ONF enodebd Makefile
2#
3# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
4# SPDX-License-Identifier: Apache-2.0
5
6# Use bash for pushd/popd, and to fail quickly.
7# No -u as virtualenv activate script has undefined vars
8SHELL = bash -e -o pipefail
9
10# tooling
11VIRTUALENV ?= python3 -m venv
12
13# all files with extensions
Wei-Yu Chenb91af852022-03-15 22:24:49 +080014PYTHON_FILES ?= $(wildcard devices/sercomm.py devices/device_utils.py devices/device_map.py)
Wei-Yu Chen49950b92021-11-08 19:19:18 +080015
16.DEFAULT_GOAL := help
17.PHONY: test lint license help
18
Wei-Yu Chenb91af852022-03-15 22:24:49 +080019# Variables
20VERSION ?= $(shell cat VERSION)
21VENV_NAME := venv
22
23# Docker related
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_BUILD_ARGS ?=
27DOCKER_TAG ?= ${VERSION}
28ADAPTER_IMAGENAME ?= ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}enodebd:${DOCKER_TAG}
29
30# The default target in the Makefile
31help:
32 @echo "Usage: make [<target>]"
33 @echo "where available targets are:"
34 @echo
35 @echo "help : Print this help"
36 @echo "all : Build the runtime environment in local machine"
37 @echo "docker-build : Build the enodebd docker image"
38 @echo "test : Run enodebd coding style tests"
39
40
41docker-build:
42 docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME} .
43
44docker-push:
45 docker push ${ADAPTER_IMAGENAME}
46
47# The complete building procedure
48all: venv install-protoc proto
Wei-Yu Chen49950b92021-11-08 19:19:18 +080049
50$(VENV_NAME): requirements.txt
51 $(VIRTUALENV) $@ ;\
Wei-Yu Chenb91af852022-03-15 22:24:49 +080052 source ./$@/bin/activate ; set -u ;\
53 python -m pip install --upgrade pip;\
54 python -m pip install -r requirements.txt
Wei-Yu Chen49950b92021-11-08 19:19:18 +080055 echo "To enter virtualenv, run 'source $@/bin/activate'"
56
Wei-Yu Chenad55cb82022-02-15 20:07:01 +080057install-protoc: ## Get the protobyf from GitHub
58 curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip -o /opt/protoc.zip ;\
Wei-Yu Chenb91af852022-03-15 22:24:49 +080059 unzip -o /opt/protoc.zip -d /opt/protobuf ;\
60 ln -sf /opt/protobuf/bin/protoc /usr/bin/
Wei-Yu Chenad55cb82022-02-15 20:07:01 +080061
62proto: $(VENV_NAME) ## Compile proto definition of enodebd
63 source ./$</bin/activate ; set -u ;\
Wei-Yu Chenb91af852022-03-15 22:24:49 +080064 python tools/gen_protos.py proto_files/orc8r/protos \
65 proto_files,proto_files/orc8r/protos/prometheus,/opt/protobuf/include proto_files . ;\
66 python tools/gen_protos.py proto_files/lte/protos \
67 proto_files,proto_files/orc8r/protos/prometheus,/opt/protobuf/include proto_files . ;\
68 python tools/gen_prometheus_proto.py . .
Wei-Yu Chenad55cb82022-02-15 20:07:01 +080069
Wei-Yu Chen49950b92021-11-08 19:19:18 +080070license: $(VENV_NAME) ## Check license with the reuse tool
71 source ./$</bin/activate ; set -u ;\
Wei-Yu Chenb91af852022-03-15 22:24:49 +080072 reuse --version ;\
73 reuse --root . lint
Wei-Yu Chen49950b92021-11-08 19:19:18 +080074
Wei-Yu Chenb91af852022-03-15 22:24:49 +080075# Linting / Testing
Wei-Yu Chen49950b92021-11-08 19:19:18 +080076test: flake8 pylint black ## run all standard tests
77
78flake8: $(VENV_NAME) ## check python formatting with flake8
79 source ./$</bin/activate ; set -u ;\
Wei-Yu Chenb91af852022-03-15 22:24:49 +080080 flake8 --version ;\
81 flake8 --max-line-length 99 --per-file-ignores="__init__.py:F401" $(PYTHON_FILES)
Wei-Yu Chen49950b92021-11-08 19:19:18 +080082
83pylint: $(VENV_NAME) ## pylint check for python 3 compliance
84 source ./$</bin/activate ; set -u ;\
Wei-Yu Chenb91af852022-03-15 22:24:49 +080085 pylint --version ;\
86 pylint --rcfile=pylint.ini $(PYTHON_FILES)
Wei-Yu Chen49950b92021-11-08 19:19:18 +080087
88black: $(VENV_NAME) ## run black on python files in check mode
89 source ./$</bin/activate ; set -u ;\
Wei-Yu Chenb91af852022-03-15 22:24:49 +080090 black --version ;\
91 black --check $(PYTHON_FILES)
Wei-Yu Chen49950b92021-11-08 19:19:18 +080092
93blacken: $(VENV_NAME) ## run black on python files to reformat
94 source ./$</bin/activate ; set -u ;\
Wei-Yu Chenb91af852022-03-15 22:24:49 +080095 black --version ;\
96 black $(PYTHON_FILES)
Wei-Yu Chen49950b92021-11-08 19:19:18 +080097
Wei-Yu Chen49950b92021-11-08 19:19:18 +080098