blob: b50ebcb721df26fe3bf3ef292cebadded27366c0 [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)
Joey Armstrongccab2cf2024-04-06 18:00:59 -040050json-find-args += $(foreach dir,$(onf-excl-dirs),-not -path './$(dir)/*')
51
Joey Armstrong0205d332023-04-11 17:29:23 -040052lint-json-all:
53 $(HIDE)$(MAKE) --no-print-directory lint-json-install
54
55 $(activate)\
Joey Armstrongccab2cf2024-04-06 18:00:59 -040056 && find . $(json-find-args) -name '*.json' -print0 \
Joey Armstrong0205d332023-04-11 17:29:23 -040057 | $(xargs-n1) python -m json.tool > /dev/null ;\
58
59## -----------------------------------------------------------------------
60## Intent: check deps for format and python3 cleanliness
61## Note:
62## json --py3k option no longer supported
63## -----------------------------------------------------------------------
64lint-json-modified: $(venv-activate-script)
65 $(HIDE)$(MAKE) --no-print-directory lint-json-install
66
67 $(activate)\
68 && for jsonfile in $(JSON_FILES); do \
69 echo "Validating json file: $$jsonfile" ;\
70 python -m json.tool $$jsonfile > /dev/null ;\
71 done
72
73## -----------------------------------------------------------------------
74## Intent:
75## -----------------------------------------------------------------------
76.PHONY: lint-json-install
77lint-json-install: $(venv-activate-script)
78 @echo
79 @echo "** -----------------------------------------------------------------------"
80 @echo "** json syntax checking"
81 @echo "** -----------------------------------------------------------------------"
82# $(activate) && pip install --upgrade json.tool
83# $(activate) && python -m json.tool --version (?-howto-?)
84 @echo
85
86## -----------------------------------------------------------------------
87## Intent: Display command usage
88## -----------------------------------------------------------------------
89help::
90 @echo ' lint-json Syntax check python using the json command'
91 ifdef VERBOSE
92 @echo ' lint-json-all json checking: exhaustive'
93 @echo ' lint-json-modified json checking: only modified'
94 endif
95
96$(if $(DEBUG),$(warning LEAVE))
97
98# [EOF]