blob: f217cdea08e738ad701695f7c6e63c91a55e2d7f [file] [log] [blame]
Joey Armstrong7298cc42023-12-11 17:35:41 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2017-2023 Open Networking Foundation
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
18$(if $(DEBUG),$(warning ENTER))
19
20GOLANG_FILES ?= $(error PYTHON_FILES= is required)
21
22.PHONY: lint-golang-sca
23
24# lint : lint-golang-sca
25
26## -----------------------------------------------------------------------
27## Intent: Run goformat on files on sandbox files.
28## 1) find . -name '*.go' -print0
29## - gather all *.go sources (-name '*.go')
30## - pass as a list of null terminated items (-print0)
31## 2) xargs --null --max-args=[n] --no-run-if-empty gofmt -d
32## - Iterate over the list (xargs --null)
33## - process one item per line (--max-args=1)
34## - display filename-to-check (--verbose)
35## - display content when diffs are detected:
36## gofmt -d
37## gofmt -d -s
38## -----------------------------------------------------------------------
39lint-golang-sca-xargs := $(null)
40lint-golang-sca-xargs += --null#+ # Source paths are null terminated
41lint-golang-sca-xargs += --max-args=1#+ # Check one file at a time
42lint-golang-sca-xargs += --no-run-if-empty
43lint-golang-sca-xargs += --verbose#+ # Display source path to check
44
45## [INPLACE-EDITS] make lint-golang-sca FIX=1
46ifdef FIX
47 lint-golang-sca-args += -w
48endif
49
50lint-golang-sca:
51 find . -name '*.go' -print0 \
52 | xargs $(lint-golang-sca-xargs) gofmt -d -s
53
54help::
55 @echo " lint-golang-sca Syntax check golang sources"
56 @echo " MODIFIER: FIX=1 Correct problems (gofmt -d -s -w)"
57
58todo ::
59 @echo ' Rename sca.mk to source-code-analysis.mk'
60 @echo ' lint-golang-sca is a default lint target for repo:voltha-openolt-adapter'
61 @echo ' Update logic to support common targets lint-*-{all,mod,src}'
62 @echo ' What flag should be used for inplace edits: APPLY=1, FIX=1, UPDATE=1, ??'
63
64$(if $(DEBUG),$(warning LEAVE))
65
66# [EOF]