blob: bbb46e21fba987082004ec131810fd76585d8c15 [file] [log] [blame]
Joey Armstrongb085c502023-01-17 13:56:24 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors
Scott Baker2c1c4822019-10-16 11:02:41 -07004#
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 Armstrongb085c502023-01-17 13:56:24 -050016# -----------------------------------------------------------------------
Scott Baker2c1c4822019-10-16 11:02:41 -070017
Joey Armstrongb085c502023-01-17 13:56:24 -050018.DEFAULT_GOAL := help
19
20##-------------------##
21##---] GLOBALS [---##
22##-------------------##
23TOP ?= .
24MAKEDIR ?= $(TOP)/makefiles
25
26NO-LINT-MAKEFILE := true # cleanup needed
27NO-LINT-PYTHON := true # cleanup needed
28NO-LINT-SHELL := true # cleanup needed
29
30export SHELL := bash -e -o pipefail
31
32##--------------------##
33##---] INCLUDES [---##
34##--------------------##
35include $(MAKEDIR)/include.mk
Scott Baker2c1c4822019-10-16 11:02:41 -070036
37# Variables
38VERSION ?= $(shell cat ./VERSION)
39
Kent Hagermanfac11d42020-01-28 12:18:55 -050040# tool containers
David K. Bainbridgec50d88c2021-04-08 15:47:03 +000041VOLTHA_TOOLS_VERSION ?= 2.4.0
Kent Hagermanfac11d42020-01-28 12:18:55 -050042
Kent Hagerman08d15ab2020-02-14 14:54:52 -050043GO = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang go
Kent Hagermanfac11d42020-01-28 12:18:55 -050044GO_JUNIT_REPORT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-go-junit-report go-junit-report
khenaidoo26721882021-08-11 17:42:52 -040045GOCOVER_COBERTURA = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app/src/github.com/opencord/voltha-lib-go/v7 -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-gocover-cobertura gocover-cobertura
Kent Hagerman08d15ab2020-02-14 14:54:52 -050046GOLANGCI_LINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golangci-lint golangci-lint
Scott Baker2c1c4822019-10-16 11:02:41 -070047
Scott Baker2c1c4822019-10-16 11:02:41 -070048
Joey Armstrongb085c502023-01-17 13:56:24 -050049## -----------------------------------------------------------------------
Scott Baker2c1c4822019-10-16 11:02:41 -070050## Local Development Helpers
Joey Armstrongb085c502023-01-17 13:56:24 -050051## -----------------------------------------------------------------------
52.PHONY: local-protos
Scott Baker2c1c4822019-10-16 11:02:41 -070053local-protos:
54 @mkdir -p python/local_imports
55ifdef LOCAL_PROTOS
Joey Armstrong26245a32022-12-17 21:49:06 -050056 $(RM) -r vendor/github.com/opencord/voltha-protos
khenaidoo26721882021-08-11 17:42:52 -040057 mkdir -p vendor/github.com/opencord/voltha-protos/v5/go
58 cp -r ${LOCAL_PROTOS}/go/* vendor/github.com/opencord/voltha-protos/v5/go
Joey Armstrong26245a32022-12-17 21:49:06 -050059 $(RM) -r python/local_imports/voltha-protos
Scott Baker2c1c4822019-10-16 11:02:41 -070060 mkdir -p python/local_imports/voltha-protos/dist
Scott Bakerf1b096c2019-11-01 12:36:30 -070061 cp ${LOCAL_PROTOS}/dist/*.tar.gz python/local_imports/voltha-protos/dist/
Scott Baker2c1c4822019-10-16 11:02:41 -070062endif
63
Joey Armstrongb085c502023-01-17 13:56:24 -050064## -----------------------------------------------------------------------
Scott Baker2c1c4822019-10-16 11:02:41 -070065## build the library
Joey Armstrongb085c502023-01-17 13:56:24 -050066## -----------------------------------------------------------------------
Scott Bakerf1b096c2019-11-01 12:36:30 -070067build: local-protos
khenaidoo26721882021-08-11 17:42:52 -040068## ${GO} build -mod=vendor ./...
Kent Hagermanfac11d42020-01-28 12:18:55 -050069 ${GO} build -mod=vendor ./...
Scott Baker2c1c4822019-10-16 11:02:41 -070070
71## lint and unit tests
72
Joey Armstrongb085c502023-01-17 13:56:24 -050073## -----------------------------------------------------------------------
74## -----------------------------------------------------------------------
Scott Baker2c1c4822019-10-16 11:02:41 -070075lint-mod:
76 @echo "Running dependency check..."
Kent Hagermanfac11d42020-01-28 12:18:55 -050077 @${GO} mod verify
Scott Bakera36b4982019-11-26 08:09:23 -080078 @echo "Dependency check OK. Running vendor check..."
79 @git status > /dev/null
Kent Hagerman3da1fd02020-02-26 10:54:07 -050080 @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)
81 @[[ `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)
Kent Hagermanfac11d42020-01-28 12:18:55 -050082 ${GO} mod tidy
83 ${GO} mod vendor
Scott Bakera36b4982019-11-26 08:09:23 -080084 @git status > /dev/null
Kent Hagerman3da1fd02020-02-26 10:54:07 -050085 @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)
86 @[[ `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 Bakera36b4982019-11-26 08:09:23 -080087 @echo "Vendor check OK."
Scott Baker2c1c4822019-10-16 11:02:41 -070088
Joey Armstrongb085c502023-01-17 13:56:24 -050089## -----------------------------------------------------------------------
90## -----------------------------------------------------------------------
Kent Hagerman3da1fd02020-02-26 10:54:07 -050091lint: lint-mod
Scott Baker2c1c4822019-10-16 11:02:41 -070092
Joey Armstrongb085c502023-01-17 13:56:24 -050093## -----------------------------------------------------------------------
94## -----------------------------------------------------------------------
Kent Hagermanfac11d42020-01-28 12:18:55 -050095sca:
Joey Armstrong26245a32022-12-17 21:49:06 -050096 @$(RM) -r ./sca-report
Scott Baker2c1c4822019-10-16 11:02:41 -070097 @mkdir -p ./sca-report
Kent Hagerman3da1fd02020-02-26 10:54:07 -050098 @echo "Running static code analysis..."
99 @${GOLANGCI_LINT} run --deadline=4m --out-format junit-xml ./... | tee ./sca-report/sca-report.xml
100 @echo ""
101 @echo "Static code analysis OK"
Scott Baker2c1c4822019-10-16 11:02:41 -0700102
Joey Armstrongb085c502023-01-17 13:56:24 -0500103## -----------------------------------------------------------------------
104## -----------------------------------------------------------------------
Matteo Scandolod58eaef2020-03-30 12:30:02 -0700105test: local-protos
Scott Baker2c1c4822019-10-16 11:02:41 -0700106 @mkdir -p ./tests/results
Kent Hagermanfac11d42020-01-28 12:18:55 -0500107 @${GO} test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
Scott Baker2c1c4822019-10-16 11:02:41 -0700108 RETURN=$$? ;\
Kent Hagermanfac11d42020-01-28 12:18:55 -0500109 ${GO_JUNIT_REPORT} < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
110 ${GOCOVER_COBERTURA} < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
Scott Baker2c1c4822019-10-16 11:02:41 -0700111 exit $$RETURN
112
Joey Armstrongb085c502023-01-17 13:56:24 -0500113## -----------------------------------------------------------------------
114## -----------------------------------------------------------------------
Kent Hagermanfac11d42020-01-28 12:18:55 -0500115clean: distclean
Scott Baker2c1c4822019-10-16 11:02:41 -0700116
Joey Armstrongb085c502023-01-17 13:56:24 -0500117## -----------------------------------------------------------------------
118## -----------------------------------------------------------------------
Joey Armstrong26245a32022-12-17 21:49:06 -0500119distclean sterile:
120 $(RM) -r ./sca-report ./tests
Scott Baker2c1c4822019-10-16 11:02:41 -0700121
Joey Armstrongb085c502023-01-17 13:56:24 -0500122## -----------------------------------------------------------------------
123## -----------------------------------------------------------------------
Kent Hagermanfac11d42020-01-28 12:18:55 -0500124mod-update:
125 ${GO} mod tidy
126 ${GO} mod vendor
Joey Armstrong26245a32022-12-17 21:49:06 -0500127
128# [EOF]