Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | 518f357 | 2024-02-11 07:56:25 -0500 | [diff] [blame] | 3 | # Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 4 | # |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 5 | # Licensed under the Apache License, Version 2.0 (the "License") |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 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 | # ----------------------------------------------------------------------- |
| 17 | |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 18 | $(if $(DEBUG),$(warning ENTER)) |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 19 | |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 20 | ##-------------------## |
| 21 | ##---] GLOBALS [---## |
| 22 | ##-------------------## |
| 23 | .PHONY: lint-json lint-json-all lint-json-modified |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 24 | |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 25 | have-json-files := $(if $(strip $(JSON_FILES)),true) |
| 26 | JSON_FILES ?= $(error JSON_FILES= required) |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 27 | |
| 28 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 29 | ## Intent: Use the json command to perform syntax checking. |
| 30 | ## o If UNSTABLE=1 syntax check all sources |
| 31 | ## o else only check sources modified by the developer. |
| 32 | ## Usage: |
| 33 | ## % make lint UNSTABLE=1 |
| 34 | ## % make lint-json-all |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 35 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 36 | ifndef NO-LINT-JSON |
| 37 | lint-json-mode := $(if $(have-json-files),modified,all) |
| 38 | lint : lint-json-$(lint-json-mode) |
| 39 | endif# NO-LINT-JSON |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 40 | |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 41 | ## ----------------------------------------------------------------------- |
| 42 | ## Intent: exhaustive json syntax checking |
| 43 | ## ----------------------------------------------------------------------- |
| 44 | json-find-args := $(null) |
| 45 | json-find-args += -name '$(venv-name)' |
| 46 | lint-json-all: |
| 47 | $(HIDE)$(MAKE) --no-print-directory lint-json-install |
| 48 | |
| 49 | $(activate)\ |
| 50 | && find . \( $(json-find-args) \) -prune -o -name '*.json' -print0 \ |
| 51 | | $(xargs-n1) python -m json.tool > /dev/null ;\ |
| 52 | |
| 53 | ## ----------------------------------------------------------------------- |
| 54 | ## Intent: check deps for format and python3 cleanliness |
| 55 | ## Note: |
| 56 | ## json --py3k option no longer supported |
| 57 | ## ----------------------------------------------------------------------- |
| 58 | lint-json-modified: $(venv-activate-script) |
| 59 | $(HIDE)$(MAKE) --no-print-directory lint-json-install |
| 60 | |
| 61 | $(activate)\ |
| 62 | && for jsonfile in $(JSON_FILES); do \ |
| 63 | echo "Validating json file: $$jsonfile" ;\ |
| 64 | python -m json.tool $$jsonfile > /dev/null ;\ |
| 65 | done |
| 66 | |
| 67 | ## ----------------------------------------------------------------------- |
| 68 | ## Intent: |
| 69 | ## ----------------------------------------------------------------------- |
| 70 | .PHONY: lint-json-install |
| 71 | lint-json-install: $(venv-activate-script) |
| 72 | @echo |
| 73 | @echo "** -----------------------------------------------------------------------" |
| 74 | @echo "** json syntax checking" |
| 75 | @echo "** -----------------------------------------------------------------------" |
| 76 | # $(activate) && pip install --upgrade json.tool |
| 77 | # $(activate) && python -m json.tool --version (?-howto-?) |
| 78 | @echo |
| 79 | |
| 80 | ## ----------------------------------------------------------------------- |
| 81 | ## Intent: Display command usage |
| 82 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 83 | help:: |
Joey Armstrong | 980e37f | 2023-02-28 18:57:41 -0500 | [diff] [blame] | 84 | @echo ' lint-json Syntax check python using the json command' |
| 85 | ifdef VERBOSE |
| 86 | @echo ' lint-json-all json checking: exhaustive' |
| 87 | @echo ' lint-json-modified json checking: only modified' |
| 88 | endif |
| 89 | |
| 90 | $(if $(DEBUG),$(warning LEAVE)) |
Joey Armstrong | 28eddda | 2023-01-10 03:09:34 -0500 | [diff] [blame] | 91 | |
| 92 | # [EOF] |