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