Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | 25589d8 | 2024-01-02 22:31:35 -0500 | [diff] [blame] | 3 | # Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 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 | |
Joey Armstrong | e0c1a8d | 2023-04-13 15:16:21 -0400 | [diff] [blame] | 20 | ##-------------------## |
| 21 | ##---] GLOBALS [---## |
| 22 | ##-------------------## |
| 23 | .PHONY: lint-golang lint-golang-sca-all lint-golang-sca-modified |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 24 | |
Joey Armstrong | e0c1a8d | 2023-04-13 15:16:21 -0400 | [diff] [blame] | 25 | GOLANG_FILES ?= $(error GOLANG_FILES= is required) |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 26 | |
Joey Armstrong | e0c1a8d | 2023-04-13 15:16:21 -0400 | [diff] [blame] | 27 | ## ----------------------------------------------------------------------- |
| 28 | ## Intent: Use the golang command to perform syntax checking. |
| 29 | ## o If UNSTABLE=1 syntax check all sources |
| 30 | ## o else only check sources modified by the developer. |
| 31 | ## Usage: |
| 32 | ## % make lint UNSTABLE=1 |
| 33 | ## % make lint-golang-all |
| 34 | ## ----------------------------------------------------------------------- |
| 35 | ifndef NO-LINT-GOLANG |
| 36 | lint-golang-mode := $(if $(have-golang-files),modified,all) |
| 37 | lint : lint-golang-sca-$(lint-golang-mode) |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 38 | |
Joey Armstrong | e0c1a8d | 2023-04-13 15:16:21 -0400 | [diff] [blame] | 39 | lint-golang-all : lint-golang-sca-all |
| 40 | lint-golang-modified : lint-golang-sca-modified |
| 41 | endif# NO-LINT-GOLANG |
| 42 | |
| 43 | ## ----------------------------------------------------------------------- |
| 44 | ## Intent: exhaustive golint syntax checking |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 45 | ## ----------------------------------------------------------------------- |
| 46 | ## Intent: Run goformat on files on sandbox files. |
| 47 | ## 1) find . -name '*.go' -print0 |
| 48 | ## - gather all *.go sources (-name '*.go') |
| 49 | ## - pass as a list of null terminated items (-print0) |
| 50 | ## 2) xargs --null --max-args=[n] --no-run-if-empty gofmt -d |
| 51 | ## - Iterate over the list (xargs --null) |
| 52 | ## - process one item per line (--max-args=1) |
| 53 | ## - display filename-to-check (--verbose) |
| 54 | ## - display content when diffs are detected: |
| 55 | ## gofmt -d |
| 56 | ## gofmt -d -s |
| 57 | ## ----------------------------------------------------------------------- |
| 58 | lint-golang-sca-xargs := $(null) |
| 59 | lint-golang-sca-xargs += --null#+ # Source paths are null terminated |
| 60 | lint-golang-sca-xargs += --max-args=1#+ # Check one file at a time |
| 61 | lint-golang-sca-xargs += --no-run-if-empty |
| 62 | lint-golang-sca-xargs += --verbose#+ # Display source path to check |
| 63 | |
| 64 | ## [INPLACE-EDITS] make lint-golang-sca FIX=1 |
| 65 | ifdef FIX |
| 66 | lint-golang-sca-args += -w |
| 67 | endif |
| 68 | |
Joey Armstrong | e0c1a8d | 2023-04-13 15:16:21 -0400 | [diff] [blame] | 69 | gofmt-args += -d# Do not output reformatted lines |
| 70 | # gofmt-args += -e# Display all errors (including spurious) |
| 71 | gofmt-args += -s# Try to simplify code |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 72 | |
Joey Armstrong | e0c1a8d | 2023-04-13 15:16:21 -0400 | [diff] [blame] | 73 | ## ----------------------------------------------------------------------- |
| 74 | ## Intent: exhaustive golang syntax checking |
| 75 | ## ----------------------------------------------------------------------- |
| 76 | lint-golang-sca-all: $(venv-activate-script) |
| 77 | # $(MAKE) --no-print-directory lint-sca-install |
| 78 | |
| 79 | find . -name '*.go' -print0 \ |
| 80 | | xargs $(lint-golang-sca-xargs) gofmt $(gofmt-args) |
| 81 | |
| 82 | ## ----------------------------------------------------------------------- |
| 83 | ## Intent: check deps for format and cleanliness |
| 84 | ## ----------------------------------------------------------------------- |
| 85 | lint-golang-sca-modified: lint-golang-all |
| 86 | # $(MAKE) --no-print-directory lint-golang-sca-install |
| 87 | |
| 88 | gofmt $(gofmt-args) $(GOLANG_FILES) |
| 89 | |
| 90 | ## ----------------------------------------------------------------------- |
| 91 | ## Intent: Tool installation as needed |
| 92 | ## ----------------------------------------------------------------------- |
| 93 | .PHONY: lint-golang-sca-install |
| 94 | lint-golang-sca-install: |
| 95 | @echo |
| 96 | @echo "** -----------------------------------------------------------------------" |
| 97 | @echo "** golang syntax checking" |
| 98 | @echo "** -----------------------------------------------------------------------" |
| 99 | @echo |
| 100 | |
| 101 | ## ----------------------------------------------------------------------- |
| 102 | ## Intent: Display target help |
| 103 | ## ----------------------------------------------------------------------- |
| 104 | .PHONY: help-golang-sca |
| 105 | help-verbose += help-golang-sca |
| 106 | help-golang-sca : |
| 107 | @echo " % $(MAKE) lint-golang GOLANG_FILES=..." |
| 108 | @echo ' lint-golang-sca-modified golang checking: only modified' |
| 109 | @echo ' lint-golang-sca-all golang checking: exhaustive' |
Joey Armstrong | e6cdd8e | 2022-12-29 11:58:15 -0500 | [diff] [blame] | 110 | |
| 111 | $(if $(DEBUG),$(warning LEAVE)) |
| 112 | |
| 113 | # [EOF] |