Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 1 | # 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 |
| 8 | SHELL = bash -e -o pipefail |
| 9 | |
| 10 | # tooling |
| 11 | VIRTUALENV ?= python3 -m venv |
| 12 | |
| 13 | # all files with extensions |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 14 | PYTHON_FILES ?= $(wildcard devices/sercomm.py devices/device_utils.py devices/device_map.py) |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 15 | |
| 16 | .DEFAULT_GOAL := help |
| 17 | .PHONY: test lint license help |
| 18 | |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 19 | # Variables |
| 20 | VERSION ?= $(shell cat VERSION) |
| 21 | VENV_NAME := venv |
| 22 | |
| 23 | # Docker related |
| 24 | DOCKER_REGISTRY ?= |
| 25 | DOCKER_REPOSITORY ?= |
| 26 | DOCKER_BUILD_ARGS ?= |
| 27 | DOCKER_TAG ?= ${VERSION} |
| 28 | ADAPTER_IMAGENAME ?= ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}enodebd:${DOCKER_TAG} |
| 29 | |
| 30 | # The default target in the Makefile |
| 31 | help: |
| 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 | |
| 41 | docker-build: |
| 42 | docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME} . |
| 43 | |
| 44 | docker-push: |
| 45 | docker push ${ADAPTER_IMAGENAME} |
| 46 | |
| 47 | # The complete building procedure |
| 48 | all: venv install-protoc proto |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 49 | |
| 50 | $(VENV_NAME): requirements.txt |
| 51 | $(VIRTUALENV) $@ ;\ |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 52 | source ./$@/bin/activate ; set -u ;\ |
| 53 | python -m pip install --upgrade pip;\ |
| 54 | python -m pip install -r requirements.txt |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 55 | echo "To enter virtualenv, run 'source $@/bin/activate'" |
| 56 | |
Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame] | 57 | install-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 Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 59 | unzip -o /opt/protoc.zip -d /opt/protobuf ;\ |
| 60 | ln -sf /opt/protobuf/bin/protoc /usr/bin/ |
Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame] | 61 | |
| 62 | proto: $(VENV_NAME) ## Compile proto definition of enodebd |
| 63 | source ./$</bin/activate ; set -u ;\ |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 64 | 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 Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame] | 69 | |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 70 | license: $(VENV_NAME) ## Check license with the reuse tool |
| 71 | source ./$</bin/activate ; set -u ;\ |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 72 | reuse --version ;\ |
| 73 | reuse --root . lint |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 74 | |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 75 | # Linting / Testing |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 76 | test: flake8 pylint black ## run all standard tests |
| 77 | |
| 78 | flake8: $(VENV_NAME) ## check python formatting with flake8 |
| 79 | source ./$</bin/activate ; set -u ;\ |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 80 | flake8 --version ;\ |
| 81 | flake8 --max-line-length 99 --per-file-ignores="__init__.py:F401" $(PYTHON_FILES) |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 82 | |
| 83 | pylint: $(VENV_NAME) ## pylint check for python 3 compliance |
| 84 | source ./$</bin/activate ; set -u ;\ |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 85 | pylint --version ;\ |
| 86 | pylint --rcfile=pylint.ini $(PYTHON_FILES) |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 87 | |
| 88 | black: $(VENV_NAME) ## run black on python files in check mode |
| 89 | source ./$</bin/activate ; set -u ;\ |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 90 | black --version ;\ |
| 91 | black --check $(PYTHON_FILES) |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 92 | |
| 93 | blacken: $(VENV_NAME) ## run black on python files to reformat |
| 94 | source ./$</bin/activate ; set -u ;\ |
Wei-Yu Chen | b91af85 | 2022-03-15 22:24:49 +0800 | [diff] [blame^] | 95 | black --version ;\ |
| 96 | black $(PYTHON_FILES) |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 97 | |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 98 | |