blob: d49dd9a54d3232289980a82724b3bd47b60f2f80 [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-yaml lint-yaml-all lint-yaml-modified
29
30have-yaml-files := $(if $(strip $(YAML_FILES)),true)
31YAML_FILES ?= $(error YAML_FILES= is required)
32
Joey Armstrongccab2cf2024-04-06 18:00:59 -040033# Gather sources to check
34yaml-find-args := find .
35yaml-find-args += $(foreach dir,$(onf-excl-dirs),-not -path './$(dir)/*')
36
Joey Armstrong0205d332023-04-11 17:29:23 -040037## -----------------------------------------------------------------------
38## Intent: Use the yaml command to perform syntax checking.
39## o If UNSTABLE=1 syntax check all sources
40## o else only check sources modified by the developer.
41## Usage:
42## % make lint UNSTABLE=1
43## % make lint-yaml-all
44## -----------------------------------------------------------------------
45lint-yaml-mode := $(if $(have-yaml-files),modified,all)
46lint-yaml : lint-yaml-$(lint-yaml-mode)
47
48ifndef NO-LINT-YAML
49 lint : lint-yaml# # Enable as a default lint target
50endif# NO-LINT-YAML
51
52## -----------------------------------------------------------------------
53## Intent: exhaustive yaml syntax checking
54## -----------------------------------------------------------------------
55lint-yaml-all:
56 $(HIDE)$(MAKE) --no-print-directory lint-yaml-install
57
Joey Armstrongccab2cf2024-04-06 18:00:59 -040058 find . $(yaml-find-args) \( -iname '*.yaml' -o -iname '*.yml' \) -print0 \
Joey Armstrong0205d332023-04-11 17:29:23 -040059 | $(xargs-n1-clean) yamllint --strict
60
61## -----------------------------------------------------------------------
62## Intent: check deps for format and python3 cleanliness
63## Note:
64## yaml --py3k option no longer supported
65## -----------------------------------------------------------------------
66lint-yaml-modified:
67 $(HIDE)$(MAKE) --no-print-directory lint-yaml-install
68 yamllint -s $(YAML_FILES)
69
70## -----------------------------------------------------------------------
71## Intent:
72## -----------------------------------------------------------------------
73lint-yaml-install:
74 @echo
75 @echo "** -----------------------------------------------------------------------"
76 @echo "** yaml syntax checking"
77 @echo "** -----------------------------------------------------------------------"
78 yamllint --version
79 @echo
80
81## -----------------------------------------------------------------------
82## Intent: Display command usage
83## -----------------------------------------------------------------------
84help::
85 @echo ' lint-yaml Syntax check python using the yaml command'
86 ifdef VERBOSE
87 @echo ' lint-yaml-all yaml checking: exhaustive'
88 @echo ' lint-yaml-modified yaml checking: only locally modified'
89 endif
90
91$(if $(DEBUG),$(warning LEAVE))
92
93# [EOF]