Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame^] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | # use bash for pushd/popd, and to fail quickly. virtualenv's activate |
| 16 | # has undefined variables, so no -u |
| 17 | SHELL := bash -e -o pipefail |
| 18 | |
| 19 | WORKSPACE ?= $(HOME) |
| 20 | VERSION ?= $(shell cat ./VERSION) |
| 21 | |
| 22 | # Robot confiig |
| 23 | ROBOT_FILE ?= |
| 24 | ROBOT_DIR ?= |
| 25 | ROBOT_DEBUG_LOG_OPT ?= |
| 26 | ROBOT_MISC_ARGS ?= |
| 27 | ROBOT_TEST_TAGS ?= stable |
| 28 | |
| 29 | # Robot Job definitions |
| 30 | siab-robot: ROBOT_FILE := SIAB.robot |
| 31 | siab-robot: ROBOT_DIR := src/test/cord-api/Tests/WorkflowValidations |
| 32 | siab-robot: ROBOT_MISC_ARGS += --removekeywords wuks -e notready $(ROBOT_DEBUG_LOG_OPT) -i $(ROBOT_TEST_TAGS) -v VOLTHA_DIR:$(WORKSPACE)/cord/incubator/voltha -v SUBSCRIBER_FILENAME:SIABSubscriberLatest -v WHITELIST_FILENAME:SIABWhitelistLatest -v OLT_DEVICE_FILENAME:SIABOLT0Device |
| 33 | siab-robot: seba-robot |
| 34 | |
| 35 | seba-robot: venv_cord |
| 36 | source ./$</bin/activate ; set -u ;\ |
| 37 | cd $(ROBOT_DIR) ;\ |
| 38 | robot -V $(ROBOT_FILE) $(ROBOT_MISC_ARGS) |
| 39 | |
| 40 | # self-test, lint, and setup targets |
| 41 | ROBOT_LINT_ARGS ?= --verbose \ |
| 42 | --configure LineTooLong:120 -e LineTooLong \ |
| 43 | -e TooManyTestSteps \ |
| 44 | -e TooManyTestCases \ |
| 45 | --configure TooFewTestSteps:1 \ |
| 46 | --configure TooFewKeywordSteps:1 \ |
| 47 | -e FileTooLong \ |
| 48 | -e TrailingWhitespace |
| 49 | |
| 50 | PYTHON_FILES := $(shell find ./src -name *.py -print) |
| 51 | ROBOT_FILES := $(shell find ./src -name *.robot -print) |
| 52 | YAML_FILES := $(shell find . -type f \( -name *.yaml -o -name *.yml \) -print) |
| 53 | JSON_FILES := $(shell find ./src -name *.json -print) |
| 54 | JENKINSFILES := $(shell find . -type f -name 'Jenkinsfile*' -print) |
| 55 | |
| 56 | # virtualenv for the robot tools |
| 57 | venv_cord: |
| 58 | virtualenv -p python3 $@ ;\ |
| 59 | source ./$@/bin/activate ;\ |
| 60 | pip install -r requirements.txt ;\ |
| 61 | pip install -e cord-robot |
| 62 | |
| 63 | test: cord-robot-test |
| 64 | |
| 65 | cord-robot-test: |
| 66 | cd cord-robot; tox |
| 67 | |
| 68 | lint: lint-python lint-json lint-yaml # lint-robot lint-jenkins |
| 69 | |
| 70 | lint-robot: venv_cord |
| 71 | source ./$</bin/activate ; set -u ;\ |
| 72 | rflint $(ROBOT_LINT_ARGS) $(ROBOT_FILES) |
| 73 | |
| 74 | # check deps for format and python3 cleanliness |
| 75 | lint-python: venv_cord |
| 76 | source ./$</bin/activate ; set -u ;\ |
| 77 | pylint --py3k $(PYTHON_FILES) ;\ |
| 78 | flake8 --max-line-length=119 --count $(PYTHON_FILES) |
| 79 | |
| 80 | lint-yaml: venv_cord |
| 81 | source ./$</bin/activate ; set -u ;\ |
| 82 | yamllint \ |
| 83 | -d "{extends: default, rules: {line-length: {max: 119}}}" \ |
| 84 | -s $(YAML_FILES) |
| 85 | |
| 86 | lint-json: venv_cord |
| 87 | source ./$</bin/activate ; set -u ;\ |
| 88 | for jsonfile in $(JSON_FILES); do \ |
| 89 | echo "Validating json file: $$jsonfile" ;\ |
| 90 | python -m json.tool $$jsonfile > /dev/null ;\ |
| 91 | done |
| 92 | |
| 93 | # only works on declarative pipeline Jenkinsfiles |
| 94 | lint-jenkins: |
| 95 | ./scripts/jflint.sh $(JENKINSFILES) |
| 96 | |
| 97 | # tidy target will be more useful once issue with removing leading comments |
| 98 | # is resolved: https://github.com/robotframework/robotframework/issues/3263 |
| 99 | tidy-robot: venv_cord |
| 100 | source ./$</bin/activate ; set -u ;\ |
| 101 | python -m robot.tidy --inplace $(ROBOT_FILES); |
| 102 | |
| 103 | ## Variables for gendocs |
| 104 | TEST_SOURCE := $(wildcard tests/*/*.robot) |
| 105 | TEST_BASENAME := $(basename $(TEST_SOURCE)) |
| 106 | TEST_DIRS := $(dir $(TEST_SOURCE)) |
| 107 | |
| 108 | LIB_SOURCE := $(wildcard libraries/*.robot) |
| 109 | LIB_BASENAME := $(basename $(LIB_SOURCE)) |
| 110 | LIB_DIRS := $(dir $(LIB_SOURCE)) |
| 111 | |
| 112 | .PHONY: gendocs lint test |
| 113 | # In future explore use of --docformat REST - integration w/Sphinx? |
| 114 | gendocs: venv_cord |
| 115 | source ./$</bin/activate ; set -u ;\ |
| 116 | mkdir -p $@ ;\ |
| 117 | for dir in ${LIB_DIRS}; do mkdir -p $@/$$dir; done;\ |
| 118 | for dir in ${LIB_BASENAME}; do\ |
| 119 | python -m robot.libdoc --format HTML $$dir.robot $@/$$dir.html ;\ |
| 120 | done ;\ |
| 121 | for dir in ${TEST_DIRS}; do mkdir -p $@/$$dir; done;\ |
| 122 | for dir in ${TEST_BASENAME}; do\ |
| 123 | python -m robot.testdoc $$dir.robot $@/$$dir.html ;\ |
| 124 | done |
| 125 | |
| 126 | clean: |
| 127 | find . -name output.xml -print |
| 128 | |
| 129 | clean-all: clean |
| 130 | rm -rf venv_cord gendocs cord-robot/CORDRobot/VERSION |
| 131 | |