blob: 0652bb484d9d3382b9d7641cc93680f6a74cc8f0 [file] [log] [blame]
Joey Armstrongccab2cf2024-04-06 18:00:59 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2022-2024 Open Networking Foundation Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# 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# SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20# Intent:
21# -----------------------------------------------------------------------
22
23$(if $(DEBUG),$(warning ENTER))
24
25##-------------------##
26##---] GLOBALS [---##
27##-------------------##
28.PHONY: lint-groovy
29.PHONY: lint-groovy-all lint-groovy-mod lint-groovy-src
30
31have-groovy-files := $(if $(strip $(GROOVY_SOURCE)),true)
32GROOVY_SOURCE ?= $(error GROOVY_SOURCE= is required)
33
34groovy-check := $(activate-npm) && $(lint-groovy-cmd) $(lint-groovy-args)
35
36##-------------------##
37##---] TARGETS [---##
38##-------------------##
39
40## -----------------------------------------------------------------------
41## Intent: Enabled by repository_sandbox_root/config.mk
42## -----------------------------------------------------------------------
43ifndef NO-LINT-GROOVY
44 lint-groovy-mode := $(if $(have-groovy-files),mod,all)
45 lint-groovy : lint
46 lint-groovy : lint-groovy-$(lint-groovy-mode)
47endif# NO-LINT-GROOVY
48
49
50groovy-find-args += $(foreach dir,$(onf-excl-dirs),-not -path './$(dir)/*')
51
52## -----------------------------------------------------------------------
53## Intent: Perform a lint check on command line script sources
54## -----------------------------------------------------------------------
55lint-groovy-all: lint-groovy-version
56
57 $(call banner-enter,Target $@)
58
59 @echo
60# $(HIDE)$(env-clean) find . \
61#-not -path './.tmp/*' \
62#-not -path "./.$(venv-name)/*" \
63
64 $(HIDE)$(env-clean) find . $(groovy-find-args) -iname '*.groovy' -print0 \
65 | $(xargs-n1) bash -c "$(groovy-check)"
66
67 $(call banner-leave,Target $@)
68
69## -----------------------------------------------------------------------
70## Intent: On-demand lint checking
71## -----------------------------------------------------------------------
72lint-groovy-src : lint-groovy-version
73
74 ifndef GROOVY_SRC
75 @echo "ERROR: Usage: $(MAKE) $@ GROOVY_SRC="
76 @exit 1
77 endif
78
79 $(call banner-enter,Target $@)
80 @echo
81 $(HIDE) $(groovy-check) $(GROOVY_SRC)
82 $(call banner-leave,Target $@)
83
84## -----------------------------------------------------------------------
85## Intent: Perform lint check on locally modified sources
86## -----------------------------------------------------------------------
87lint-groovy-bygit = $(git status -s | grep '\.groovy' | grep -v -e '^D' -e '^?' | cut -c4-)
88lint-groovy-mod: lint-groovy-version
89
90 $(call banner-enter,Target $@)
91 @echo
92 $(foreach fyl,$(lint-groovy-bygit),$(groovy-check) $(fyl))
93 $(call banner-leave,Target $@)
94
95## -----------------------------------------------------------------------
96## Intent: Display command help
97## -----------------------------------------------------------------------
98help-summary ::
99 @echo ' lint-groovy Conditionally lint groovy source'
100 ifdef VERBOSE
101 @echo ' lint-groovy-all Lint all available sources'
102 @echo ' lint-groovy-mod Lint locally modified (git status)'
103 @echo ' lint-groovy-src Lint individually (BY_SRC=list-of-files)'
104 endif
105
106$(if $(DEBUG),$(warning LEAVE))
107
108# [EOF]