blob: 1aeb7c0f906d4d807f910da4083e188c4fd03a37 [file] [log] [blame]
Joey Armstrong0205d332023-04-11 17:29:23 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# -----------------------------------------------------------------------
Joey Armstrong686d3b92023-09-15 17:59:59 -040017# https://gerrit.opencord.org/plugins/gitiles/onf-make
18# ONF.makefile.version = 1.1
19# -----------------------------------------------------------------------
Joey Armstrong0205d332023-04-11 17:29:23 -040020
21##-------------------##
22##---] GLOBALS [---##
23##-------------------##
24
25# Gather sources to check
26# TODO: implement deps, only check modified files
27shell-check-find := find .
28# vendor scripts but they really should be lintable
29shell-check-find += -name 'vendor' -prune
30shell-check-find += -o \( -name '*.sh' \)
31shell-check-find += -type f -print0
32
Joey Armstrong686d3b92023-09-15 17:59:59 -040033shell-check := $(env-clean) shellcheck
34# shell-check := shellcheck
Joey Armstrong0205d332023-04-11 17:29:23 -040035
Joey Armstrong686d3b92023-09-15 17:59:59 -040036shell-check-args += --check-sourced
37shell-check-args += --external-sources
Joey Armstrong0205d332023-04-11 17:29:23 -040038
39##-------------------##
40##---] TARGETS [---##
41##-------------------##
42ifndef NO-LINT-SHELL
43 lint : lint-shell
44endif
45
46## -----------------------------------------------------------------------
Joey Armstrong686d3b92023-09-15 17:59:59 -040047## All or on-demand
48## -----------------------------------------------------------------------
49ifdef LINT_SRC
50 lint-shell : lint-shell-src
51else
52 lint-shell : lint-shell-all
53endif
54
55## -----------------------------------------------------------------------
Joey Armstrong0205d332023-04-11 17:29:23 -040056## Intent: Perform a lint check on command line script sources
57## -----------------------------------------------------------------------
Joey Armstrong686d3b92023-09-15 17:59:59 -040058lint-shell-all:
Joey Armstrong0205d332023-04-11 17:29:23 -040059 $(shell-check) -V
60 @echo
61 $(HIDE)$(env-clean) $(shell-check-find) \
62 | $(xargs-n1) $(shell-check) $(shell-check-args)
63
64## -----------------------------------------------------------------------
Joey Armstrong686d3b92023-09-15 17:59:59 -040065## Intent: On-demand lint checking
66## -----------------------------------------------------------------------
67lint-shell-src:
68 ifndef SHELL_SRC
69 @echo "ERROR: Usage: $(MAKE) $@ SHELL_SRC="
70 @exit 1
71 endif
72 $(shell-check) --version
73 @echo
74 $(HIDE) $(shell-check) $(shell-check-args) $(SHELL_SRC)
75
76## -----------------------------------------------------------------------
77## Intent: Perform lint check on a named list of files
78## -----------------------------------------------------------------------
79# git show --diff-filter=AM --pretty="format:" --name-only #{commitId}
80# lint-shell-bygit = $(shell git diff --name-only HEAD | grep '\.sh')
81lint-shell-bygit = $(git status -s | grep '\.sh' | grep -v -e '^D' -e '^?' | cut -c4-)
82
83# $(error lint-shell-bygit = $(lint-shell-bygit))
84lint-shell-mod:
85 $(shell-check) --version
86 @echo
87 $(foreach fyl,$(lint-shell-bygit),$(shell-check) $(shell-check-args) $(fyl))
88
89## -----------------------------------------------------------------------
Joey Armstrong0205d332023-04-11 17:29:23 -040090## Intent: Display command help
91## -----------------------------------------------------------------------
92help-summary ::
Joey Armstrong686d3b92023-09-15 17:59:59 -040093 @echo ' lint-shell Conditionally lint shell source'
94 ifdef VERBOSE
95 @echo ' lint-shell-all Lint all available sources'
96 @echo ' lint-shell-mod Lint locally modified (git status)'
97 @echo ' lint-shell-src Lint individually (BY_SRC=list-of-files)'
98 endif
99
100# [SEE ALSO]
101# -----------------------------------------------------------------------
102# o https://www.shellcheck.net/wiki/Directive
Joey Armstrong0205d332023-04-11 17:29:23 -0400103
Joey Armstrong0205d332023-04-11 17:29:23 -0400104# [EOF]