blob: e0d705c992a3692eff29809b68537b01bb49d6aa [file] [log] [blame]
Joey Armstrong0205d332023-04-11 17:29:23 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrongdc04c932024-04-01 12:14:21 -04003# Copyright 2017-2024 Open Networking Foundation Contributors
Joey Armstrong0205d332023-04-11 17:29:23 -04004#
Joey Armstrongdc04c932024-04-01 12:14:21 -04005# Licensed under the Apache License, Version 2.0 (the "License");
Joey Armstrong0205d332023-04-11 17:29:23 -04006# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
Joey Armstrongdc04c932024-04-01 12:14:21 -04009# http:#www.apache.org/licenses/LICENSE-2.0
Joey Armstrong0205d332023-04-11 17:29:23 -040010#
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 Armstrongdc04c932024-04-01 12:14:21 -040017# SPDX-FileCopyrightText: 2017-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20# Intent:
21# -----------------------------------------------------------------------
Joey Armstrong0205d332023-04-11 17:29:23 -040022
23$(if $(DEBUG),$(warning ENTER))
24
25##-------------------##
26##---] GLOBALS [---##
27##-------------------##
28.PHONY: lint-json lint-json-all lint-json-modified
29
30have-json-files := $(if $(strip $(JSON_FILES)),true)
31JSON_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## -----------------------------------------------------------------------
41ifndef NO-LINT-JSON
42 lint-json-mode := $(if $(have-json-files),modified,all)
43 lint : lint-json-$(lint-json-mode)
44endif# NO-LINT-JSON
45
46## -----------------------------------------------------------------------
47## Intent: exhaustive json syntax checking
48## -----------------------------------------------------------------------
49json-find-args := $(null)
50json-find-args += -name '$(venv-name)'
51lint-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## -----------------------------------------------------------------------
63lint-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
76lint-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## -----------------------------------------------------------------------
88help::
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]