blob: a446df52737a5fa247d3680ea0b87abe3cf95b3a [file] [log] [blame]
Girish Gowdra64503432020-01-07 10:59:10 +05301#
2# Copyright 2016 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# set default shell
18SHELL = bash -e -o pipefail
19
20# Variables
21VERSION ?= $(shell cat ./VERSION)
22
23DOCKER_EXTRA_ARGS ?=
24DOCKER_REGISTRY ?=
25DOCKER_REPOSITORY ?=
26DOCKER_TAG ?= ${VERSION}
27IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}openolt-scale-tester:${DOCKER_TAG}
28
29# Default is GO111MODULE=auto, which will refuse to use go mod if running
30# go less than 1.13.0 and this repository is checked out in GOPATH. For now,
31# force module usage. This affects commands executed from this Makefile, but
32# not the environment inside the Docker build (which does not build from
33# inside a GOPATH).
34export GO111MODULE=on
35
36DOCKER_BUILD_ARGS ?= \
37 ${DOCKER_EXTRA_ARGS} \
38
39.PHONY: docker-build local-protos local-lib-go
40
41# This should to be the first and default target in this Makefile
42help:
43 @echo "Usage: make [<target>]"
44 @echo "where available targets are:"
45 @echo ""
46 @echo "clean : Removes any local filesystem artifacts generated by a build"
47 @echo "distclean : Removes any local filesystem artifacts generated by a build or test run"
48 @echo "build : Build all openolt adapter artifacts"
49 @echo "docker-build : Build openolt adapter docker image"
50 @echo "docker-push : Push the docker images to an external repository"
51 @echo "help : Print this help"
52 @echo "lint : Run all lint targets"
53 @echo "lint-mod : Verify the Go dependencies"
54 @echo "lint-sanity : Run the Go language sanity tests (vet)"
55 @echo "lint-style : Verify the Go standard format of the source"
56 @echo "sca : Runs various SCA through golangci-lint tool"
57 @echo "test : Run unit tests, if any"
58 @echo
59
Girish Gowdra5d7d6442020-09-08 17:03:11 -070060## Local Development Helpers
61local-protos: ## Copies a local version of the voltha-protos dependency into the vendor directory
62ifdef LOCAL_PROTOS
Girish Gowdra390f12f2021-07-01 15:53:49 -070063 rm -rf vendor/github.com/opencord/voltha-protos/v5/go
64 mkdir -p vendor/github.com/opencord/voltha-protos/v5/go
65 cp -r ${LOCAL_PROTOS}/go/* vendor/github.com/opencord/voltha-protos/v5/go
66 rm -rf vendor/github.com/opencord/voltha-protos/v5/go/vendor
Girish Gowdra5d7d6442020-09-08 17:03:11 -070067endif
68
69local-lib-go: ## Copies a local version of the voltha-lib-go dependency into the vendor directory
70ifdef LOCAL_LIB_GO
Girish Gowdra390f12f2021-07-01 15:53:49 -070071 mkdir -p vendor/github.com/opencord/voltha-lib-go/v7/pkg
72 cp -r ${LOCAL_LIB_GO}/pkg/* vendor/github.com/opencord/voltha-lib-go/v7/pkg/
Girish Gowdra5d7d6442020-09-08 17:03:11 -070073endif
74
Girish Gowdra64503432020-01-07 10:59:10 +053075## Docker targets
76
77build: docker-build
78
79docker-build: local-protos local-lib-go
80 docker build $(DOCKER_BUILD_ARGS) -t ${IMAGENAME} -f docker/Dockerfile .
81
82docker-push:
83 docker push ${IMAGENAME}
84
85lint-style:
86ifeq (,$(shell which gofmt))
87 go get -u github.com/golang/go/src/cmd/gofmt
88endif
89 @echo "Running style check..."
90 @gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
91 if [ ! -z "$$gofmt_out" ]; then \
92 echo "$$gofmt_out" ;\
93 echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
94 exit 1 ;\
95 fi
96 @echo "Style check OK"
97
98lint-sanity:
99 @echo "Running sanity check..."
100 @go vet -mod=vendor ./...
101 @echo "Sanity check OK"
102
103lint-mod:
104 @echo "Running dependency check..."
105 @go mod verify
106 @echo "Dependency check OK. Running vendor check..."
107 @git status > /dev/null
108 @git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Staged or modified files must be committed before running this test" && echo "`git status`" && exit 1)
109 @[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files must be cleaned up before running this test" && echo "`git status`" && exit 1)
110 go mod tidy
111 go mod vendor
112 @git status > /dev/null
113 @git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Modified files detected after running go mod tidy / go mod vendor" && echo "`git status`" && exit 1)
114 @[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files detected after running go mod tidy / go mod vendor" && echo "`git status`" && exit 1)
115 @echo "Vendor check OK."
116
117lint: lint-style lint-sanity lint-mod
118
Girish Gowdra55444792020-03-26 13:43:18 -0700119# There is no unit test for openolt-scale-tester as of today. Just ensure docker-build is successful
120test: docker-build
Girish Gowdra64503432020-01-07 10:59:10 +0530121
122GOLANGCI_LINT_TOOL:=$(shell which golangci-lint)
123sca: golangci_lint_tool_install
124 @mkdir -p ./sca-report
125 golangci-lint run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml
126
127clean:
128
129distclean: clean
130 rm -rf ./sca_report
131
132# end file