blob: f8c2f7f263b95f41c0e506734ea818ee8cc02beb [file] [log] [blame]
Joey Armstrongf548adc2023-09-08 15:59:42 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrongdc04c932024-04-01 12:14:21 -04003# Copyright 2017-2024 Open Networking Foundation Contributors
Joey Armstrongf548adc2023-09-08 15:59:42 -04004#
Joey Armstrongdc04c932024-04-01 12:14:21 -04005# Licensed under the Apache License, Version 2.0 (the "License");
Joey Armstrongf548adc2023-09-08 15:59:42 -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 Armstrongf548adc2023-09-08 15:59:42 -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 Armstrongf548adc2023-09-08 15:59:42 -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
33YAMLLINT = $(activate) && yamllint
34yamllint-args += --strict
35
Joey Armstrongccab2cf2024-04-06 18:00:59 -040036yaml-find-args := $(null)
37yaml-find-args += $(foreach dir,$(onf-excl-dirs),-not -path './$(dir)/*')
38yaml-find-args += -a \( -iname '*.yaml' -o -iname '*.yml' \)
39yaml-find-args += -print0
40
Joey Armstrongf548adc2023-09-08 15:59:42 -040041## -----------------------------------------------------------------------
42## Intent: Use the yaml command to perform syntax checking.
43## -----------------------------------------------------------------------
44ifndef NO-LINT-YAML
45 lint-yaml-mode := $(if $(have-yaml-files),modified,all)
46 lint : lint-yaml
47 lint-yaml : lint-yaml-$(lint-yaml-mode)
48endif# NO-LINT-YAML
49
50## -----------------------------------------------------------------------
51## Intent: exhaustive yaml syntax checking
52## -----------------------------------------------------------------------
53lint-yaml-all: lint-yaml-cmd-version
54
55 $(call banner-enter,Target $@)
56 $(HIDE)$(MAKE) --no-print-directory lint-yaml-install
Joey Armstrongccab2cf2024-04-06 18:00:59 -040057
58 $(HIDE)$(activate) && find . $(yaml-find-args) \
Joey Armstrongf548adc2023-09-08 15:59:42 -040059 | $(env-clean) $(xargs-cmd) -I'{}' \
60 bash -c "$(YAMLLINT) $(yamllint-args) {}"
61 $(call banner-leave,Target $@)
62
63## -----------------------------------------------------------------------
64## Intent: check deps for format and python3 cleanliness
65## Note:
66## yaml --py3k option no longer supported
67## -----------------------------------------------------------------------
68lint-yaml-modified: lint-yaml-cmd-version
69
70 $(call banner-enter,Target $@)
71 $(HIDE)$(MAKE) --no-print-directory lint-yaml-install
72 $(YAMLLINT) $(yamllint-args) $(YAML_FILES)
73 $(call banner-leave,Target $@)
74
75## -----------------------------------------------------------------------
76## Intent: Display command usage
77## -----------------------------------------------------------------------
78help::
79 @echo ' lint-yaml Syntax check python using the yaml command'
80 ifdef VERBOSE
81 @echo ' $(MAKE) lint-yaml YAML_FILES=...'
82 @echo ' lint-yaml-all yaml checking: exhaustive'
83 @echo ' lint-yaml-modified yaml checking: only locally modified'
84 @echo ' lint-yaml-install Install the pylint command'
85 endif
86
87$(if $(DEBUG),$(warning LEAVE))
88
89# [EOF]