blob: ab5b9d6540dccc8f32cf6a7d184da2e799c1adca [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-yaml lint-yaml-all lint-yaml-modified
Joey Armstrong36592e32022-11-28 09:00:28 -050024
Joey Armstrong4de98b72023-02-09 14:51:38 -050025have-yaml-files := $(if $(strip $(YAML_FILES)),true)
26YAML_FILES ?= $(error YAML_FILES= is required)
Joey Armstrong36592e32022-11-28 09:00:28 -050027
Joey Armstrong4de98b72023-02-09 14:51:38 -050028## -----------------------------------------------------------------------
29## Intent: Use the yaml 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-yaml-all
35## -----------------------------------------------------------------------
Joey Armstrong449ce7a2023-07-18 18:32:24 -040036lint-yaml-mode := $(if $(have-yaml-files),modified,all)
37lint-yaml : lint-yaml-$(lint-yaml-mode)
38
Joey Armstrong4de98b72023-02-09 14:51:38 -050039ifndef NO-LINT-YAML
Joey Armstrong449ce7a2023-07-18 18:32:24 -040040 lint : lint-yaml# # Enable as a default lint target
Joey Armstrong4de98b72023-02-09 14:51:38 -050041endif# NO-LINT-YAML
Joey Armstrong36592e32022-11-28 09:00:28 -050042
Joey Armstrong4de98b72023-02-09 14:51:38 -050043## -----------------------------------------------------------------------
44## Intent: exhaustive yaml syntax checking
45## -----------------------------------------------------------------------
46lint-yaml-all:
47 $(HIDE)$(MAKE) --no-print-directory lint-yaml-install
48
49 find . \( -iname '*.yaml' -o -iname '*.yml' \) -print0 \
50 | $(xargs-n1-clean) yamllint --strict
51
52## -----------------------------------------------------------------------
53## Intent: check deps for format and python3 cleanliness
54## Note:
55## yaml --py3k option no longer supported
56## -----------------------------------------------------------------------
57lint-yaml-modified:
58 $(HIDE)$(MAKE) --no-print-directory lint-yaml-install
59 yamllint -s $(YAML_FILES)
60
61## -----------------------------------------------------------------------
62## Intent:
63## -----------------------------------------------------------------------
64lint-yaml-install:
65 @echo
66 @echo "** -----------------------------------------------------------------------"
67 @echo "** yaml syntax checking"
68 @echo "** -----------------------------------------------------------------------"
69 yamllint --version
70 @echo
71
72## -----------------------------------------------------------------------
73## Intent: Display command usage
74## -----------------------------------------------------------------------
Joey Armstrong36592e32022-11-28 09:00:28 -050075help::
Joey Armstrong4de98b72023-02-09 14:51:38 -050076 @echo ' lint-yaml Syntax check python using the yaml command'
77 ifdef VERBOSE
78 @echo ' lint-yaml-all yaml checking: exhaustive'
Joey Armstrong449ce7a2023-07-18 18:32:24 -040079 @echo ' lint-yaml-modified yaml checking: only locally modified'
Joey Armstrong4de98b72023-02-09 14:51:38 -050080 endif
81
82$(if $(DEBUG),$(warning LEAVE))
Joey Armstrong36592e32022-11-28 09:00:28 -050083
84# [EOF]