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/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]