blob: 34f4bd328ce86e033b19b595ec1ab511a317eb6b [file] [log] [blame]
Zack Williams821c5022020-01-15 15:11:46 -07001# 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
17SHELL := bash -e -o pipefail
18
19WORKSPACE ?= $(HOME)
20VERSION ?= $(shell cat ./VERSION)
21
22# Robot confiig
23ROBOT_FILE ?=
24ROBOT_DIR ?=
25ROBOT_DEBUG_LOG_OPT ?=
26ROBOT_MISC_ARGS ?=
27ROBOT_TEST_TAGS ?= stable
28
29# Robot Job definitions
30siab-robot: ROBOT_FILE := SIAB.robot
31siab-robot: ROBOT_DIR := src/test/cord-api/Tests/WorkflowValidations
32siab-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
33siab-robot: seba-robot
34
35seba-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
41ROBOT_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
50PYTHON_FILES := $(shell find ./src -name *.py -print)
51ROBOT_FILES := $(shell find ./src -name *.robot -print)
52YAML_FILES := $(shell find . -type f \( -name *.yaml -o -name *.yml \) -print)
53JSON_FILES := $(shell find ./src -name *.json -print)
54JENKINSFILES := $(shell find . -type f -name 'Jenkinsfile*' -print)
55
56# virtualenv for the robot tools
57venv_cord:
58 virtualenv -p python3 $@ ;\
59 source ./$@/bin/activate ;\
60 pip install -r requirements.txt ;\
61 pip install -e cord-robot
62
63test: cord-robot-test
64
65cord-robot-test:
66 cd cord-robot; tox
67
68lint: lint-python lint-json lint-yaml # lint-robot lint-jenkins
69
70lint-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
75lint-python: venv_cord
76 source ./$</bin/activate ; set -u ;\
77 pylint --py3k $(PYTHON_FILES) ;\
78 flake8 --max-line-length=119 --count $(PYTHON_FILES)
79
80lint-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
86lint-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
94lint-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
99tidy-robot: venv_cord
100 source ./$</bin/activate ; set -u ;\
101 python -m robot.tidy --inplace $(ROBOT_FILES);
102
103## Variables for gendocs
104TEST_SOURCE := $(wildcard tests/*/*.robot)
105TEST_BASENAME := $(basename $(TEST_SOURCE))
106TEST_DIRS := $(dir $(TEST_SOURCE))
107
108LIB_SOURCE := $(wildcard libraries/*.robot)
109LIB_BASENAME := $(basename $(LIB_SOURCE))
110LIB_DIRS := $(dir $(LIB_SOURCE))
111
112.PHONY: gendocs lint test
113# In future explore use of --docformat REST - integration w/Sphinx?
114gendocs: 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
126clean:
127 find . -name output.xml -print
128
129clean-all: clean
Andy Bavier95032202020-02-26 06:25:56 -0700130 rm -rf venv_cord gendocs cord-robot/CORDRobot/VERSION cord-robot/dist/*
Zack Williams821c5022020-01-15 15:11:46 -0700131