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 |
| 14 | PYTHON_FILES ?= $(wildcard devices/freedomfi_one.py devices/device_utils.py devices/device_map.py) |
| 15 | |
| 16 | .DEFAULT_GOAL := help |
| 17 | .PHONY: test lint license help |
| 18 | |
| 19 | # Create the virtualenv with all the tools installed |
| 20 | VENV_NAME = venv |
| 21 | |
| 22 | $(VENV_NAME): requirements.txt |
| 23 | $(VIRTUALENV) $@ ;\ |
| 24 | source ./$@/bin/activate ; set -u ;\ |
| 25 | python -m pip install --upgrade pip;\ |
| 26 | python -m pip install -r requirements.txt |
| 27 | echo "To enter virtualenv, run 'source $@/bin/activate'" |
| 28 | |
Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame^] | 29 | install-protoc: ## Get the protobyf from GitHub |
| 30 | curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip -o /opt/protoc.zip ;\ |
| 31 | unzip -o /opt/protoc.zip -d /opt/protobuf ;\ |
| 32 | ln -sf /opt/protobuf/bin/protoc /usr/bin/ |
| 33 | |
| 34 | proto: $(VENV_NAME) ## Compile proto definition of enodebd |
| 35 | source ./$</bin/activate ; set -u ;\ |
| 36 | python tools/gen_protos.py proto_files/orc8r/protos \ |
| 37 | proto_files,proto_files/orc8r/protos/prometheus,/opt/protobuf/include proto_files . ;\ |
| 38 | python tools/gen_protos.py proto_files/lte/protos \ |
| 39 | proto_files,proto_files/orc8r/protos/prometheus,/opt/protobuf/include proto_files . ;\ |
| 40 | python tools/gen_prometheus_proto.py . . |
| 41 | |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 42 | license: $(VENV_NAME) ## Check license with the reuse tool |
| 43 | source ./$</bin/activate ; set -u ;\ |
| 44 | reuse --version ;\ |
| 45 | reuse --root . lint |
| 46 | |
| 47 | test: flake8 pylint black ## run all standard tests |
| 48 | |
| 49 | flake8: $(VENV_NAME) ## check python formatting with flake8 |
| 50 | source ./$</bin/activate ; set -u ;\ |
| 51 | flake8 --version ;\ |
| 52 | flake8 --max-line-length 99 --per-file-ignores="__init__.py:F401" $(PYTHON_FILES) |
| 53 | |
| 54 | pylint: $(VENV_NAME) ## pylint check for python 3 compliance |
| 55 | source ./$</bin/activate ; set -u ;\ |
| 56 | pylint --version ;\ |
| 57 | pylint --rcfile=pylint.ini $(PYTHON_FILES) |
| 58 | |
| 59 | black: $(VENV_NAME) ## run black on python files in check mode |
| 60 | source ./$</bin/activate ; set -u ;\ |
| 61 | black --version ;\ |
| 62 | black --check $(PYTHON_FILES) |
| 63 | |
| 64 | blacken: $(VENV_NAME) ## run black on python files to reformat |
| 65 | source ./$</bin/activate ; set -u ;\ |
| 66 | black --version ;\ |
| 67 | black $(PYTHON_FILES) |
| 68 | |
| 69 | clean: |
| 70 | rm -rf $(VENV_NAME) ansible_collections |
| 71 | |
| 72 | help: ## Print help for each target |
| 73 | @echo enodebd make targets |
| 74 | @echo |
| 75 | @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \ |
| 76 | | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};' |