Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 3 | # Copyright 2017-2024 Open Networking Foundation Contributors |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 4 | # |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 9 | # http:#www.apache.org/licenses/LICENSE-2.0 |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 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 | # ----------------------------------------------------------------------- |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 17 | # SPDX-FileCopyrightText: 2017-2024 Open Networking Foundation Contributors |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ----------------------------------------------------------------------- |
| 20 | # Intent: |
| 21 | # ----------------------------------------------------------------------- |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 22 | |
| 23 | $(if $(DEBUG),$(warning ENTER)) |
| 24 | |
| 25 | ##-------------------## |
| 26 | ##---] GLOBALS [---## |
| 27 | ##-------------------## |
| 28 | .PHONY: lint-yaml lint-yaml-all lint-yaml-modified |
| 29 | |
| 30 | have-yaml-files := $(if $(strip $(YAML_FILES)),true) |
| 31 | YAML_FILES ?= $(error YAML_FILES= is required) |
| 32 | |
| 33 | YAMLLINT = $(activate) && yamllint |
| 34 | yamllint-args += --strict |
| 35 | |
Joey Armstrong | ccab2cf | 2024-04-06 18:00:59 -0400 | [diff] [blame] | 36 | yaml-find-args := $(null) |
| 37 | yaml-find-args += $(foreach dir,$(onf-excl-dirs),-not -path './$(dir)/*') |
| 38 | yaml-find-args += -a \( -iname '*.yaml' -o -iname '*.yml' \) |
| 39 | yaml-find-args += -print0 |
| 40 | |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 41 | ## ----------------------------------------------------------------------- |
| 42 | ## Intent: Use the yaml command to perform syntax checking. |
| 43 | ## ----------------------------------------------------------------------- |
| 44 | ifndef 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) |
| 48 | endif# NO-LINT-YAML |
| 49 | |
| 50 | ## ----------------------------------------------------------------------- |
| 51 | ## Intent: exhaustive yaml syntax checking |
| 52 | ## ----------------------------------------------------------------------- |
| 53 | lint-yaml-all: lint-yaml-cmd-version |
| 54 | |
| 55 | $(call banner-enter,Target $@) |
| 56 | $(HIDE)$(MAKE) --no-print-directory lint-yaml-install |
Joey Armstrong | ccab2cf | 2024-04-06 18:00:59 -0400 | [diff] [blame] | 57 | |
| 58 | $(HIDE)$(activate) && find . $(yaml-find-args) \ |
Joey Armstrong | f548adc | 2023-09-08 15:59:42 -0400 | [diff] [blame] | 59 | | $(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 | ## ----------------------------------------------------------------------- |
| 68 | lint-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 | ## ----------------------------------------------------------------------- |
| 78 | help:: |
| 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] |