Makefile edits to improve library lint target support.
Makefile
--------
o Replace inlined includes with single $(MAKEDIR)/include.mk
o virtualenv install w/dependencies handled by makefiles/virtualenv.mk
o Use '&&' for command separation to improve error handling.
o Added more target documentation.
o Re-home doc8/rst syntax checking into makefiles/lint/doc8.mk.
howto/code/linting.rst
----------------------
o Document supported lint targets on docs.voltha.org.
howto/release/index.rst
howto/release/post-release/
howto/release/vcs/
---------------------------
o Document more release related activity (bugfix branch creation)
makefiles/consts.mk
-------------------
o Define and use more library macros.
config.mk
---------
o Per-repository library makefile configuration, disable linting.
makefiles/virtualenv.mk
-----------------------
o Library virtualenv install with dependences.
o Begin using a consistent install directory.
o Ugh: repository (voltha-docs) submodules each install a full venv.
o Install dependency drive based on existence of activate script.
o Lint targets updated to use activate script as a dependency.
o Update activate macro to run: set -u && activate && set +u
makefiles/patches/include.mk
----------------------------
o Update to use virtualenv.mk defined macros.
makefiles/lint/doc8.mk
makefiles/lint/python/flake8.mk
makefiles/lint/json.mk
makefiles/lint/python/pylint.mk
makefiles/lint/robot.mk
makefiles/lint/shell.mk
makefiles/lint/yaml.mk
-------------------------------
o All library linting defines consistent targets and logic.
o Support two library targets: lint-all and lint-modified.
o Default to checking all available sources.
o Linting can be disabled per-repository via {project}/config.mk
Change-Id: I7b7b5e523c867183d44244a0da21cfa3584e9a50
diff --git a/makefiles/consts.mk b/makefiles/consts.mk
index 043ec65..bac4362 100644
--- a/makefiles/consts.mk
+++ b/makefiles/consts.mk
@@ -13,16 +13,40 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+#
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
-null :=#
-space :=$(null) $(null)
-dot :=.
-HIDE ?=@
+$(if $(DEBUG),$(warning ENTER))
-# use bash for pusdh/popd and quick failures.
-# virtual env(s) activate has undefined vars so no -u
-# ^---+ verify this is still true
-export SHELL := bash -e -o pipefail
+# include makefiles/constants.mk
+export dot :=.
+export null :=#
+export space := $(null) $(null)
+export quote-single := $(null)"$(null)#"
+export quote-double := $(null)'$(null)#'
+
+# [DEBUG] make {target} HIDE=
+HIDE ?= @
+
+env-clean ?= /usr/bin/env --ignore-environment
+xargs-n1 := xargs -0 -t -n1 --no-run-if-empty
+xargs-n1-clean := $(env-clean) $(xargs-n1)
+
+## -----------------------------------------------------------------------
+## Default shell:
+## o set -e enable error checking
+## o set -u report undefined errors
+## o set -o pipefail propogate shell pipeline failures.
+## -----------------------------------------------------------------------
+SHELL ?= /bin/bash
+have-shell-bash := $(filter bash,$(subst /,$(space),$(SHELL)))
+$(if $(have-shell-bash),$(null),\
+ $(eval export SHELL := bash -euo pipefail))
+
+export SHELL ?= bash -euo pipefail
+
+$(if $(DEBUG),$(warning LEAVE))
# [EOF]
diff --git a/makefiles/include.mk b/makefiles/include.mk
new file mode 100644
index 0000000..3042488
--- /dev/null
+++ b/makefiles/include.mk
@@ -0,0 +1,41 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+# OPT_ROOT ?= /opt/trainlab/current
+# OPT_MAKEDIR := $(OPT_ROOT)/makefiles
+# MAKEDIR ?= $(OPT_MAKEDIR)
+
+ONF_MAKE ?= $(MAKEDIR)# [TODO] -- local and library makefiles/ needed.
+ONF_MAKE ?= $(error ONF_MAKE= is required)
+
+include $(ONF_MAKE)/consts.mk
+include $(ONF_MAKE)/help/include.mk
+
+include $(ONF_MAKE)/virtualenv.mk# # lint-{jjb,python} depends on venv
+include $(ONF_MAKE)/lint/include.mk
+include $(ONF_MAKE)/todo.mk
+include $(MAKEDIR)/patches/include.mk# # Patch when python 3.10+ in use
+include $(ONF_MAKE)/help/variables.mk
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/lint/doc8.mk b/makefiles/lint/doc8.mk
new file mode 100644
index 0000000..e0594df
--- /dev/null
+++ b/makefiles/lint/doc8.mk
@@ -0,0 +1,79 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2017-2022 Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+.PHONY: lint-doc8 lint-doc8-all lint-doc8-modified
+
+have-rst-files := $(if $(strip $(RST_SOURCE)),true)
+RST_SOURCE ?= $(error RST_SOURCE= is required)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+ifndef NO-LINT-DOC8
+ lint-doc8-mode := $(if $(have-doc8-files),modified,all)
+ lint : lint-doc8-$(lint-doc8-mode)
+endif# NO-LINT-DOC8
+
+# Consistent targets across lint makefiles
+lint-doc8-all : lint-doc8
+lint-doc8-modified : lint-doc8
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+lint-doc8-excl += --ignore-path '$(venv-name)'
+lint-doc8-excl += --ignore-path '$(BUILDDIR)'
+
+# YUCK! -- overhead
+# o Submodule(s) use individual/variant virtualenv install paths.
+# o Exclude special snowflakes to enable library makefile use.
+# o [TODO] Use makefiles/virtualenv.mk to avoid duplication.
+
+lint-doc8-excl += --ignore-path '*/venv_cord'
+lint-doc8-excl += --ignore-path '*/vst_venv'
+
+lint-doc8-excl += --ignore-path './cord-tester'
+lint-doc8-excl += --ignore-path './repos/cord-tester'
+
+lint-doc8-excl += --ignore-path './bbsim/internal/bbsim/responders/sadis/dp.txt'
+lint-doc8-excl += --ignore-path './repos/bbsim/internal/bbsim/responders/sadis/dp.txt'
+lint-doc8-excl += --ignore-path './repos/voltha-helm-charts/voltha-infra/templates/NOTES.txt'
+lint-doc8-excl += --ignore-path './voltha-helm-charts/voltha-infra/templates/NOTES.txt'
+
+lint-doc8-args += --max-line-length 120
+
+lint-doc8: $(venv-activate-script)
+ @echo
+ @echo '** -----------------------------------------------------------------------'
+ @echo '** doc8 *.rst syntax checking'
+ @echo '** -----------------------------------------------------------------------'
+ $(activate) && doc8 --version
+ @echo
+ $(activate) && doc8 $(lint-doc8-excl) $(lint-doc8-args) .
+
+## -----------------------------------------------------------------------
+## Intent: Display command usage
+## -----------------------------------------------------------------------
+help::
+ @echo ' lint-doc8 Syntax check python using the doc8 command'
+ ifdef VERBOSE
+ @echo ' lint-doc8-all doc8 checking: exhaustive'
+ @echo ' lint-doc8-modified doc8 checking: only modified'
+ endif
+
+# [EOF]
diff --git a/makefiles/lint/include.mk b/makefiles/lint/include.mk
index 0f653c9..96f6bce 100644
--- a/makefiles/lint/include.mk
+++ b/makefiles/lint/include.mk
@@ -15,12 +15,29 @@
# limitations under the License.
# -----------------------------------------------------------------------
+# -----------------------------------------------------------------------
+# Intent: Display help banner early before library lint help targets.
+# -----------------------------------------------------------------------
help::
@echo
@echo "[LINT]"
+## Disable python linting in bulk ?
+ifdef NO-LINT-PYTHON
+ NO-LINT-FLAKE8 := true
+ NO-LINT-PYLINT := true
+endif
+
+# Define early else {flake8,pylint}.mk will complain:
+# PYTHON_FILES ?= $(error)
+have-python-files := $(if $(strip $(PYTHON_FILES)),true)
+
+##--------------------##
+##---] INCLUDES [---##
+##--------------------##
+include $(MAKEDIR)/lint/doc8.mk
include $(MAKEDIR)/lint/json.mk
-include $(MAKEDIR)/lint/python.mk
+include $(MAKEDIR)/lint/python/include.mk
include $(MAKEDIR)/lint/robot.mk
include $(MAKEDIR)/lint/shell.mk
include $(MAKEDIR)/lint/yaml.mk
diff --git a/makefiles/lint/json.mk b/makefiles/lint/json.mk
index e67fee1..1deeaba 100644
--- a/makefiles/lint/json.mk
+++ b/makefiles/lint/json.mk
@@ -1,8 +1,8 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2017-2023 Open Networking Foundation
+# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
#
-# Licensed under the Apache License, Version 2.0 (the "License");
+# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -15,21 +15,78 @@
# limitations under the License.
# -----------------------------------------------------------------------
-JSON_FILES ?= $(error JSON_FILES= is rqeuired)
+$(if $(DEBUG),$(warning ENTER))
-.PHONY: lint-json
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+.PHONY: lint-json lint-json-all lint-json-modified
-lint : lint-json
+have-json-files := $(if $(strip $(JSON_FILES)),true)
+JSON_FILES ?= $(error JSON_FILES= required)
-lint-json: vst_venv
- source ./$</bin/activate \
- ; set -u \
- ; for jsonfile in $(JSON_FILES); do \
- echo "Validating json file: $$jsonfile" ;\
- python -m json.tool $$jsonfile > /dev/null ;\
- done
+## -----------------------------------------------------------------------
+## Intent: Use the json command to perform syntax checking.
+## o If UNSTABLE=1 syntax check all sources
+## o else only check sources modified by the developer.
+## Usage:
+## % make lint UNSTABLE=1
+## % make lint-json-all
+## -----------------------------------------------------------------------
+ifndef NO-LINT-JSON
+ lint-json-mode := $(if $(have-json-files),modified,all)
+ lint : lint-json-$(lint-json-mode)
+endif# NO-LINT-JSON
+## -----------------------------------------------------------------------
+## Intent: exhaustive json syntax checking
+## -----------------------------------------------------------------------
+json-find-args := $(null)
+json-find-args += -name '$(venv-name)'
+lint-json-all:
+ $(HIDE)$(MAKE) --no-print-directory lint-json-install
+
+ $(activate)\
+ && find . \( $(json-find-args) \) -prune -o -name '*.json' -print0 \
+ | $(xargs-n1) python -m json.tool > /dev/null ;\
+
+## -----------------------------------------------------------------------
+## Intent: check deps for format and python3 cleanliness
+## Note:
+## json --py3k option no longer supported
+## -----------------------------------------------------------------------
+lint-json-modified: $(venv-activate-script)
+ $(HIDE)$(MAKE) --no-print-directory lint-json-install
+
+ $(activate)\
+ && for jsonfile in $(JSON_FILES); do \
+ echo "Validating json file: $$jsonfile" ;\
+ python -m json.tool $$jsonfile > /dev/null ;\
+ done
+
+## -----------------------------------------------------------------------
+## Intent:
+## -----------------------------------------------------------------------
+.PHONY: lint-json-install
+lint-json-install: $(venv-activate-script)
+ @echo
+ @echo "** -----------------------------------------------------------------------"
+ @echo "** json syntax checking"
+ @echo "** -----------------------------------------------------------------------"
+# $(activate) && pip install --upgrade json.tool
+# $(activate) && python -m json.tool --version (?-howto-?)
+ @echo
+
+## -----------------------------------------------------------------------
+## Intent: Display command usage
+## -----------------------------------------------------------------------
help::
- @echo " lint-json Syntax check json sources"
+ @echo ' lint-json Syntax check python using the json command'
+ ifdef VERBOSE
+ @echo ' lint-json-all json checking: exhaustive'
+ @echo ' lint-json-modified json checking: only modified'
+ endif
+
+$(if $(DEBUG),$(warning LEAVE))
# [EOF]
diff --git a/makefiles/lint/python/flake8.mk b/makefiles/lint/python/flake8.mk
new file mode 100644
index 0000000..bb474a9
--- /dev/null
+++ b/makefiles/lint/python/flake8.mk
@@ -0,0 +1,85 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License")
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+.PHONY: lint-flake8 lint-flake8-all lint-flake8-modified
+
+PYTHON_FILES ?= $(error PYTHON_FILES= required)
+
+## -----------------------------------------------------------------------
+## Intent: Use the flake8 command to perform syntax checking.
+## Usage:
+## % make lint
+## % make lint-flake8-all
+## -----------------------------------------------------------------------
+ifndef NO-LINT-FLAKE8
+ lint-flake8-mode := $(if $(have-python-files),modified,all)
+ lint : lint-flake8-$(lint-flake8-mode)
+endif# NO-LINT-FLAKE8
+
+## -----------------------------------------------------------------------
+## Intent: exhaustive flake8 syntax checking
+## -----------------------------------------------------------------------
+lint-flake8-all: $(venv-activate-script)
+ $(HIDE)$(MAKE) --no-print-directory lint-flake8-install
+
+ $(activate)\
+ && find . \( -name '$(venv-name)' \) -prune -o -name '*.py' -print0 \
+ | $(xargs-n1) flake8 --max-line-length=99 --count
+
+## -----------------------------------------------------------------------
+## Intent: check deps for format and python3 cleanliness
+## Note:
+## pylint --py3k option no longer supported
+## -----------------------------------------------------------------------
+lint-flake8-modified: $(venv-activate-script)
+ $(HIDE)$(MAKE) --no-print-directory lint-flake8-install
+
+ $(activate)\
+ && flake8 --max-line-length=99 --count $(PYTHON_FILES)
+
+## -----------------------------------------------------------------------
+## Intent:
+## -----------------------------------------------------------------------
+.PHONY: lint-flake8-install
+lint-flake8-install: $(venv-activate-script)
+ @echo
+ @echo "** -----------------------------------------------------------------------"
+ @echo "** python flake8 syntax checking"
+ @echo "** -----------------------------------------------------------------------"
+ $(activate) && pip install --upgrade flake8
+ $(activate) && flake8 --version
+ @echo
+
+## -----------------------------------------------------------------------
+## Intent: Display command usage
+## -----------------------------------------------------------------------
+help::
+ @echo ' lint-flake8 Syntax check python using the flake8 command'
+ ifdef VERBOSE
+ @echo ' $(MAKE) lint-pylint PYTHON_FILES=...'
+ @echo ' lint-flake8-modified flake8 checking: only modified'
+ @echo ' lint-flake8-all flake8 checking: exhaustive'
+ endif
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/lint/python.mk b/makefiles/lint/python/include.mk
similarity index 62%
rename from makefiles/lint/python.mk
rename to makefiles/lint/python/include.mk
index d8bdfe0..69811a5 100644
--- a/makefiles/lint/python.mk
+++ b/makefiles/lint/python/include.mk
@@ -1,6 +1,6 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2017-2023 Open Networking Foundation
+# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,20 +15,13 @@
# limitations under the License.
# -----------------------------------------------------------------------
-PYTHON_FILES ?= $(error PYTHON_FILES= is required)
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+$(if $(UNSTABLE),$(eval lint-python-all := true))
-.PHONY: lint-python
-
-lint : lint-python
-
-# check deps for format and python3 cleanliness
-lint-python: vst_venv
- source ./$</bin/activate \
- ; set -u \
- ; pylint --py3k $(PYTHON_FILES) \
- ; flake8 --max-line-length=99 --count $(PYTHON_FILES)
-
-help::
- @echo " lint-python Syntax check using pylint and flake8"
+include $(MAKEDIR)/lint/python/flake8.mk
+include $(MAKEDIR)/lint/python/pylint.mk
+# include $(MAKEDIR)/lint/python/tox.mk
# [EOF]
diff --git a/makefiles/lint/python/pylint.mk b/makefiles/lint/python/pylint.mk
new file mode 100644
index 0000000..9dc1c7c
--- /dev/null
+++ b/makefiles/lint/python/pylint.mk
@@ -0,0 +1,89 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License")
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+.PHONY: lint-pylint lint-pylint-all lint-pylint-modified
+
+PYTHON_FILES ?= $(error PYTHON_FILES= required)
+
+## -----------------------------------------------------------------------
+## Intent: Use the pylint command to perform syntax checking.
+## o If UNSTABLE=1 syntax check all sources
+## o else only check sources modified by the developer.
+## Usage:
+## % make lint UNSTABLE=1
+## % make lint-pylint-all
+## -----------------------------------------------------------------------
+ifndef NO-LINT-PYLINT
+ lint-pylint-mode := $(if $(have-python-files),modified,all)
+ lint : lint-pylint-$(lint-pylint-mode)
+endif# NO-LINT-PYLINT
+
+## -----------------------------------------------------------------------
+## Intent: exhaustive pylint syntax checking
+## -----------------------------------------------------------------------
+pylint-find-args := $(null)
+pylint-find-args += -name '$(venv-name)'
+pylint-find-args += -o -name 'patches'
+lint-pylint-all: $(venv-activate-script)
+ $(MAKE) --no-print-directory lint-pylint-install
+
+ $(activate)\
+ && find . \( $(pylint-find-args) \) -prune -o -name '*.py' -print0 \
+ | $(xargs-n1) pylint
+
+## -----------------------------------------------------------------------
+## Intent: check deps for format and python3 cleanliness
+## Note:
+## pylint --py3k option no longer supported
+## -----------------------------------------------------------------------
+lint-pylint-modified: $(venv-activate-script)
+ $(MAKE) --no-print-directory lint-pylint-install
+
+ $(activate) && pylint $(PYTHON_FILES)
+
+## -----------------------------------------------------------------------
+## Intent:
+## -----------------------------------------------------------------------
+.PHONY: lint-pylint-install
+lint-pylint-install: $(venv-activate-script)
+ @echo
+ @echo "** -----------------------------------------------------------------------"
+ @echo "** python pylint syntax checking"
+ @echo "** -----------------------------------------------------------------------"
+ $(activate) && pip install --upgrade pylint
+ $(activate) && pylint --version
+ @echo
+
+## -----------------------------------------------------------------------
+## Intent: Display command usage
+## -----------------------------------------------------------------------
+help::
+ @echo ' lint-pylint Syntax check python using the pylint command'
+ ifdef VERBOSE
+ @echo ' $(MAKE) lint-pylint PYTHON_FILES=...'
+ @echo ' lint-pylint-modified pylint checking: only modified'
+ @echo ' lint-pylint-all pylint checking: exhaustive'
+ endif
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/lint/robot.mk b/makefiles/lint/robot.mk
index 1c7119f..fa8175c 100644
--- a/makefiles/lint/robot.mk
+++ b/makefiles/lint/robot.mk
@@ -1,8 +1,8 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2017-2023 Open Networking Foundation
+# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
#
-# Licensed under the Apache License, Version 2.0 (the "License");
+# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -15,7 +15,15 @@
# limitations under the License.
# -----------------------------------------------------------------------
-ROBOT_FILES ?= $(error ROBOT_FILES= is required)
+$(if $(DEBUG),$(warning ENTER))
+
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+.PHONY: lint-robot lint-robot-all lint-robot-modified
+
+have-robot-files := $(if $(ROBOT_FILES),true)
+ROBOT_FILES ?= $(error ROBOT_FILES= required)
LINT_ARGS ?= --verbose --configure LineTooLong:130 -e LineTooLong \
--configure TooManyTestSteps:65 -e TooManyTestSteps \
@@ -25,17 +33,62 @@
--configure FileTooLong:2000 -e FileTooLong \
-e TrailingWhitespace
+## -----------------------------------------------------------------------
+## Intent: Use the robot command to perform syntax checking.
+## % make lint
+## % make lint-robot-all
+## % make lint-robot-modified
+## -----------------------------------------------------------------------
+ifndef NO-LINT-ROBOT
+ lint-robot-mode := $(if $(have-robot-files),modified,all)
+ lint : lint-robot-$(lint-robot-mode)
+endif# NO-LINT-ROBOT
-.PHONY: lint-robot
+## -----------------------------------------------------------------------
+## Intent: exhaustive robot syntax checking
+## -----------------------------------------------------------------------
+lint-robot-all:
+ $(HIDE)$(MAKE) --no-print-directory rflint-install
-lint : lint-robot
+ $(activate)\
+ && find . \( -iname '*.robot' \) -print0 \
+ | $(xargs-n1) rflint $(LINT_ARGS)
-lint-robot: vst_venv
- source ./$</bin/activate \
- ; set -u \
- ; rflint $(LINT_ARGS) $(ROBOT_FILES)
+## -----------------------------------------------------------------------
+## Intent: check deps for format and python3 cleanliness
+## Note:
+## robot --py3k option no longer supported
+## -----------------------------------------------------------------------
+lint-robot-modified: $(venv-activate-script)
+ $(HIDE)$(MAKE) --no-print-directory rflint-install
+ $(activate) && rflint $(LINT_ARGS) $(ROBOT_FILES)
+
+## -----------------------------------------------------------------------
+## Intent: Install the rflint command for syntax checking.
+## Note: requirements.txt pip install not used here ATM due to implicit
+## per-repository dependency config to enable checking.
+## -----------------------------------------------------------------------
+rflint-install: $(venv-activate-script)
+ @echo
+ @echo "** -----------------------------------------------------------------------"
+ @echo "** robot syntax checking"
+ @echo "** -----------------------------------------------------------------------"
+ $(activate)\
+ && pip install --upgrade robotframework-lint
+ $(activate) && rflint --version
+ @echo
+
+## -----------------------------------------------------------------------
+## Intent: Display command usage
+## -----------------------------------------------------------------------
help::
- @echo " lint-robot Syntax check robot sources using rflint"
+ @echo ' lint-robot Syntax check python using the robot command'
+ ifdef VERBOSE
+ @echo ' lint-robot-all robot checking: exhaustive'
+ @echo ' lint-robot-modified robot checking: only modified'
+ endif
+
+$(if $(DEBUG),$(warning LEAVE))
# [EOF]
diff --git a/makefiles/lint/shell.mk b/makefiles/lint/shell.mk
index 9923b72..3c04539 100644
--- a/makefiles/lint/shell.mk
+++ b/makefiles/lint/shell.mk
@@ -1,8 +1,8 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2017-2023 Open Networking Foundation
+# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
#
-# Licensed under the Apache License, Version 2.0 (the "License");
+# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -15,19 +15,73 @@
# limitations under the License.
# -----------------------------------------------------------------------
-JSON_FILES ?= $(error JSON_FILES= is required)
+$(if $(DEBUG),$(warning ENTER))
-.PHONY: lint-shell
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+.PHONY: lint-shell lint-shell-all lint-shell-modified
-lint : lint-shell
+have-shell-sources := $(if $(strip $(SHELL_SOURCES)),true)
+SHELL_SOURCES ?= $(error SHELL_SOURCES= required)
-lint-shell:
+## -----------------------------------------------------------------------
+## Intent: Use the shell command to perform syntax checking.
+## % make lint
+## % make lint-shell-all
+## -----------------------------------------------------------------------
+ifndef NO-LINT-SHELL
+ lint-shell-mode := $(if $(have-shell-sources),modified,all)
+ lint : lint-shell-$(lint-shell-mode)
+endif# NO-LINT-SHELL
+
+## -----------------------------------------------------------------------
+## Intent: exhaustive shell syntax checking
+## -----------------------------------------------------------------------
+shellcheck-find-args := $(null)
+shellcheck-find-args += -name '$(venv-name)'
+shellcheck-find-args += -o -name 'staging'
+lint-shell-all:
+ $(MAKE) --no-print-directory lint-shellcheck-install
+
+ find . \( $(shellcheck-find-args) \) -prune -name '*.sh' -print0 \
+ | $(xargs-n1-clean) shellcheck
+
+## -----------------------------------------------------------------------
+## Intent: check deps for format and python3 cleanliness
+## Note:
+## shell --py3k option no longer supported
+## -----------------------------------------------------------------------
+lint-shell-modified:
+ $(MAKE) --no-print-directory lint-shell-install
+
+ shellcheck $(SHELL_SOURCES)
+
+## -----------------------------------------------------------------------
+## Intent:
+## -----------------------------------------------------------------------
+.PHONY: lint-shellcheck-install
+lint-shellcheck-install:
+ @echo
+ @echo "** -----------------------------------------------------------------------"
+ @echo '** command shell syntax checking'
+ @echo "** -----------------------------------------------------------------------"
+
+ # {apt-get,rpm,yum} install shellcheck
shellcheck --version
- find . \( -name 'staging' -o -name 'vst_venv' \) -prune \
- -o -name '*.sh' ! -name 'activate.sh' -print0 \
- | xargs -0 -n1 shellcheck
+ @echo
+## -----------------------------------------------------------------------
+## Intent: Display command usage
+## -----------------------------------------------------------------------
help::
- @echo " lint-shell Syntax check bash,bourne,etc sources"
+ @echo ' lint-shell Syntax check sources using shellcheck'
+ ifdef VERBOSE
+ @echo ' $(MAKE) lint-shell SHELL_SOURCES=...'
+ @echo ' lint-shell-modified shell checking: only modified'
+ @echo ' lint-shell-all shell checking: exhaustive'
+ endif
+
+$(if $(DEBUG),$(warning LEAVE))
# [EOF]
diff --git a/makefiles/lint/yaml.mk b/makefiles/lint/yaml.mk
index c875686..566ac18 100644
--- a/makefiles/lint/yaml.mk
+++ b/makefiles/lint/yaml.mk
@@ -1,8 +1,8 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2017-2023 Open Networking Foundation
+# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
#
-# Licensed under the Apache License, Version 2.0 (the "License");
+# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -15,18 +15,68 @@
# limitations under the License.
# -----------------------------------------------------------------------
-YAML_FILES ?= $(error YAML_FILES= is required)
+$(if $(DEBUG),$(warning ENTER))
-.PHONY: lint-yaml
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+.PHONY: lint-yaml lint-yaml-all lint-yaml-modified
-lint : lint-yaml
+have-yaml-files := $(if $(strip $(YAML_FILES)),true)
+YAML_FILES ?= $(error YAML_FILES= is required)
-lint-yaml: vst_venv
- source ./$</bin/activate \
- ; set -u \
- ; yamllint -s $(YAML_FILES)
+## -----------------------------------------------------------------------
+## Intent: Use the yaml command to perform syntax checking.
+## o If UNSTABLE=1 syntax check all sources
+## o else only check sources modified by the developer.
+## Usage:
+## % make lint UNSTABLE=1
+## % make lint-yaml-all
+## -----------------------------------------------------------------------
+ifndef NO-LINT-YAML
+ lint-yaml-mode := $(if $(have-yaml-files),modified,all)
+ lint : lint-yaml-$(lint-yaml-mode)
+endif# NO-LINT-YAML
+## -----------------------------------------------------------------------
+## Intent: exhaustive yaml syntax checking
+## -----------------------------------------------------------------------
+lint-yaml-all:
+ $(HIDE)$(MAKE) --no-print-directory lint-yaml-install
+
+ find . \( -iname '*.yaml' -o -iname '*.yml' \) -print0 \
+ | $(xargs-n1-clean) yamllint --strict
+
+## -----------------------------------------------------------------------
+## Intent: check deps for format and python3 cleanliness
+## Note:
+## yaml --py3k option no longer supported
+## -----------------------------------------------------------------------
+lint-yaml-modified:
+ $(HIDE)$(MAKE) --no-print-directory lint-yaml-install
+ yamllint -s $(YAML_FILES)
+
+## -----------------------------------------------------------------------
+## Intent:
+## -----------------------------------------------------------------------
+lint-yaml-install:
+ @echo
+ @echo "** -----------------------------------------------------------------------"
+ @echo "** yaml syntax checking"
+ @echo "** -----------------------------------------------------------------------"
+ yamllint --version
+ @echo
+
+## -----------------------------------------------------------------------
+## Intent: Display command usage
+## -----------------------------------------------------------------------
help::
- @echo " lint-yaml Syntax check yaml source using yamllint"
+ @echo ' lint-yaml Syntax check python using the yaml command'
+ ifdef VERBOSE
+ @echo ' lint-yaml-all yaml checking: exhaustive'
+ @echo ' lint-yaml-modified yaml checking: only modified'
+ endif
+
+$(if $(DEBUG),$(warning LEAVE))
# [EOF]
diff --git a/makefiles/patches/include.mk b/makefiles/patches/include.mk
index 2bd1bfd..4accdf2 100644
--- a/makefiles/patches/include.mk
+++ b/makefiles/patches/include.mk
@@ -27,7 +27,9 @@
patch-gather-args += '-e' 'from collections import Mapping'
patch-gather-args += '-e' 'from collections import MutableMapping'
-VENV_NAME ?= $(error $(MAKE) VENV_NAME= is required)
+# Defined by [Mm]akefile or makefiles/virtualenv.mk
+venv-name ?= $(error $(MAKE) venv-name= is required)
+
PATCH_PATH ?= $(error $(MAKE) PATCH_PATH= is required)
## -----------------------------------------------------------------------
@@ -38,7 +40,7 @@
## -----------------------------------------------------------------------
## -----------------------------------------------------------------------
patch-diff:
- $(HIDE)diff -qr staging $(VENV_NAME) \
+ $(HIDE)diff -qr staging $(venv-name) \
| awk '{print "# diff -Naur "$$2" "$$4}' \
| tee $@.log
@@ -46,16 +48,16 @@
## -----------------------------------------------------------------------
patch-create:
mkdir -p patches/$(PATCH_PATH)
- diff -Naur staging/$(PATCH_PATH) $(VENV_NAME)/$(PATCH_PATH) | tee patches/$(PATCH_PATH)/patch
+ diff -Naur staging/$(PATCH_PATH) $(venv-name)/$(PATCH_PATH) | tee patches/$(PATCH_PATH)/patch
exit 1
## -----------------------------------------------------------------------
## -----------------------------------------------------------------------
patch-init:
- find "$(VENV_NAME)" -name '__pycache__' -type d -print0 \
+ find "$(venv-name)" -name '__pycache__' -type d -print0 \
| xargs -I'{}' --null --no-run-if-empty $(RM) -r {}
mkdir -p staging
- rsync -rv --checksum "$(VENV_NAME)/." "staging/."
+ rsync -rv --checksum "$(venv-name)/." "staging/."
@echo "Modify files beneath staging/ to create a patch source"
# [SEE ALSO]
diff --git a/makefiles/todo.mk b/makefiles/todo.mk
new file mode 100644
index 0000000..b122a9e
--- /dev/null
+++ b/makefiles/todo.mk
@@ -0,0 +1,35 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+todo ::
+ @echo '[TODO]'
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help ::
+ @echo ' todo Display future enhancement list.'
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/virtualenv.mk b/makefiles/virtualenv.mk
index d54bfda..bcda734 100644
--- a/makefiles/virtualenv.mk
+++ b/makefiles/virtualenv.mk
@@ -1,6 +1,6 @@
# -*- makefile -*-
## -----------------------------------------------------------------------
-# Copyright 2017-2023 Open Networking Foundation
+# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,18 +15,73 @@
# limitations under the License.
## -----------------------------------------------------------------------
-# virtualenv for the robot tools
-# VOL-2724 Invoke pip via python3 to avoid pathname too long on QA jobs
+$(if $(DEBUG),$(warning ENTER))
-vst_venv-2 : vst_venv/bin/activate requirements.txt
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+.PHONY: venv
-vst_venv/bin/activate: requirements.txt
- virtualenv -p python3 $@
+##------------------##
+##---] LOCALS [---##
+##------------------##
+venv-name ?= .venv# # default install directory
+venv-abs-path := $(PWD)/$(venv-name)
- @echo
- @[ -r requirements.txt ]\
- && { echo "python -m pip install -r requirements.txt"; }\
- && source ./$@/bin/activate\
- && python -m pip install -r requirements.txt
+venv-activate-script := $(venv-name)/bin/activate# # dependency
+
+# Intent: activate= is a macro for accessing the virtualenv activation script#
+# Usage: $(activate) && python
+activate ?= set +u && source $(venv-activate-script) && set -u
+
+## -----------------------------------------------------------------------
+## Intent: Activate script path dependency
+## Usage:
+## o place on the right side of colon as a target dependency
+## o When the script does not exist install the virtual env and display.
+## -----------------------------------------------------------------------
+$(venv-activate-script):
+ @echo
+ @echo "============================="
+ @echo "Installing python virtual env"
+ @echo "============================="
+ virtualenv -p python3 $(venv-name)
+ $(activate) && python -m pip install --upgrade pip
+ $(activate) && pip install --upgrade setuptools
+ $(activate) && { [[ -r requirements.txt ]] && python -m pip install -r requirements.txt; }
+ $(activate) && python --version
+
+ifndef NO_PYTHON_UPGRADE_PATCHING
+ @echo
+ @echo '** -----------------------------------------------------------------------'
+ @echo '** Applying python virtualenv patches as needed (v3.10+)'
+ @echo '** -----------------------------------------------------------------------'
+ ./patches/python_310_migration.sh '--venv' '$(venv-name)' 'apply'
+endif
+
+## -----------------------------------------------------------------------
+## Intent: Explicit named installer target w/o dependencies.
+## Makefile targets should depend on venv-activate-script.
+## -----------------------------------------------------------------------
+venv: $(venv-activate-script)
+
+## -----------------------------------------------------------------------
+## Intent: Revert installation to a clean checkout
+## -----------------------------------------------------------------------
+sterile :: clean
+ $(RM) -r "$(venv-abs-path)"
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help ::
+ @echo
+ @echo '[VIRTUAL ENV]'
+ @echo ' venv Create a python virtual environment'
+ @echo ' venv-name= Subdir name for virtualenv install'
+ @echo ' venv-activate-script make macro name'
+ @echo ' $$(target) dependency install python virtualenv'
+ @echo ' source $$(macro) && cmd configure env and run cmd'
+
+$(if $(DEBUG),$(warning LEAVE))
# [EOF]