Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame^] | 1 | # -*- 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 | |
| 20 | GOLANG_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 | ## ----------------------------------------------------------------------- |
| 39 | lint-golang-sca-xargs := $(null) |
| 40 | lint-golang-sca-xargs += --null#+ # Source paths are null terminated |
| 41 | lint-golang-sca-xargs += --max-args=1#+ # Check one file at a time |
| 42 | lint-golang-sca-xargs += --no-run-if-empty |
| 43 | lint-golang-sca-xargs += --verbose#+ # Display source path to check |
| 44 | |
| 45 | ## [INPLACE-EDITS] make lint-golang-sca FIX=1 |
| 46 | ifdef FIX |
| 47 | lint-golang-sca-args += -w |
| 48 | endif |
| 49 | |
| 50 | lint-golang-sca: |
| 51 | find . -name '*.go' -print0 \ |
| 52 | | xargs $(lint-golang-sca-xargs) gofmt -d -s |
| 53 | |
| 54 | help:: |
| 55 | @echo " lint-golang-sca Syntax check golang sources" |
| 56 | @echo " MODIFIER: FIX=1 Correct problems (gofmt -d -s -w)" |
| 57 | |
| 58 | $(if $(DEBUG),$(warning LEAVE)) |
| 59 | |
| 60 | # [EOF] |