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