blob: f24dba6cd4388d869874fb01f38d41140e94ea74 [file] [log] [blame]
Joey Armstrong36592e32022-11-28 09:00:28 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong4de98b72023-02-09 14:51:38 -05003# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong36592e32022-11-28 09:00:28 -05004#
Joey Armstrong4de98b72023-02-09 14:51:38 -05005# Licensed under the Apache License, Version 2.0 (the "License")
Joey Armstrong36592e32022-11-28 09:00:28 -05006# 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 Armstrong4de98b72023-02-09 14:51:38 -050018$(if $(DEBUG),$(warning ENTER))
Joey Armstrong36592e32022-11-28 09:00:28 -050019
Joey Armstrong4de98b72023-02-09 14:51:38 -050020##-------------------##
21##---] GLOBALS [---##
22##-------------------##
23.PHONY: lint-json lint-json-all lint-json-modified
Joey Armstrong36592e32022-11-28 09:00:28 -050024
Joey Armstrong4de98b72023-02-09 14:51:38 -050025have-json-files := $(if $(strip $(JSON_FILES)),true)
26JSON_FILES ?= $(error JSON_FILES= required)
Joey Armstrong36592e32022-11-28 09:00:28 -050027
Joey Armstrong4de98b72023-02-09 14:51:38 -050028## -----------------------------------------------------------------------
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
35## -----------------------------------------------------------------------
36ifndef NO-LINT-JSON
37 lint-json-mode := $(if $(have-json-files),modified,all)
38 lint : lint-json-$(lint-json-mode)
39endif# NO-LINT-JSON
Joey Armstrong36592e32022-11-28 09:00:28 -050040
Joey Armstrong4de98b72023-02-09 14:51:38 -050041## -----------------------------------------------------------------------
42## Intent: exhaustive json syntax checking
43## -----------------------------------------------------------------------
44json-find-args := $(null)
Joey Armstrong644fb652023-10-02 13:12:20 -040045
46## -----------------------------------------------------------------------
47## [TODO] makefile migration enhancement
48## Move switches into makefiles/onf-make/makefiles/lint/json/excl.mk
49## -----------------------------------------------------------------------
50## makefiles/virtualenv/index.mk could also append $(venv-name) to a
51## global directory exclusion list for central maintenance.
52## -----------------------------------------------------------------------
Joey Armstrong4de98b72023-02-09 14:51:38 -050053json-find-args += -name '$(venv-name)'
Joey Armstrong644fb652023-10-02 13:12:20 -040054
55## Migrate into makefiles/local/lint/json/excl.mk
56json-find-args += -o -name '*venv*'
57json-find-args += -o -name '_build'
58
Joey Armstrong4de98b72023-02-09 14:51:38 -050059lint-json-all:
60 $(HIDE)$(MAKE) --no-print-directory lint-json-install
61
62 $(activate)\
63 && find . \( $(json-find-args) \) -prune -o -name '*.json' -print0 \
64 | $(xargs-n1) python -m json.tool > /dev/null ;\
65
66## -----------------------------------------------------------------------
67## Intent: check deps for format and python3 cleanliness
68## Note:
69## json --py3k option no longer supported
70## -----------------------------------------------------------------------
71lint-json-modified: $(venv-activate-script)
72 $(HIDE)$(MAKE) --no-print-directory lint-json-install
73
74 $(activate)\
75 && for jsonfile in $(JSON_FILES); do \
76 echo "Validating json file: $$jsonfile" ;\
77 python -m json.tool $$jsonfile > /dev/null ;\
78 done
79
80## -----------------------------------------------------------------------
81## Intent:
82## -----------------------------------------------------------------------
83.PHONY: lint-json-install
84lint-json-install: $(venv-activate-script)
85 @echo
86 @echo "** -----------------------------------------------------------------------"
87 @echo "** json syntax checking"
88 @echo "** -----------------------------------------------------------------------"
89# $(activate) && pip install --upgrade json.tool
90# $(activate) && python -m json.tool --version (?-howto-?)
91 @echo
92
93## -----------------------------------------------------------------------
94## Intent: Display command usage
95## -----------------------------------------------------------------------
Joey Armstrong36592e32022-11-28 09:00:28 -050096help::
Joey Armstrong4de98b72023-02-09 14:51:38 -050097 @echo ' lint-json Syntax check python using the json command'
98 ifdef VERBOSE
99 @echo ' lint-json-all json checking: exhaustive'
100 @echo ' lint-json-modified json checking: only modified'
101 endif
102
103$(if $(DEBUG),$(warning LEAVE))
Joey Armstrong36592e32022-11-28 09:00:28 -0500104
105# [EOF]