Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | 9cdee9f | 2024-01-03 04:56:14 -0500 | [diff] [blame] | 3 | # Copyright 2016-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [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. |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 17 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 18 | .DEFAULT_GOAL := help |
| 19 | |
| 20 | ##-------------------## |
| 21 | ##---] GLOBALS [---## |
| 22 | ##-------------------## |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 23 | |
| 24 | ##--------------------## |
| 25 | ##---] INCLUDES [---## |
| 26 | ##--------------------## |
Joey Armstrong | 7cd92a1 | 2024-05-01 17:47:58 -0400 | [diff] [blame^] | 27 | $(if $(findstring disabled-joey,$(USER)),\ |
| 28 | $(eval USE_LF_MK := 1)) # special snowflake |
| 29 | |
| 30 | ##--------------------## |
| 31 | ##---] INCLUDES [---## |
| 32 | ##--------------------## |
| 33 | ifdef USE_LF_MK |
| 34 | $(error should not be here) |
| 35 | include lf/include.mk |
| 36 | else |
| 37 | include lf/transition.mk |
| 38 | endif # ifdef USE_LF_MK |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 39 | |
| 40 | # Variables |
| 41 | VERSION ?= $(shell cat ./VERSION) |
| 42 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 43 | ## ----------------------------------------------------------------------- |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 44 | ## Local Development Helpers |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 45 | ## ----------------------------------------------------------------------- |
| 46 | .PHONY: local-protos |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 47 | local-protos: |
| 48 | @mkdir -p python/local_imports |
| 49 | ifdef LOCAL_PROTOS |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 50 | $(RM) -r vendor/github.com/opencord/voltha-protos |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 51 | mkdir -p vendor/github.com/opencord/voltha-protos/v5/go |
| 52 | cp -r ${LOCAL_PROTOS}/go/* vendor/github.com/opencord/voltha-protos/v5/go |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 53 | $(RM) -r python/local_imports/voltha-protos |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 54 | mkdir -p python/local_imports/voltha-protos/dist |
Scott Baker | f1b096c | 2019-11-01 12:36:30 -0700 | [diff] [blame] | 55 | cp ${LOCAL_PROTOS}/dist/*.tar.gz python/local_imports/voltha-protos/dist/ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 56 | endif |
| 57 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 58 | ## ----------------------------------------------------------------------- |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 59 | ## build the library |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 60 | ## ----------------------------------------------------------------------- |
Scott Baker | f1b096c | 2019-11-01 12:36:30 -0700 | [diff] [blame] | 61 | build: local-protos |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 62 | $(call banner-enter,Target $@) |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 63 | ${GO} build -mod=vendor ./... |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 64 | $(call banner-leave,Target $@) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 65 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 66 | ## ----------------------------------------------------------------------- |
| 67 | ## ----------------------------------------------------------------------- |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 68 | lint-mod: |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 69 | $(call banner-entry,Target $@) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 70 | @echo "Running dependency check..." |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 71 | @${GO} mod verify |
Scott Baker | a36b498 | 2019-11-26 08:09:23 -0800 | [diff] [blame] | 72 | @echo "Dependency check OK. Running vendor check..." |
| 73 | @git status > /dev/null |
Kent Hagerman | 3da1fd0 | 2020-02-26 10:54:07 -0500 | [diff] [blame] | 74 | @git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Staged or modified files must be committed before running this test" && git status -- go.mod go.sum vendor && exit 1) |
| 75 | @[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files must be cleaned up before running this test" && git status -- go.mod go.sum vendor && exit 1) |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 76 | |
| 77 | $(HIDE)$(MAKE) --no-print-directory mod-update |
| 78 | |
Scott Baker | a36b498 | 2019-11-26 08:09:23 -0800 | [diff] [blame] | 79 | @git status > /dev/null |
Kent Hagerman | 3da1fd0 | 2020-02-26 10:54:07 -0500 | [diff] [blame] | 80 | @git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Modified files detected after running go mod tidy / go mod vendor" && git status -- go.mod go.sum vendor && git checkout -- go.mod go.sum vendor && exit 1) |
| 81 | @[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files detected after running go mod tidy / go mod vendor" && git status -- go.mod go.sum vendor && git checkout -- go.mod go.sum vendor && exit 1) |
Scott Baker | a36b498 | 2019-11-26 08:09:23 -0800 | [diff] [blame] | 82 | @echo "Vendor check OK." |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 83 | $(call banner-leave,Target $@) |
| 84 | |
| 85 | ## ----------------------------------------------------------------------- |
| 86 | ## ----------------------------------------------------------------------- |
| 87 | .PHONY: mod-update |
Joey Armstrong | 074f64f | 2023-12-01 10:05:02 -0500 | [diff] [blame] | 88 | mod-update: go-version mod-tidy mod-vendor |
| 89 | |
| 90 | ## ----------------------------------------------------------------------- |
| 91 | ## ----------------------------------------------------------------------- |
| 92 | .PHONY: go-version |
| 93 | go-version : |
| 94 | $(call banner-enter,Target $@) |
| 95 | ${GO} version |
| 96 | $(call banner-leave,Target $@) |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 97 | |
| 98 | ## ----------------------------------------------------------------------- |
| 99 | ## ----------------------------------------------------------------------- |
| 100 | .PHONY: mod-tidy |
| 101 | mod-tidy : |
| 102 | $(call banner-enter,Target $@) |
| 103 | ${GO} mod tidy |
| 104 | $(call banner-leave,Target $@) |
| 105 | |
| 106 | ## ----------------------------------------------------------------------- |
| 107 | ## ----------------------------------------------------------------------- |
| 108 | .PHONY: mod-vendor |
| 109 | mod-vendor : mod-tidy |
| 110 | mod-vendor : |
| 111 | $(call banner-enter,Target $@) |
| 112 | $(if $(LOCAL_FIX_PERMS),chmod o+w $(CURDIR)) |
| 113 | ${GO} mod vendor |
| 114 | $(if $(LOCAL_FIX_PERMS),chmod o-w $(CURDIR)) |
| 115 | $(call banner-leave,Target $@) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 116 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 117 | ## ----------------------------------------------------------------------- |
| 118 | ## ----------------------------------------------------------------------- |
Kent Hagerman | 3da1fd0 | 2020-02-26 10:54:07 -0500 | [diff] [blame] | 119 | lint: lint-mod |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 120 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 121 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 122 | ## Coverage report: Static code analysis |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 123 | ## ----------------------------------------------------------------------- |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 124 | sca: |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 125 | @$(RM) -r ./sca-report |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 126 | @mkdir -p ./sca-report |
Kent Hagerman | 3da1fd0 | 2020-02-26 10:54:07 -0500 | [diff] [blame] | 127 | @echo "Running static code analysis..." |
| 128 | @${GOLANGCI_LINT} run --deadline=4m --out-format junit-xml ./... | tee ./sca-report/sca-report.xml |
| 129 | @echo "" |
| 130 | @echo "Static code analysis OK" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 131 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 132 | ## ----------------------------------------------------------------------- |
| 133 | ## ----------------------------------------------------------------------- |
Matteo Scandolo | d58eaef | 2020-03-30 12:30:02 -0700 | [diff] [blame] | 134 | test: local-protos |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 135 | |
| 136 | $(call banner-enter,Target $@) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 137 | @mkdir -p ./tests/results |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 138 | |
| 139 | # No stream redirects, exit with shell status |
| 140 | $(MAKE) test-go |
| 141 | |
| 142 | # Redirect I/O, ignore shell exit status (for now) |
| 143 | $(MAKE) test-go-cover |
| 144 | |
| 145 | $(call banner-leave,Target $@) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 146 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 147 | ## ----------------------------------------------------------------------- |
| 148 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 149 | .PHONY: test-go |
| 150 | test-go : |
| 151 | |
| 152 | $(call banner-enter,Target $@) |
| 153 | @echo "** Testing attempt #1: exit-with-error-status: enabled" |
| 154 | -$(GO) test -mod=vendor ./... |
| 155 | $(call banner-leave,Target $@) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 156 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 157 | ## ----------------------------------------------------------------------- |
| 158 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 159 | .PHONY: test-go-cover |
Joey Armstrong | fd77d5e | 2023-07-15 16:37:44 -0400 | [diff] [blame] | 160 | test-go-cover : gen-coverage-coverprofile gen-coverage-junit gen-coverage-cobertura |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 161 | |
| 162 | ## ----------------------------------------------------------------------- |
| 163 | ## Intent: Generate coverprofile data |
| 164 | ## ----------------------------------------------------------------------- |
| 165 | cover-dir := ./tests/results |
| 166 | go-cover-out := $(cover-dir)/go-test-coverage.out |
| 167 | go-result-out := $(cover-dir)/go-test-results.out |
| 168 | |
| 169 | .PHONY: gen-coverage-coverprofile |
| 170 | gen-coverage-coverprofile: |
| 171 | |
| 172 | $(call banner-enter,Target $@) |
| 173 | @echo "** Testing attempt #2: exit-with-error-status: disabled" |
| 174 | |
| 175 | # Fix docker volume perms if building locally |
| 176 | touch "$(go-cover-out)" |
| 177 | $(if $(LOCAL_FIX_PERMS),chmod o+w "$(go-cover-out)") |
| 178 | |
| 179 | # Fix docker volume perms if building locally |
| 180 | $(if $(LOCAL_FIX_PERMS),touch "$(go-result-out)") |
| 181 | $(if $(LOCAL_FIX_PERMS),chmod o+w "$(go-result-out)") |
| 182 | |
Joey Armstrong | 7cd92a1 | 2024-05-01 17:47:58 -0400 | [diff] [blame^] | 183 | # ------------------------------------------ |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 184 | # set -euo pipefail else tee masks $? return |
| 185 | # ------------------------------------------ |
| 186 | @echo '** Running test coverage: exit-on-error is currently disabled' |
| 187 | -(\ |
| 188 | set -euo pipefail; \ |
| 189 | $(GO) test -mod=vendor -v -coverprofile "$(go-cover-out)" -covermode count ./... 2>&1 | tee "$(go-result-out)" \ |
Joey Armstrong | 7cd92a1 | 2024-05-01 17:47:58 -0400 | [diff] [blame^] | 190 | ) |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 191 | |
| 192 | $(if $(LOCAL_FIX_PERMS),chmod o-w "$(go-result-out)") |
Joey Armstrong | fd77d5e | 2023-07-15 16:37:44 -0400 | [diff] [blame] | 193 | $(if $(LOCAL_FIX_PERMS),chmod o-w "$(go-cover-out)") |
| 194 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 195 | $(call banner-leave,Target $@) |
| 196 | |
| 197 | ## ----------------------------------------------------------------------- |
| 198 | ## Intent: Morph coverage data into junit/xml content |
| 199 | ## ----------------------------------------------------------------------- |
| 200 | go-results-xml := $(cover-dir)/go-test-results.xml |
| 201 | |
| 202 | .PHONY: gen-coverage-junit |
| 203 | gen-coverage-junit : gen-coverage-coverprofile |
| 204 | gen-coverage-junit: |
| 205 | $(call banner-enter,Target $@) |
| 206 | |
| 207 | # Fix docker volume perms if building locally |
| 208 | $(if $(LOCAL_FIX_PERMS),touch "$(go-results-xml)") |
| 209 | $(if $(LOCAL_FIX_PERMS),chmod o+w "$(go-results-xml)") |
| 210 | |
| 211 | ${GO_JUNIT_REPORT} < $(go-result-out) > "$(go-results-xml)" |
| 212 | |
| 213 | $(if $(LOCAL_FIX_PERMS),chmod o-w "$(go-results-xml)") |
| 214 | $(call banner-leave,Target $@) |
| 215 | |
| 216 | ## ----------------------------------------------------------------------- |
| 217 | ## Intent: Morph coverage data into cobertura xml |
| 218 | ## ----------------------------------------------------------------------- |
| 219 | go-cover-xml := $(cover-dir)/go-test-coverage.xml |
| 220 | |
| 221 | .PHONY: gen-coverage-cobertura |
| 222 | gen-coverage-cobertura : gen-coverage-junit |
| 223 | gen-coverage-cobertura : |
| 224 | |
| 225 | $(call banner-enter,Target $@) |
| 226 | |
| 227 | # Fix docker volume perms if building locally |
| 228 | $(if $(LOCAL_FIX_PERMS),touch "$(go-cover-xml)") |
Joey Armstrong | fd77d5e | 2023-07-15 16:37:44 -0400 | [diff] [blame] | 229 | $(if $(LOCAL_FIX_PERMS),chmod o+w "$(go-cover-xml)") |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 230 | |
| 231 | ${GOCOVER_COBERTURA} < "$(go-cover-out)" > "$(go-cover-xml)" |
| 232 | |
| 233 | $(if $(LOCAL_FIX_PERMS),chmod o-w "$(go-cover-xml)") |
| 234 | $(call banner-leave,Target $@) |
| 235 | |
| 236 | ## ----------------------------------------------------------------------- |
| 237 | ## ----------------------------------------------------------------------- |
| 238 | distclean: |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 239 | $(RM) -r ./sca-report ./tests |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 240 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 241 | ## ----------------------------------------------------------------------- |
| 242 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 243 | clean :: distclean |
| 244 | |
| 245 | ## ----------------------------------------------------------------------- |
| 246 | ## ----------------------------------------------------------------------- |
| 247 | sterile :: clean |
| 248 | |
| 249 | ## ----------------------------------------------------------------------- |
| 250 | ## ----------------------------------------------------------------------- |
| 251 | help :: |
| 252 | @echo "Usage: make [<target>]" |
| 253 | @echo "where available targets are:" |
| 254 | @echo |
| 255 | @echo "build : Build the library" |
| 256 | @echo "clean : Remove files created by the build" |
| 257 | @echo "distclean : Remove build and testing artifacts and reports" |
| 258 | @echo "lint-mod : Verify the integrity of the 'mod' files" |
| 259 | @echo "mod-update : Update go.mod and the vendor directory" |
| 260 | @echo "test : Generate reports for all go tests" |
| 261 | @echo |
| 262 | @echo '[REPORT: coverage]' |
| 263 | @echo ' gen-coverage-coverprofile Generate profiling data' |
| 264 | @echo ' gen-coverage-junit Generate junit coverage report' |
| 265 | @echo ' gen-coverage-cobertura Generate cobertura report' |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 266 | |
| 267 | # [EOF] |