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