Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 1 | # -*- 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 Armstrong | 686d3b9 | 2023-09-15 17:59:59 -0400 | [diff] [blame] | 17 | # https://gerrit.opencord.org/plugins/gitiles/onf-make |
| 18 | # ONF.makefile.version = 1.1 |
| 19 | # ----------------------------------------------------------------------- |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 20 | |
| 21 | ##-------------------## |
| 22 | ##---] GLOBALS [---## |
| 23 | ##-------------------## |
| 24 | |
| 25 | # Gather sources to check |
| 26 | # TODO: implement deps, only check modified files |
| 27 | shell-check-find := find . |
| 28 | # vendor scripts but they really should be lintable |
| 29 | shell-check-find += -name 'vendor' -prune |
| 30 | shell-check-find += -o \( -name '*.sh' \) |
| 31 | shell-check-find += -type f -print0 |
| 32 | |
Joey Armstrong | 686d3b9 | 2023-09-15 17:59:59 -0400 | [diff] [blame] | 33 | shell-check := $(env-clean) shellcheck |
| 34 | # shell-check := shellcheck |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 35 | |
Joey Armstrong | 686d3b9 | 2023-09-15 17:59:59 -0400 | [diff] [blame] | 36 | shell-check-args += --check-sourced |
| 37 | shell-check-args += --external-sources |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 38 | |
| 39 | ##-------------------## |
| 40 | ##---] TARGETS [---## |
| 41 | ##-------------------## |
| 42 | ifndef NO-LINT-SHELL |
| 43 | lint : lint-shell |
| 44 | endif |
| 45 | |
| 46 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 686d3b9 | 2023-09-15 17:59:59 -0400 | [diff] [blame] | 47 | ## All or on-demand |
| 48 | ## ----------------------------------------------------------------------- |
| 49 | ifdef LINT_SRC |
| 50 | lint-shell : lint-shell-src |
| 51 | else |
| 52 | lint-shell : lint-shell-all |
| 53 | endif |
| 54 | |
| 55 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 56 | ## Intent: Perform a lint check on command line script sources |
| 57 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 686d3b9 | 2023-09-15 17:59:59 -0400 | [diff] [blame] | 58 | lint-shell-all: |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 59 | $(shell-check) -V |
| 60 | @echo |
| 61 | $(HIDE)$(env-clean) $(shell-check-find) \ |
| 62 | | $(xargs-n1) $(shell-check) $(shell-check-args) |
| 63 | |
| 64 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 686d3b9 | 2023-09-15 17:59:59 -0400 | [diff] [blame] | 65 | ## Intent: On-demand lint checking |
| 66 | ## ----------------------------------------------------------------------- |
| 67 | lint-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') |
| 81 | lint-shell-bygit = $(git status -s | grep '\.sh' | grep -v -e '^D' -e '^?' | cut -c4-) |
| 82 | |
| 83 | # $(error lint-shell-bygit = $(lint-shell-bygit)) |
| 84 | lint-shell-mod: |
| 85 | $(shell-check) --version |
| 86 | @echo |
| 87 | $(foreach fyl,$(lint-shell-bygit),$(shell-check) $(shell-check-args) $(fyl)) |
| 88 | |
| 89 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 90 | ## Intent: Display command help |
| 91 | ## ----------------------------------------------------------------------- |
| 92 | help-summary :: |
Joey Armstrong | 686d3b9 | 2023-09-15 17:59:59 -0400 | [diff] [blame] | 93 | @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 Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 103 | |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 104 | # [EOF] |